resolve: When suppressing out_of_scope_macro_calls suppress unused_imports as well

This commit is contained in:
Vadim Petrochenkov 2025-10-20 19:02:49 +03:00
parent fd847d4d5d
commit 078fe7ca29
2 changed files with 9 additions and 2 deletions

View file

@ -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 {

View file

@ -3,6 +3,7 @@
//@ check-pass
//@ edition:2018
#![warn(unused_imports)]
#![doc = in_root!()]
macro_rules! in_root { () => { "" } }