Skip to content

Commit 79e42cf

Browse files
authored
Rollup merge of rust-lang#138882 - oli-obk:ast-lowering-mod-rib, r=fee1-dead
`with_scope` is only ever used for ast modules Thus I renamed it to match other similar functions (`with_mod_rib`) and made it panic if used on non-modules
2 parents c4f14db + 2d3115f commit 79e42cf

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Diff for: compiler/rustc_resolve/src/late.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -1544,20 +1544,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
15441544
ret
15451545
}
15461546

1547-
fn with_scope<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1548-
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
1549-
// Move down in the graph.
1550-
let orig_module = replace(&mut self.parent_scope.module, module);
1551-
self.with_rib(ValueNS, RibKind::Module(module), |this| {
1552-
this.with_rib(TypeNS, RibKind::Module(module), |this| {
1553-
let ret = f(this);
1554-
this.parent_scope.module = orig_module;
1555-
ret
1556-
})
1547+
fn with_mod_rib<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1548+
let module = self.r.expect_module(self.r.local_def_id(id).to_def_id());
1549+
// Move down in the graph.
1550+
let orig_module = replace(&mut self.parent_scope.module, module);
1551+
self.with_rib(ValueNS, RibKind::Module(module), |this| {
1552+
this.with_rib(TypeNS, RibKind::Module(module), |this| {
1553+
let ret = f(this);
1554+
this.parent_scope.module = orig_module;
1555+
ret
15571556
})
1558-
} else {
1559-
f(self)
1560-
}
1557+
})
15611558
}
15621559

15631560
fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper: bool) {
@@ -2738,7 +2735,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
27382735
}
27392736

27402737
ItemKind::Mod(..) => {
2741-
self.with_scope(item.id, |this| {
2738+
self.with_mod_rib(item.id, |this| {
27422739
if mod_inner_docs {
27432740
this.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
27442741
}

0 commit comments

Comments
 (0)