resolve: Refactor obtaining Module from its DefId

The `Option<Module>` version is supported for the case where we don't know whether the `DefId` refers to a module or not.
Non-local traits and enums are also correctly found now.
This commit is contained in:
Vadim Petrochenkov
2021-09-12 02:06:27 +03:00
parent a8021888c8
commit ab834e5ea9
6 changed files with 76 additions and 78 deletions

View File

@@ -799,7 +799,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}
fn with_scope<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
if let Some(module) = self.r.module_map.get(&self.r.local_def_id(id).to_def_id()).copied() {
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
// Move down in the graph.
let orig_module = replace(&mut self.parent_scope.module, module);
self.with_rib(ValueNS, ModuleRibKind(module), |this| {