use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
-use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type};
+use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type, ImplBlock};
/// Data about a generic parameter (to a function, struct, impl, ...).
#[derive(Clone, PartialEq, Eq, Debug)]
Enum(Enum),
Trait(Trait),
Type(Type),
+ ImplBlock(ImplBlock),
}
-impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type);
+impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type, ImplBlock);
impl GenericParams {
pub(crate) fn generic_params_query(
GenericDef::Enum(it) => generics.fill(&*it.source(db).1),
GenericDef::Trait(it) => generics.fill(&*it.source(db).1),
GenericDef::Type(it) => generics.fill(&*it.source(db).1),
+ GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1),
}
Arc::new(generics)
type_ref::TypeRef,
ids::LocationCtx,
resolve::Resolver,
- ty::Ty,
+ ty::Ty, generics::GenericParams
};
use crate::code_model_api::{Module, ModuleSource};
}
}
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ImplBlock {
module: Module,
impl_id: ImplId,
}
/// Returns the syntax of the impl block
- pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
+ pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
let source_map = db.impls_in_module_source_map(self.module);
let (file_id, source) = self.module.definition_source(db);
(file_id, source_map.get(&source, self.impl_id))
self.module
}
- pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TypeRef> {
+ pub fn target_trait_ref(&self, db: &impl PersistentHirDatabase) -> Option<TypeRef> {
db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned()
}
- pub fn target_type(&self, db: &impl HirDatabase) -> TypeRef {
+ pub fn target_type(&self, db: &impl PersistentHirDatabase) -> TypeRef {
db.impls_in_module(self.module).impls[self.impl_id].target_type().clone()
}
None
}
- pub fn items(&self, db: &impl HirDatabase) -> Vec<ImplItem> {
+ pub fn items(&self, db: &impl PersistentHirDatabase) -> Vec<ImplItem> {
db.impls_in_module(self.module).impls[self.impl_id].items().to_vec()
}
+ pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
+ db.generic_params((*self).into())
+ }
+
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
let r = self.module().resolver(db);
// TODO: add generics