about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/items_after_test_module.rs15
-rw-r--r--tests/ui/items_after_test_module/block_module.rs (renamed from tests/ui/items_after_test_module.rs)0
-rw-r--r--tests/ui/items_after_test_module/block_module.stderr (renamed from tests/ui/items_after_test_module.stderr)2
-rw-r--r--tests/ui/items_after_test_module/imported_module.rs17
-rw-r--r--tests/ui/items_after_test_module/imported_module.stderr0
-rw-r--r--tests/ui/items_after_test_module/tests/mod.rs1
6 files changed, 27 insertions, 8 deletions
diff --git a/clippy_lints/src/items_after_test_module.rs b/clippy_lints/src/items_after_test_module.rs
index 52d716feea0..96097575c9c 100644
--- a/clippy_lints/src/items_after_test_module.rs
+++ b/clippy_lints/src/items_after_test_module.rs
@@ -64,20 +64,21 @@ impl LateLintPass<'_> for ItemsAfterTestModule {
                 span_lint_and_help(cx, ITEMS_AFTER_TEST_MODULE, test_mod_span.unwrap().with_hi(item.span.hi()), "items were found after the testing module", None, "move the items to before the testing module was defined");
             }};
 
-            if matches!(item.kind, ItemKind::Mod(_)) {
-                for attr in cx.tcx.get_attrs(item.owner_id.to_def_id(), sym::cfg) {
-                    if_chain! {
-                        if attr.has_name(sym::cfg);
+            if let ItemKind::Mod(module) = item.kind && item.span.hi() == module.spans.inner_span.hi() {
+			// Check that it works the same way, the only I way I've found for #10713
+				for attr in cx.tcx.get_attrs(item.owner_id.to_def_id(), sym::cfg) {
+					if_chain! {
+						if attr.has_name(sym::cfg);
                         if let Some(mitems) = attr.meta_item_list();
                         if let [mitem] = &*mitems;
                         if mitem.has_name(sym::test);
                         then {
-                            was_test_mod_visited = true;
-                            test_mod_span = Some(item.span);
+							was_test_mod_visited = true;
+                            test_mod_span = Some(module.spans.inner_span.with_lo(item.span.lo()));
                         }
                     }
                 }
-            }
+			}
         }
     }
 }
diff --git a/tests/ui/items_after_test_module.rs b/tests/ui/items_after_test_module/block_module.rs
index 5136b2557ec..5136b2557ec 100644
--- a/tests/ui/items_after_test_module.rs
+++ b/tests/ui/items_after_test_module/block_module.rs
diff --git a/tests/ui/items_after_test_module.stderr b/tests/ui/items_after_test_module/block_module.stderr
index 8f1616dabc1..597f1b9510c 100644
--- a/tests/ui/items_after_test_module.stderr
+++ b/tests/ui/items_after_test_module/block_module.stderr
@@ -1,5 +1,5 @@
 error: items were found after the testing module
-  --> $DIR/items_after_test_module.rs:13:1
+  --> $DIR/block_module.rs:13:1
    |
 LL | / mod tests {
 LL | |     #[test]
diff --git a/tests/ui/items_after_test_module/imported_module.rs b/tests/ui/items_after_test_module/imported_module.rs
new file mode 100644
index 00000000000..819b6c8a9e0
--- /dev/null
+++ b/tests/ui/items_after_test_module/imported_module.rs
@@ -0,0 +1,17 @@
+//@compile-flags: --test
+#![allow(unused)]
+#![warn(clippy::items_after_test_module)]
+
+fn main() {}
+
+fn should_not_lint() {}
+
+#[cfg(test)]
+mod tests; // Should not lint
+
+fn should_lint() {}
+
+const SHOULD_ALSO_LINT: usize = 1;
+macro_rules! should_not_lint {
+    () => {};
+}
diff --git a/tests/ui/items_after_test_module/imported_module.stderr b/tests/ui/items_after_test_module/imported_module.stderr
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/tests/ui/items_after_test_module/imported_module.stderr
diff --git a/tests/ui/items_after_test_module/tests/mod.rs b/tests/ui/items_after_test_module/tests/mod.rs
new file mode 100644
index 00000000000..f328e4d9d04
--- /dev/null
+++ b/tests/ui/items_after_test_module/tests/mod.rs
@@ -0,0 +1 @@
+fn main() {}