Skip to content

Commit a1f9145

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 a1f9145

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clippy_lints/src/module_style.rs

Lines changed: 7 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,12 @@ 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+
.take_while(|c| !matches!(c, Component::Normal("src")))
157+
.any(|c| matches!(c, Component::Normal("tests")))
158+
{
154159
span_lint_and_then(
155160
cx,
156161
MOD_MODULE_FILES,

0 commit comments

Comments
 (0)