diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs
index 307625bcfb1..d57dabdd78d 100644
--- a/compiler/rustc_resolve/src/build_reduced_graph.rs
+++ b/compiler/rustc_resolve/src/build_reduced_graph.rs
@@ -374,7 +374,6 @@ fn add_import(
root_span,
root_id,
vis,
- used: Default::default(),
});
self.r.indeterminate_imports.push(import);
@@ -890,8 +889,10 @@ fn build_reduced_graph_for_extern_crate(
span: item.span,
module_path: Vec::new(),
vis,
- used: Cell::new(used.then_some(Used::Other)),
});
+ if used {
+ self.r.import_use_map.insert(import, Used::Other);
+ }
self.r.potentially_unused_imports.push(import);
let imported_binding = self.r.import(binding, import);
if parent == self.r.graph_root {
@@ -1091,7 +1092,6 @@ fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool
span,
module_path: Vec::new(),
vis: ty::Visibility::Restricted(CRATE_DEF_ID),
- used: Default::default(),
})
};
@@ -1256,8 +1256,8 @@ fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> {
span,
module_path: Vec::new(),
vis,
- used: Cell::new(Some(Used::Other)),
});
+ self.r.import_use_map.insert(import, Used::Other);
let import_binding = self.r.import(binding, import);
self.r.define(self.r.graph_root, ident, MacroNS, import_binding);
} else {
diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs
index 75b8ecebdd9..1cee876b80f 100644
--- a/compiler/rustc_resolve/src/check_unused.rs
+++ b/compiler/rustc_resolve/src/check_unused.rs
@@ -381,9 +381,9 @@ pub(crate) fn check_unused(&mut self, krate: &ast::Crate) {
for import in self.potentially_unused_imports.iter() {
match import.kind {
- _ if import.used.get().is_some()
- || import.vis.is_public()
- || import.span.is_dummy() =>
+ _ if import.vis.is_public()
+ || import.span.is_dummy()
+ || self.import_use_map.contains_key(import) =>
{
if let ImportKind::MacroUse { .. } = import.kind {
if !import.span.is_dummy() {
diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs
index 4a891d12281..42171edf757 100644
--- a/compiler/rustc_resolve/src/imports.rs
+++ b/compiler/rustc_resolve/src/imports.rs
@@ -176,7 +176,6 @@ pub(crate) struct ImportData<'a> {
/// The resolution of `module_path`.
pub imported_module: Cell