From 4daf931111029cee9bb43691f88c32f0aa47a802 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Nov 2019 16:23:02 +0300 Subject: Remove old hir::generics module --- crates/ra_hir/src/code_model.rs | 46 ++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir/src/code_model.rs') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 92860fb59..5690040a7 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -27,7 +27,6 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, - generics::{GenericDef, HasGenericParams}, ids::{ AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, TypeAliasId, @@ -835,7 +834,7 @@ impl Trait { // lifetime problems, but since there usually shouldn't be more than a // few direct traits this should be fine (we could even use some kind of // SmallVec if performance is a concern) - self.generic_params(db) + db.generic_params(self.id.into()) .where_predicates .iter() .filter_map(|pred| match &pred.type_ref { @@ -975,16 +974,6 @@ pub enum AssocItem { // casting them, and somehow making the constructors private, which would be annoying. impl_froms!(AssocItem: Function, Const, TypeAlias); -impl From for crate::generics::GenericDef { - fn from(item: AssocItem) -> Self { - match item { - AssocItem::Function(f) => f.into(), - AssocItem::Const(c) => c.into(), - AssocItem::TypeAlias(t) => t.into(), - } - } -} - impl AssocItem { pub fn module(self, db: &impl DefDatabase) -> Module { match self { @@ -1004,6 +993,39 @@ impl AssocItem { } } +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +pub enum GenericDef { + Function(Function), + Adt(Adt), + Trait(Trait), + TypeAlias(TypeAlias), + ImplBlock(ImplBlock), + // enum variants cannot have generics themselves, but their parent enums + // can, and this makes some code easier to write + EnumVariant(EnumVariant), + // consts can have type parameters from their parents (i.e. associated consts of traits) + Const(Const), +} +impl_froms!( + GenericDef: Function, + Adt(Struct, Enum, Union), + Trait, + TypeAlias, + ImplBlock, + EnumVariant, + Const +); + +impl From for GenericDef { + fn from(item: AssocItem) -> Self { + match item { + AssocItem::Function(f) => f.into(), + AssocItem::Const(c) => c.into(), + AssocItem::TypeAlias(t) => t.into(), + } + } +} + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct Local { pub(crate) parent: DefWithBody, -- cgit v1.2.3