aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-03-31 19:02:16 +0100
committerFlorian Diebold <[email protected]>2019-04-14 10:28:53 +0100
commita1ed53a4f183b5826162eb9e998207b92be9c57f (patch)
tree7c139a7dc38483188653c6d40583cddac9d23192 /crates/ra_hir/src/code_model_api.rs
parent413c87f155ab6b389b1cc122b5739716acccb476 (diff)
More trait infrastructure
- make it possible to get parent trait from method - add 'obligation' machinery for checking that a type implements a trait (and inferring facts about type variables from that) - handle type parameters of traits (to a certain degree) - improve the hacky implements check to cover enough cases to exercise the handling of traits with type parameters - basic canonicalization (will probably also be done by Chalk)
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 5d8cf57b6..b53fe1f63 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -194,7 +194,7 @@ impl Module {
194 Resolver::default().push_module_scope(def_map, self.module_id) 194 Resolver::default().push_module_scope(def_map, self.module_id)
195 } 195 }
196 196
197 pub fn declarations(self, db: &impl HirDatabase) -> Vec<ModuleDef> { 197 pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> {
198 let def_map = db.crate_def_map(self.krate); 198 let def_map = db.crate_def_map(self.krate);
199 def_map[self.module_id] 199 def_map[self.module_id]
200 .scope 200 .scope
@@ -547,13 +547,20 @@ impl Function {
547 ImplBlock::containing(module_impls, (*self).into()) 547 ImplBlock::containing(module_impls, (*self).into())
548 } 548 }
549 549
550 /// The containing trait, if this is a trait method definition.
551 pub fn parent_trait(&self, db: &impl DefDatabase) -> Option<Trait> {
552 db.trait_items_index(self.module(db)).get_parent_trait((*self).into())
553 }
554
550 // FIXME: move to a more general type for 'body-having' items 555 // FIXME: move to a more general type for 'body-having' items
551 /// Builds a resolver for code inside this item. 556 /// Builds a resolver for code inside this item.
552 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 557 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
553 // take the outer scope... 558 // take the outer scope...
559 // FIXME abstract over containers (trait/impl)
554 let r = self 560 let r = self
555 .impl_block(db) 561 .impl_block(db)
556 .map(|ib| ib.resolver(db)) 562 .map(|ib| ib.resolver(db))
563 .or_else(|| self.parent_trait(db).map(|tr| tr.resolver(db)))
557 .unwrap_or_else(|| self.module(db).resolver(db)); 564 .unwrap_or_else(|| self.module(db).resolver(db));
558 // ...and add generic params, if present 565 // ...and add generic params, if present
559 let p = self.generic_params(db); 566 let p = self.generic_params(db);
@@ -699,6 +706,14 @@ impl Trait {
699 pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> { 706 pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> {
700 db.trait_data(self) 707 db.trait_data(self)
701 } 708 }
709
710 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
711 let r = self.module(db).resolver(db);
712 // add generic params, if present
713 let p = self.generic_params(db);
714 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
715 r
716 }
702} 717}
703 718
704impl Docs for Trait { 719impl Docs for Trait {