Basics for trait method resolution

This commit is contained in:
Florian Diebold 2019-03-24 17:36:15 +01:00
parent bb77bc5c2f
commit c947c15ce1
11 changed files with 156 additions and 25 deletions

View file

@ -11,7 +11,7 @@ use crate::{
generics::GenericParams,
expr::{scope::{ExprScopes, ScopeId}, PatId, Body},
impl_block::ImplBlock,
path::Path,
path::Path, Trait
};
#[derive(Debug, Clone, Default)]
@ -175,6 +175,21 @@ impl Resolver {
names
}
pub(crate) fn traits_in_scope<'a>(&'a self) -> impl Iterator<Item = Trait> + 'a {
// FIXME prelude
self.scopes
.iter()
.rev()
.flat_map(|scope| {
match scope {
Scope::ModuleScope(m) => Some(m.crate_def_map[m.module_id].scope.traits()),
_ => None,
}
.into_iter()
})
.flat_map(|i| i)
}
fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> {
self.scopes.iter().rev().find_map(|scope| match scope {
Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)),