diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 961cdb317e7..66b79513032 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; -use rustc_ast::{ptr::P, Crate, Item, ItemKind, MacroDef, ModKind, UseTreeKind, VisibilityKind}; +use rustc_ast::{ptr::P, Crate, Item, ItemKind, MacroDef, ModKind, UseTreeKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -76,14 +76,13 @@ fn check_mod(cx: &EarlyContext<'_>, items: &[P]) { ); } - for single_use in &single_use_usages { - if !imports_reused_with_self.contains(&single_use.0) { - let can_suggest = single_use.2; + for (name, span, can_suggest) in single_use_usages { + if !imports_reused_with_self.contains(&name) { if can_suggest { span_lint_and_sugg( cx, SINGLE_COMPONENT_PATH_IMPORTS, - single_use.1, + span, "this import is redundant", "remove it entirely", String::new(), @@ -93,7 +92,7 @@ fn check_mod(cx: &EarlyContext<'_>, items: &[P]) { span_lint_and_help( cx, SINGLE_COMPONENT_PATH_IMPORTS, - single_use.1, + span, "this import is redundant", None, "remove this import", @@ -124,14 +123,11 @@ fn track_uses( ItemKind::Use(use_tree) => { let segments = &use_tree.prefix.segments; - let should_report = - |name: &Symbol| !macros.contains(name) || matches!(item.vis.kind, VisibilityKind::Inherited); - // keep track of `use some_module;` usages if segments.len() == 1 { if let UseTreeKind::Simple(None, _, _) = use_tree.kind { let name = segments[0].ident.name; - if should_report(&name) { + if !macros.contains(&name) { single_use_usages.push((name, item.span, true)); } } @@ -146,7 +142,7 @@ fn track_uses( if segments.len() == 1 { if let UseTreeKind::Simple(None, _, _) = tree.0.kind { let name = segments[0].ident.name; - if should_report(&name) { + if !macros.contains(&name) { single_use_usages.push((name, tree.0.span, false)); } } diff --git a/tests/ui/single_component_path_imports_macro.fixed b/tests/ui/single_component_path_imports_macro.fixed deleted file mode 100644 index e43f5d381aa..00000000000 --- a/tests/ui/single_component_path_imports_macro.fixed +++ /dev/null @@ -1,20 +0,0 @@ -// run-rustfix -#![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] - -// #7106: use statements exporting a macro within a crate should not trigger lint - -macro_rules! m1 { - () => {}; -} -pub(crate) use m1; // ok - -macro_rules! m2 { - () => {}; -} - // fail - -fn main() { - m1!(); - m2!(); -} diff --git a/tests/ui/single_component_path_imports_macro.rs b/tests/ui/single_component_path_imports_macro.rs index 3c65ca3054c..fda294a6154 100644 --- a/tests/ui/single_component_path_imports_macro.rs +++ b/tests/ui/single_component_path_imports_macro.rs @@ -1,8 +1,8 @@ -// run-rustfix #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] // #7106: use statements exporting a macro within a crate should not trigger lint +// #7923: normal `use` statements of macros should also not trigger the lint macro_rules! m1 { () => {}; @@ -12,7 +12,7 @@ pub(crate) use m1; // ok macro_rules! m2 { () => {}; } -use m2; // fail +use m2; // ok fn main() { m1!(); diff --git a/tests/ui/single_component_path_imports_macro.stderr b/tests/ui/single_component_path_imports_macro.stderr deleted file mode 100644 index 37d5176129f..00000000000 --- a/tests/ui/single_component_path_imports_macro.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: this import is redundant - --> $DIR/single_component_path_imports_macro.rs:15:1 - | -LL | use m2; // fail - | ^^^^^^^ help: remove it entirely - | - = note: `-D clippy::single-component-path-imports` implied by `-D warnings` - -error: aborting due to previous error -