mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 01:17:16 +00:00
Auto merge of #10719 - blyxyas:fix-items_after_test_mod_imported_modules, r=Alexendoo
Fix `items_after_test_module`: Ignore imported modules Fixes #10713. It does a little bit of dark magic, but intention is what really counts. changelog:[`items_after_test_module`]: Ignore imported modules (`mod foo;`) with no body.
This commit is contained in:
commit
3594d55439
5 changed files with 29 additions and 7 deletions
|
@ -64,7 +64,8 @@ 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(_)) {
|
||||
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);
|
||||
|
|
1
tests/ui/items_after_test_module/auxiliary/tests.rs
Normal file
1
tests/ui/items_after_test_module/auxiliary/tests.rs
Normal file
|
@ -0,0 +1 @@
|
|||
fn main() {}
|
|
@ -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]
|
20
tests/ui/items_after_test_module/imported_module.rs
Normal file
20
tests/ui/items_after_test_module/imported_module.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
//@compile-flags: --test
|
||||
#![allow(unused)]
|
||||
#![warn(clippy::items_after_test_module)]
|
||||
|
||||
// Nothing here should lint, as `tests` is an imported module (that has no body).
|
||||
|
||||
fn main() {}
|
||||
|
||||
fn should_not_lint() {}
|
||||
|
||||
#[path = "auxiliary/tests.rs"]
|
||||
#[cfg(test)]
|
||||
mod tests; // Should not lint
|
||||
|
||||
fn should_not_lint2() {}
|
||||
|
||||
const SHOULD_ALSO_NOT_LINT: usize = 1;
|
||||
macro_rules! should_not_lint {
|
||||
() => {};
|
||||
}
|
Loading…
Reference in a new issue