diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-25 12:39:45 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-25 12:39:45 +0000 |
commit | c46cea2ad8239315d51952bfb1dad65c200dae7c (patch) | |
tree | 5cb05c66e7d6bfc51f206f27f561f3b54971c7b4 /crates/ra_hir/src | |
parent | 9f7fcc6ecd5334c5e3caa365c4a6d7bf3f37b649 (diff) | |
parent | c2a16632d0773dec707acb215297ef55b5c880fe (diff) |
Merge #2399
2399: Use GenericDefId more r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/from_id.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 16 | ||||
-rw-r--r-- | 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::{ | |||
24 | RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery, | 24 | RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery, |
25 | TypeAliasDataQuery, | 25 | TypeAliasDataQuery, |
26 | }, | 26 | }, |
27 | LocalStructFieldId, VariantId, | 27 | GenericDefId, LocalStructFieldId, VariantId, |
28 | }; | 28 | }; |
29 | pub use hir_expand::db::{ | 29 | pub use hir_expand::db::{ |
30 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, | 30 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, |
@@ -54,7 +54,7 @@ pub trait HirDatabase: DefDatabase { | |||
54 | ) -> Arc<[GenericPredicate]>; | 54 | ) -> Arc<[GenericPredicate]>; |
55 | 55 | ||
56 | #[salsa::invoke(crate::ty::generic_predicates_query)] | 56 | #[salsa::invoke(crate::ty::generic_predicates_query)] |
57 | fn generic_predicates(&self, def: GenericDef) -> Arc<[GenericPredicate]>; | 57 | fn generic_predicates(&self, def: GenericDefId) -> Arc<[GenericPredicate]>; |
58 | 58 | ||
59 | #[salsa::invoke(crate::ty::generic_defaults_query)] | 59 | #[salsa::invoke(crate::ty::generic_defaults_query)] |
60 | fn generic_defaults(&self, def: GenericDef) -> Substs; | 60 | 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::{ | |||
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | ty::{CallableDef, TypableDef}, | 12 | ty::TypableDef, Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, |
13 | Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, | 13 | GenericDef, ModuleDef, Static, StructField, TypeAlias, VariantDef, |
14 | ModuleDef, Static, StructField, TypeAlias, VariantDef, | ||
15 | }; | 14 | }; |
16 | 15 | ||
17 | impl From<ra_db::CrateId> for Crate { | 16 | impl From<ra_db::CrateId> for Crate { |
@@ -214,18 +213,6 @@ impl From<Adt> for GenericDefId { | |||
214 | } | 213 | } |
215 | } | 214 | } |
216 | 215 | ||
217 | impl From<CallableDef> for GenericDefId { | ||
218 | fn from(def: CallableDef) -> Self { | ||
219 | match def { | ||
220 | CallableDef::Function(it) => it.id.into(), | ||
221 | CallableDef::Struct(it) => it.id.into(), | ||
222 | CallableDef::EnumVariant(it) => { | ||
223 | EnumVariantId { parent: it.parent.id, local_id: it.id }.into() | ||
224 | } | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | |||
229 | impl From<VariantDef> for VariantId { | 216 | impl From<VariantDef> for VariantId { |
230 | fn from(def: VariantDef) -> Self { | 217 | fn from(def: VariantDef) -> Self { |
231 | match def { | 218 | 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; | |||
17 | use std::sync::Arc; | 17 | use std::sync::Arc; |
18 | use std::{fmt, iter, mem}; | 18 | use std::{fmt, iter, mem}; |
19 | 19 | ||
20 | use hir_def::{generics::GenericParams, AdtId}; | 20 | use hir_def::{generics::GenericParams, AdtId, GenericDefId}; |
21 | use ra_db::{impl_intern_key, salsa}; | 21 | use ra_db::{impl_intern_key, salsa}; |
22 | 22 | ||
23 | use crate::{ | 23 | use crate::{ |
@@ -176,7 +176,7 @@ impl TypeCtor { | |||
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | pub fn as_generic_def(self) -> Option<crate::GenericDef> { | 179 | pub fn as_generic_def(self) -> Option<GenericDefId> { |
180 | match self { | 180 | match self { |
181 | TypeCtor::Bool | 181 | TypeCtor::Bool |
182 | | TypeCtor::Char | 182 | | TypeCtor::Char |
@@ -193,7 +193,7 @@ impl TypeCtor { | |||
193 | | TypeCtor::Closure { .. } => None, | 193 | | TypeCtor::Closure { .. } => None, |
194 | TypeCtor::Adt(adt) => Some(adt.into()), | 194 | TypeCtor::Adt(adt) => Some(adt.into()), |
195 | TypeCtor::FnDef(callable) => Some(callable.into()), | 195 | TypeCtor::FnDef(callable) => Some(callable.into()), |
196 | TypeCtor::AssociatedType(type_alias) => Some(type_alias.into()), | 196 | TypeCtor::AssociatedType(type_alias) => Some(type_alias.id.into()), |
197 | } | 197 | } |
198 | } | 198 | } |
199 | } | 199 | } |
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::{ | |||
14 | path::{GenericArg, PathSegment}, | 14 | path::{GenericArg, PathSegment}, |
15 | resolver::{HasResolver, Resolver, TypeNs}, | 15 | resolver::{HasResolver, Resolver, TypeNs}, |
16 | type_ref::{TypeBound, TypeRef}, | 16 | type_ref::{TypeBound, TypeRef}, |
17 | AdtId, GenericDefId, LocalStructFieldId, VariantId, | 17 | AdtId, EnumVariantId, GenericDefId, LocalStructFieldId, VariantId, |
18 | }; | 18 | }; |
19 | use ra_arena::map::ArenaMap; | 19 | use ra_arena::map::ArenaMap; |
20 | 20 | ||
@@ -605,9 +605,9 @@ impl TraitEnvironment { | |||
605 | /// Resolve the where clause(s) of an item with generics. | 605 | /// Resolve the where clause(s) of an item with generics. |
606 | pub(crate) fn generic_predicates_query( | 606 | pub(crate) fn generic_predicates_query( |
607 | db: &impl HirDatabase, | 607 | db: &impl HirDatabase, |
608 | def: GenericDef, | 608 | def: GenericDefId, |
609 | ) -> Arc<[GenericPredicate]> { | 609 | ) -> Arc<[GenericPredicate]> { |
610 | let resolver = GenericDefId::from(def).resolver(db); | 610 | let resolver = def.resolver(db); |
611 | resolver | 611 | resolver |
612 | .where_predicates_in_scope() | 612 | .where_predicates_in_scope() |
613 | .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred)) | 613 | .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred)) |
@@ -819,12 +819,12 @@ impl CallableDef { | |||
819 | } | 819 | } |
820 | } | 820 | } |
821 | 821 | ||
822 | impl From<CallableDef> for GenericDef { | 822 | impl From<CallableDef> for GenericDefId { |
823 | fn from(def: CallableDef) -> GenericDef { | 823 | fn from(def: CallableDef) -> GenericDefId { |
824 | match def { | 824 | match def { |
825 | CallableDef::Function(f) => f.into(), | 825 | CallableDef::Function(f) => f.id.into(), |
826 | CallableDef::Struct(s) => s.into(), | 826 | CallableDef::Struct(s) => s.id.into(), |
827 | CallableDef::EnumVariant(e) => e.into(), | 827 | CallableDef::EnumVariant(e) => EnumVariantId::from(e).into(), |
828 | } | 828 | } |
829 | } | 829 | } |
830 | } | 830 | } |
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::{ | |||
9 | }; | 9 | }; |
10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; | 10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; |
11 | 11 | ||
12 | use hir_def::lang_item::LangItemTarget; | 12 | use hir_def::{lang_item::LangItemTarget, GenericDefId}; |
13 | use hir_expand::name; | 13 | use hir_expand::name; |
14 | 14 | ||
15 | use ra_db::salsa::{InternId, InternKey}; | 15 | use ra_db::salsa::{InternId, InternKey}; |
@@ -19,7 +19,7 @@ use crate::{ | |||
19 | db::HirDatabase, | 19 | db::HirDatabase, |
20 | ty::display::HirDisplay, | 20 | ty::display::HirDisplay, |
21 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, | 21 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, |
22 | Crate, GenericDef, ImplBlock, Trait, TypeAlias, | 22 | Crate, ImplBlock, Trait, TypeAlias, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | /// This represents a trait whose name we could not resolve. | 25 | /// This represents a trait whose name we could not resolve. |
@@ -402,7 +402,7 @@ fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> { | |||
402 | 402 | ||
403 | fn convert_where_clauses( | 403 | fn convert_where_clauses( |
404 | db: &impl HirDatabase, | 404 | db: &impl HirDatabase, |
405 | def: GenericDef, | 405 | def: GenericDefId, |
406 | substs: &Substs, | 406 | substs: &Substs, |
407 | ) -> Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>> { | 407 | ) -> Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>> { |
408 | let generic_predicates = db.generic_predicates(def); | 408 | let generic_predicates = db.generic_predicates(def); |
@@ -561,7 +561,7 @@ pub(crate) fn trait_datum_query( | |||
561 | marker: false, | 561 | marker: false, |
562 | fundamental: false, | 562 | fundamental: false, |
563 | }; | 563 | }; |
564 | let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); | 564 | let where_clauses = convert_where_clauses(db, trait_.id.into(), &bound_vars); |
565 | let associated_ty_ids = trait_ | 565 | let associated_ty_ids = trait_ |
566 | .items(db) | 566 | .items(db) |
567 | .into_iter() | 567 | .into_iter() |
@@ -643,7 +643,7 @@ fn impl_block_datum( | |||
643 | } else { | 643 | } else { |
644 | chalk_rust_ir::ImplType::External | 644 | chalk_rust_ir::ImplType::External |
645 | }; | 645 | }; |
646 | let where_clauses = convert_where_clauses(db, impl_block.into(), &bound_vars); | 646 | let where_clauses = convert_where_clauses(db, impl_block.id.into(), &bound_vars); |
647 | let negative = impl_block.is_negative(db); | 647 | let negative = impl_block.is_negative(db); |
648 | debug!( | 648 | debug!( |
649 | "impl {:?}: {}{} where {:?}", | 649 | "impl {:?}: {}{} where {:?}", |