From 078fe7ca29c1ec46e847e105415d718951e38922 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 20 Oct 2025 19:02:49 +0300 Subject: [PATCH] resolve: When suppressing `out_of_scope_macro_calls` suppress `unused_imports` as well --- compiler/rustc_resolve/src/macros.rs | 10 ++++++++-- tests/ui/attributes/key-value-expansion-scope-pass.rs | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index de71568e454a7..4a5894c9ffa86 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -1107,8 +1107,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // If such resolution is successful and gives the same result // (e.g. if the macro is re-imported), then silence the lint. let no_macro_rules = self.arenas.alloc_macro_rules_scope(MacroRulesScope::Empty); + let ident = path.segments[0].ident; let fallback_binding = self.reborrow().resolve_ident_in_scope_set( - path.segments[0].ident, + ident, ScopeSet::Macro(MacroKind::Bang), &ParentScope { macro_rules: no_macro_rules, ..*parent_scope }, None, @@ -1116,7 +1117,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { None, None, ); - if fallback_binding.ok().and_then(|b| b.res().opt_def_id()) != Some(def_id) { + if let Ok(fallback_binding) = fallback_binding + && fallback_binding.res().opt_def_id() == Some(def_id) + { + // Silence `unused_imports` on the fallback import as well. + self.get_mut().record_use(ident, fallback_binding, Used::Other); + } else { let location = match parent_scope.module.kind { ModuleKind::Def(kind, def_id, name) => { if let Some(name) = name { diff --git a/tests/ui/attributes/key-value-expansion-scope-pass.rs b/tests/ui/attributes/key-value-expansion-scope-pass.rs index 6b1f4e5bd4bf0..3a913b92c9741 100644 --- a/tests/ui/attributes/key-value-expansion-scope-pass.rs +++ b/tests/ui/attributes/key-value-expansion-scope-pass.rs @@ -3,6 +3,7 @@ //@ check-pass //@ edition:2018 +#![warn(unused_imports)] #![doc = in_root!()] macro_rules! in_root { () => { "" } }