// in the last step
use crate::imports::ImportKind;
+use crate::module_to_string;
use crate::Resolver;
use rustc_ast as ast;
"remove the unused import"
};
+ let parent_module = visitor.r.get_nearest_non_block_module(
+ visitor.r.local_def_id(unused.use_tree_id).to_def_id(),
+ );
+ let test_module_span = match module_to_string(parent_module) {
+ Some(module)
+ if module == "test"
+ || module == "tests"
+ || module.starts_with("test_")
+ || module.starts_with("tests_")
+ || module.ends_with("_test")
+ || module.ends_with("_tests") =>
+ {
+ Some(parent_module.span)
+ }
+ _ => None,
+ };
+
visitor.r.lint_buffer.buffer_lint_with_diagnostic(
UNUSED_IMPORTS,
unused.use_tree_id,
ms,
&msg,
- BuiltinLintDiagnostics::UnusedImports(fix_msg.into(), fixes),
+ BuiltinLintDiagnostics::UnusedImports(fix_msg.into(), fixes, test_module_span),
);
}
}