Skip to content

Commit 078fe7c

Browse files
committed
resolve: When suppressing out_of_scope_macro_calls suppress unused_imports as well
1 parent fd847d4 commit 078fe7c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/rustc_resolve/src/macros.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,16 +1107,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11071107
// If such resolution is successful and gives the same result
11081108
// (e.g. if the macro is re-imported), then silence the lint.
11091109
let no_macro_rules = self.arenas.alloc_macro_rules_scope(MacroRulesScope::Empty);
1110+
let ident = path.segments[0].ident;
11101111
let fallback_binding = self.reborrow().resolve_ident_in_scope_set(
1111-
path.segments[0].ident,
1112+
ident,
11121113
ScopeSet::Macro(MacroKind::Bang),
11131114
&ParentScope { macro_rules: no_macro_rules, ..*parent_scope },
11141115
None,
11151116
false,
11161117
None,
11171118
None,
11181119
);
1119-
if fallback_binding.ok().and_then(|b| b.res().opt_def_id()) != Some(def_id) {
1120+
if let Ok(fallback_binding) = fallback_binding
1121+
&& fallback_binding.res().opt_def_id() == Some(def_id)
1122+
{
1123+
// Silence `unused_imports` on the fallback import as well.
1124+
self.get_mut().record_use(ident, fallback_binding, Used::Other);
1125+
} else {
11201126
let location = match parent_scope.module.kind {
11211127
ModuleKind::Def(kind, def_id, name) => {
11221128
if let Some(name) = name {

tests/ui/attributes/key-value-expansion-scope-pass.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//@ check-pass
44
//@ edition:2018
55

6+
#![warn(unused_imports)]
67
#![doc = in_root!()]
78

89
macro_rules! in_root { () => { "" } }

0 commit comments

Comments
 (0)