Skip to content

Commit 273c898

Browse files
committed
Fix #10713 and move the tests to a subdir
1 parent c4f2c48 commit 273c898

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

clippy_lints/src/items_after_test_module.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,21 @@ impl LateLintPass<'_> for ItemsAfterTestModule {
6464
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");
6565
}};
6666

67-
if matches!(item.kind, ItemKind::Mod(_)) {
68-
for attr in cx.tcx.get_attrs(item.owner_id.to_def_id(), sym::cfg) {
69-
if_chain! {
70-
if attr.has_name(sym::cfg);
67+
if let ItemKind::Mod(module) = item.kind && item.span.hi() == module.spans.inner_span.hi() {
68+
// Check that it works the same way, the only I way I've found for #10713
69+
for attr in cx.tcx.get_attrs(item.owner_id.to_def_id(), sym::cfg) {
70+
if_chain! {
71+
if attr.has_name(sym::cfg);
7172
if let Some(mitems) = attr.meta_item_list();
7273
if let [mitem] = &*mitems;
7374
if mitem.has_name(sym::test);
7475
then {
75-
was_test_mod_visited = true;
76-
test_mod_span = Some(item.span);
76+
was_test_mod_visited = true;
77+
test_mod_span = Some(module.spans.inner_span.with_lo(item.span.lo()));
7778
}
7879
}
7980
}
80-
}
81+
}
8182
}
8283
}
8384
}

tests/ui/items_after_test_module.stderr renamed to tests/ui/items_after_test_module/block_module.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: items were found after the testing module
2-
--> $DIR/items_after_test_module.rs:13:1
2+
--> $DIR/block_module.rs:13:1
33
|
44
LL | / mod tests {
55
LL | | #[test]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@compile-flags: --test
2+
#![allow(unused)]
3+
#![warn(clippy::items_after_test_module)]
4+
5+
fn main() {}
6+
7+
fn should_not_lint() {}
8+
9+
#[cfg(test)]
10+
mod tests; // Should not lint
11+
12+
fn should_lint() {}
13+
14+
const SHOULD_ALSO_LINT: usize = 1;
15+
macro_rules! should_not_lint {
16+
() => {};
17+
}

tests/ui/items_after_test_module/imported_module.stderr

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}

0 commit comments

Comments
 (0)