Auto merge of #147914 - petrochenkov:oosmc-used, r=fmease

resolve: When suppressing `out_of_scope_macro_calls` suppress `unused_imports` as well

Fixes the example from this comment - https://github.com/rust-lang/rust/issues/147823#issuecomment-3421770900.
Fixes https://github.com/rust-lang/rust/issues/148143.
This commit is contained in:
bors 2025-10-26 23:44:52 +00:00
commit b1b464d6f6
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 { () => { "" } }