Use the new Resolver API for goto def

This commit is contained in:
Florian Diebold 2019-01-29 20:49:31 +01:00
parent 33ff7b56ff
commit afce8e4426
6 changed files with 89 additions and 35 deletions

View file

@ -9,7 +9,7 @@ use crate::{
name::{Name, KnownName},
nameres::{PerNs, ItemMap},
generics::GenericParams,
expr::{scope::{ExprScopes, ScopeId}, PatId},
expr::{scope::{ExprScopes, ScopeId}, PatId, Body},
impl_block::ImplBlock,
path::Path,
};
@ -106,15 +106,21 @@ impl Resolver {
}
fn module(&self) -> Option<(&ItemMap, Module)> {
for scope in self.scopes.iter().rev() {
match scope {
Scope::ModuleScope(m) => {
return Some((&m.item_map, m.module.clone()));
}
_ => {}
}
}
None
self.scopes.iter().rev().find_map(|scope| match scope {
Scope::ModuleScope(m) => Some((&*m.item_map, m.module.clone())),
Scope::ModuleScopeRef(m) => Some((m.item_map, m.module.clone())),
_ => None,
})
}
/// The body from which any `LocalBinding` resolutions in this resolver come.
pub fn body(&self) -> Option<Arc<Body>> {
self.scopes.iter().rev().find_map(|scope| match scope {
Scope::ExprScope(expr_scope) => Some(expr_scope.expr_scopes.body()),
_ => None,
})
}
}