Skip to content

Commit aedf892

Browse files
petrochenkovLorrensP-2158466
authored andcommitted
resolve: Use module_map and get_module less
1 parent f2f0c31 commit aedf892

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
27722772
}
27732773

27742774
/// Finds a cfg-ed out item inside `module` with the matching name.
2775-
pub(crate) fn find_cfg_stripped(&self, err: &mut Diag<'_>, segment: &Symbol, module: DefId) {
2775+
pub(crate) fn find_cfg_stripped(
2776+
&mut self,
2777+
err: &mut Diag<'_>,
2778+
segment: &Symbol,
2779+
module: DefId,
2780+
) {
27762781
let local_items;
27772782
let symbols = if module.is_local() {
27782783
local_items = self
@@ -2798,7 +2803,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
27982803
}
27992804

28002805
fn comes_from_same_module_for_glob(
2801-
r: &Resolver<'_, '_>,
2806+
r: &mut Resolver<'_, '_>,
28022807
parent_module: DefId,
28032808
module: DefId,
28042809
visited: &mut FxHashMap<DefId, bool>,
@@ -2810,24 +2815,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
28102815
return cached;
28112816
}
28122817
visited.insert(parent_module, false);
2813-
let res = r.module_map.get(&parent_module).is_some_and(|m| {
2814-
for importer in m.glob_importers.borrow().iter() {
2815-
if let Some(next_parent_module) = importer.parent_scope.module.opt_def_id()
2818+
let m = r.expect_module(parent_module);
2819+
let mut res = false;
2820+
for importer in m.glob_importers.borrow().iter() {
2821+
if let Some(next_parent_module) = importer.parent_scope.module.opt_def_id() {
2822+
if next_parent_module == module
2823+
|| comes_from_same_module_for_glob(
2824+
r,
2825+
next_parent_module,
2826+
module,
2827+
visited,
2828+
)
28162829
{
2817-
if next_parent_module == module
2818-
|| comes_from_same_module_for_glob(
2819-
r,
2820-
next_parent_module,
2821-
module,
2822-
visited,
2823-
)
2824-
{
2825-
return true;
2826-
}
2830+
res = true;
2831+
break;
28272832
}
28282833
}
2829-
false
2830-
});
2834+
}
28312835
visited.insert(parent_module, res);
28322836
res
28332837
}

compiler/rustc_resolve/src/effective_visibilities.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
113113
/// Update effective visibilities of bindings in the given module,
114114
/// including their whole reexport chains.
115115
fn set_bindings_effective_visibilities(&mut self, module_id: LocalDefId) {
116-
assert!(self.r.module_map.contains_key(&module_id.to_def_id()));
117-
let module = self.r.get_module(module_id.to_def_id()).unwrap();
116+
let module = self.r.expect_module(module_id.to_def_id());
118117
let resolutions = self.r.resolutions(module);
119118

120119
for (_, name_resolution) in resolutions.borrow().iter() {

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
924924
continue;
925925
};
926926
if let Res::Def(DefKind::Mod, module) = res.expect_full_res()
927-
&& let Some(module) = self.r.get_module(module)
927+
&& let module = self.r.expect_module(module)
928928
&& let item = path[idx + 1].ident
929929
&& let Some(did) = find_doc_alias_name(self.r, module, item.name)
930930
{
@@ -2526,16 +2526,14 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
25262526
// FIXME: this is not totally accurate, but mostly works
25272527
suggestion.candidate != following_seg.ident.name
25282528
}
2529-
Res::Def(DefKind::Mod, def_id) => self.r.get_module(def_id).map_or_else(
2530-
|| false,
2531-
|module| {
2532-
self.r
2533-
.resolutions(module)
2534-
.borrow()
2535-
.iter()
2536-
.any(|(key, _)| key.ident.name == following_seg.ident.name)
2537-
},
2538-
),
2529+
Res::Def(DefKind::Mod, def_id) => {
2530+
let module = self.r.expect_module(def_id);
2531+
self.r
2532+
.resolutions(module)
2533+
.borrow()
2534+
.iter()
2535+
.any(|(key, _)| key.ident.name == following_seg.ident.name)
2536+
}
25392537
_ => true,
25402538
});
25412539
}

0 commit comments

Comments
 (0)