Extract generic_params method to a HasGenericParams trait

This commit is contained in:
Florian Diebold 2019-04-14 13:07:45 +02:00
parent 4497e1d3ea
commit 8bcbcc454c
7 changed files with 33 additions and 37 deletions

View file

@ -11,7 +11,7 @@ use crate::{
expr::{Body, BodySourceMap},
ty::InferenceResult,
adt::{EnumVariantId, StructFieldId, VariantDef},
generics::GenericParams,
generics::HasGenericParams,
docs::{Documentation, Docs, docs_from_ast},
ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeAliasId},
impl_block::ImplBlock,
@ -299,10 +299,6 @@ impl Struct {
.map(|(id, _)| StructField { parent: (*self).into(), id })
}
pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
db.generic_params((*self).into())
}
pub fn ty(&self, db: &impl HirDatabase) -> Ty {
db.type_for_def((*self).into(), Namespace::Types)
}
@ -363,10 +359,6 @@ impl Enum {
.map(|(id, _)| EnumVariant { parent: *self, id })
}
pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
db.generic_params((*self).into())
}
pub fn ty(&self, db: &impl HirDatabase) -> Ty {
db.type_for_def((*self).into(), Namespace::Types)
}
@ -537,10 +529,6 @@ impl Function {
db.infer((*self).into())
}
pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
db.generic_params((*self).into())
}
/// The containing impl block, if this is a method.
pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> {
let module_impls = db.impls_in_module(self.module(db));
@ -696,10 +684,6 @@ impl Trait {
self.id.module(db)
}
pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
db.generic_params((*self).into())
}
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
self.trait_data(db).name().clone()
}
@ -737,10 +721,6 @@ impl TypeAlias {
self.id.source(db)
}
pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
db.generic_params((*self).into())
}
pub fn module(&self, db: &impl DefDatabase) -> Module {
self.id.module(db)
}