Skip to content

Commit da7bde7

Browse files
Fix mod_module_files FP for tests in workspaces
Workspaces don't have their integration tests in tests/ at the root, so this check missed them.
1 parent 8ed05ab commit da7bde7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

clippy_lints/src/module_style.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
44
use rustc_session::impl_lint_pass;
55
use rustc_span::def_id::LOCAL_CRATE;
66
use rustc_span::{FileName, SourceFile, Span, SyntaxContext, sym};
7-
use std::path::{Path, PathBuf};
7+
use std::path::{Component, Path, PathBuf};
88
use std::sync::Arc;
99

1010
declare_clippy_lint! {
@@ -150,7 +150,13 @@ fn check_self_named_module(cx: &EarlyContext<'_>, path: &Path, file: &SourceFile
150150
/// Using `mod.rs` in integration tests is a [common pattern](https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-test)
151151
/// for code-sharing between tests.
152152
fn check_mod_module(cx: &EarlyContext<'_>, path: &Path, file: &SourceFile) {
153-
if path.ends_with("mod.rs") && !path.starts_with("tests") {
153+
if path.ends_with("mod.rs")
154+
&& !path
155+
.components()
156+
.filter_map(|c| if let Component::Normal(d) = c { Some(d) } else { None })
157+
.take_while(|&c| c != "src")
158+
.any(|c| c == "tests")
159+
{
154160
span_lint_and_then(
155161
cx,
156162
MOD_MODULE_FILES,

0 commit comments

Comments
 (0)