From c2a16632d0773dec707acb215297ef55b5c880fe Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 25 Nov 2019 15:39:12 +0300 Subject: Use GenericDefId more --- crates/ra_hir/src/db.rs | 4 ++-- crates/ra_hir/src/from_id.rs | 17 ++--------------- crates/ra_hir/src/ty.rs | 6 +++--- crates/ra_hir/src/ty/lower.rs | 16 ++++++++-------- crates/ra_hir/src/ty/traits/chalk.rs | 10 +++++----- 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 5084bbacf..7ec04ad73 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -24,7 +24,7 @@ pub use hir_def::{ RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery, }, - LocalStructFieldId, VariantId, + GenericDefId, LocalStructFieldId, VariantId, }; pub use hir_expand::db::{ AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, @@ -54,7 +54,7 @@ pub trait HirDatabase: DefDatabase { ) -> Arc<[GenericPredicate]>; #[salsa::invoke(crate::ty::generic_predicates_query)] - fn generic_predicates(&self, def: GenericDef) -> Arc<[GenericPredicate]>; + fn generic_predicates(&self, def: GenericDefId) -> Arc<[GenericPredicate]>; #[salsa::invoke(crate::ty::generic_defaults_query)] fn generic_defaults(&self, def: GenericDef) -> Substs; diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index 529ac8251..3a27d6f0c 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs @@ -9,9 +9,8 @@ use hir_def::{ }; use crate::{ - ty::{CallableDef, TypableDef}, - Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, - ModuleDef, Static, StructField, TypeAlias, VariantDef, + ty::TypableDef, Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, + GenericDef, ModuleDef, Static, StructField, TypeAlias, VariantDef, }; impl From for Crate { @@ -214,18 +213,6 @@ impl From for GenericDefId { } } -impl From for GenericDefId { - fn from(def: CallableDef) -> Self { - match def { - CallableDef::Function(it) => it.id.into(), - CallableDef::Struct(it) => it.id.into(), - CallableDef::EnumVariant(it) => { - EnumVariantId { parent: it.parent.id, local_id: it.id }.into() - } - } - } -} - impl From for VariantId { fn from(def: VariantDef) -> Self { match def { diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index f62316c1f..2473ac574 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -17,7 +17,7 @@ use std::ops::Deref; use std::sync::Arc; use std::{fmt, iter, mem}; -use hir_def::{generics::GenericParams, AdtId}; +use hir_def::{generics::GenericParams, AdtId, GenericDefId}; use ra_db::{impl_intern_key, salsa}; use crate::{ @@ -176,7 +176,7 @@ impl TypeCtor { } } - pub fn as_generic_def(self) -> Option { + pub fn as_generic_def(self) -> Option { match self { TypeCtor::Bool | TypeCtor::Char @@ -193,7 +193,7 @@ impl TypeCtor { | TypeCtor::Closure { .. } => None, TypeCtor::Adt(adt) => Some(adt.into()), TypeCtor::FnDef(callable) => Some(callable.into()), - TypeCtor::AssociatedType(type_alias) => Some(type_alias.into()), + TypeCtor::AssociatedType(type_alias) => Some(type_alias.id.into()), } } } diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index b76929501..da3c8e94a 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -14,7 +14,7 @@ use hir_def::{ path::{GenericArg, PathSegment}, resolver::{HasResolver, Resolver, TypeNs}, type_ref::{TypeBound, TypeRef}, - AdtId, GenericDefId, LocalStructFieldId, VariantId, + AdtId, EnumVariantId, GenericDefId, LocalStructFieldId, VariantId, }; use ra_arena::map::ArenaMap; @@ -605,9 +605,9 @@ impl TraitEnvironment { /// Resolve the where clause(s) of an item with generics. pub(crate) fn generic_predicates_query( db: &impl HirDatabase, - def: GenericDef, + def: GenericDefId, ) -> Arc<[GenericPredicate]> { - let resolver = GenericDefId::from(def).resolver(db); + let resolver = def.resolver(db); resolver .where_predicates_in_scope() .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred)) @@ -819,12 +819,12 @@ impl CallableDef { } } -impl From for GenericDef { - fn from(def: CallableDef) -> GenericDef { +impl From for GenericDefId { + fn from(def: CallableDef) -> GenericDefId { match def { - CallableDef::Function(f) => f.into(), - CallableDef::Struct(s) => s.into(), - CallableDef::EnumVariant(e) => e.into(), + CallableDef::Function(f) => f.id.into(), + CallableDef::Struct(s) => s.id.into(), + CallableDef::EnumVariant(e) => EnumVariantId::from(e).into(), } } } diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 1a93e5e50..a0dbf6305 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -9,7 +9,7 @@ use chalk_ir::{ }; use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; -use hir_def::lang_item::LangItemTarget; +use hir_def::{lang_item::LangItemTarget, GenericDefId}; use hir_expand::name; use ra_db::salsa::{InternId, InternKey}; @@ -19,7 +19,7 @@ use crate::{ db::HirDatabase, ty::display::HirDisplay, ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, - Crate, GenericDef, ImplBlock, Trait, TypeAlias, + Crate, ImplBlock, Trait, TypeAlias, }; /// This represents a trait whose name we could not resolve. @@ -402,7 +402,7 @@ fn make_binders(value: T, num_vars: usize) -> chalk_ir::Binders { fn convert_where_clauses( db: &impl HirDatabase, - def: GenericDef, + def: GenericDefId, substs: &Substs, ) -> Vec> { let generic_predicates = db.generic_predicates(def); @@ -561,7 +561,7 @@ pub(crate) fn trait_datum_query( marker: false, fundamental: false, }; - let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); + let where_clauses = convert_where_clauses(db, trait_.id.into(), &bound_vars); let associated_ty_ids = trait_ .items(db) .into_iter() @@ -643,7 +643,7 @@ fn impl_block_datum( } else { chalk_rust_ir::ImplType::External }; - let where_clauses = convert_where_clauses(db, impl_block.into(), &bound_vars); + let where_clauses = convert_where_clauses(db, impl_block.id.into(), &bound_vars); let negative = impl_block.is_negative(db); debug!( "impl {:?}: {}{} where {:?}", -- cgit v1.2.3