Handle impl generics in method calls

This commit is contained in:
Florian Diebold 2019-02-16 22:06:23 +01:00
parent 2af067b391
commit 65bd9bc3a8
7 changed files with 122 additions and 77 deletions

View file

@ -463,7 +463,7 @@ impl Function {
self.id.source(db)
}
pub fn module(&self, db: &impl HirDatabase) -> Module {
pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
self.id.module(db)
}
@ -497,6 +497,12 @@ impl Function {
db.generic_params((*self).into())
}
/// The containing impl block, if this is a method.
pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> {
let module_impls = db.impls_in_module(self.module(db));
ImplBlock::containing(module_impls, (*self).into())
}
// TODO: move to a more general type for 'body-having' items
/// Builds a resolver for code inside this item.
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
@ -527,6 +533,16 @@ impl Const {
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
self.id.source(db)
}
pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
self.id.module(db)
}
/// The containing impl block, if this is a method.
pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> {
let module_impls = db.impls_in_module(self.module(db));
ImplBlock::containing(module_impls, (*self).into())
}
}
impl Docs for Const {
@ -544,6 +560,10 @@ impl Static {
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
self.id.source(db)
}
pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
self.id.module(db)
}
}
impl Docs for Static {
@ -562,6 +582,10 @@ impl Trait {
self.id.source(db)
}
pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
self.id.module(db)
}
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
db.generic_params((*self).into())
}
@ -586,6 +610,16 @@ impl Type {
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
db.generic_params((*self).into())
}
pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
self.id.module(db)
}
/// The containing impl block, if this is a method.
pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> {
let module_impls = db.impls_in_module(self.module(db));
ImplBlock::containing(module_impls, (*self).into())
}
}
impl Docs for Type {