Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
match def_id.as_local() {
Some(local_def_id) => self.local_module_map.get(&local_def_id).map(|m| m.to_module()),
None => {
if let module @ Some(..) = self.extern_module_map.borrow().get(&def_id) {
return module.map(|m| m.to_module());
if let Some(module) = self.extern_module_map.borrow().get(&def_id) {
return module.map(ExternModule::to_module);
}
// We need the lock on the extern_module_map for the entire duration of this call.
// It is otherwise entirely possible 2 different threads will create and allocate
Expand All @@ -135,10 +135,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
fn get_extern_module_with_lock(
&self,
def_id: DefId,
map_lock: &mut RefMut<'_, FxIndexMap<DefId, ExternModule<'ra>>>,
map_lock: &mut RefMut<'_, FxIndexMap<DefId, Option<ExternModule<'ra>>>>,
) -> Option<ExternModule<'ra>> {
if let module @ Some(..) = map_lock.get(&def_id) {
return module.copied();
if let Some(module) = map_lock.get(&def_id) {
return *module;
}
// Query `def_kind` is not used because query system overhead is too expensive here.
let def_kind = self.cstore().def_kind_untracked(def_id);
Expand All @@ -164,10 +164,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
parent.is_some_and(|module| module.no_implicit_prelude),
self.arenas,
);
map_lock.insert(def_id, module);
map_lock.insert(def_id, Some(module));
return Some(module);
}

map_lock.insert(def_id, None);
None
}

Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_resolve/src/diagnostics/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2975,12 +2975,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
.chain(
self.extern_module_map
.borrow()
.iter()
.filter(|(_, module)| {
.values()
.filter_map(|module| *module)
.filter(|module| {
let module = module.to_module();
current_module.is_ancestor_of(module) && current_module != module
})
.flat_map(|(_, module)| module.name()),
.flat_map(|module| module.name()),
)
.filter(|c| !c.to_string().is_empty())
.collect::<Vec<_>>();
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1403,8 +1403,9 @@ pub struct Resolver<'ra, 'tcx> {
local_modules: Vec<LocalModule<'ra>>,
/// Eagerly populated map of all local non-block modules.
local_module_map: FxIndexMap<LocalDefId, LocalModule<'ra>>,
/// Lazily populated cache of modules loaded from external crates.
extern_module_map: CacheRefCell<FxIndexMap<DefId, ExternModule<'ra>>>,
/// Lazily populated cache of modules loaded from external crates. `None` records an
/// immutable external definition that is not a module.
extern_module_map: CacheRefCell<FxIndexMap<DefId, Option<ExternModule<'ra>>>>,

/// Maps glob imports to the names of items actually imported.
glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
Expand Down