diff options
author | Lukas Wirth <[email protected]> | 2021-04-05 19:46:15 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-04-05 19:46:15 +0100 |
commit | d587ca2991406bd348768b2912c3cb66c869e7e8 (patch) | |
tree | 91f0421f3ca76f846548017d8a6c5a4b142b96bc /crates | |
parent | 87e56eb94ced9943977a38e7d4c6697587187ce6 (diff) |
Replace unused hir_ty::Lifetime with chalk equivalents
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/db.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 39 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 14 | ||||
-rw-r--r-- | crates/hir_ty/src/types.rs | 7 |
4 files changed, 50 insertions, 18 deletions
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index 4300680d9..07510ae02 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs | |||
@@ -5,7 +5,7 @@ use std::sync::Arc; | |||
5 | use base_db::{impl_intern_key, salsa, CrateId, Upcast}; | 5 | use base_db::{impl_intern_key, salsa, CrateId, Upcast}; |
6 | use hir_def::{ | 6 | use hir_def::{ |
7 | db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId, | 7 | db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId, |
8 | LocalFieldId, TypeParamId, VariantId, | 8 | LifetimeParamId, LocalFieldId, TypeParamId, VariantId, |
9 | }; | 9 | }; |
10 | use la_arena::ArenaMap; | 10 | use la_arena::ArenaMap; |
11 | 11 | ||
@@ -86,6 +86,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> { | |||
86 | #[salsa::interned] | 86 | #[salsa::interned] |
87 | fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId; | 87 | fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId; |
88 | #[salsa::interned] | 88 | #[salsa::interned] |
89 | fn intern_lifetime_param_id(&self, param_id: LifetimeParamId) -> InternedLifetimeParamId; | ||
90 | #[salsa::interned] | ||
89 | fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId; | 91 | fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId; |
90 | #[salsa::interned] | 92 | #[salsa::interned] |
91 | fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId; | 93 | fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId; |
@@ -156,6 +158,10 @@ pub struct InternedTypeParamId(salsa::InternId); | |||
156 | impl_intern_key!(InternedTypeParamId); | 158 | impl_intern_key!(InternedTypeParamId); |
157 | 159 | ||
158 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 160 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
161 | pub struct InternedLifetimeParamId(salsa::InternId); | ||
162 | impl_intern_key!(InternedLifetimeParamId); | ||
163 | |||
164 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
159 | pub struct InternedOpaqueTyId(salsa::InternId); | 165 | pub struct InternedOpaqueTyId(salsa::InternId); |
160 | impl_intern_key!(InternedOpaqueTyId); | 166 | impl_intern_key!(InternedOpaqueTyId); |
161 | 167 | ||
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index f31e6b108..01c7ef91f 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -1,8 +1,10 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::{array, fmt}; | 3 | use std::{ |
4 | array, | ||
5 | fmt::{self, Debug}, | ||
6 | }; | ||
4 | 7 | ||
5 | use chalk_ir::Mutability; | ||
6 | use hir_def::{ | 8 | use hir_def::{ |
7 | db::DefDatabase, | 9 | db::DefDatabase, |
8 | find_path, | 10 | find_path, |
@@ -16,9 +18,10 @@ use hir_def::{ | |||
16 | use hir_expand::name::Name; | 18 | use hir_expand::name::Name; |
17 | 19 | ||
18 | use crate::{ | 20 | use crate::{ |
19 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, | 21 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, |
20 | to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, | 22 | lt_from_placeholder_idx, primitive, to_assoc_type_id, traits::chalk::from_chalk, |
21 | CallableDefId, CallableSig, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, OpaqueTy, | 23 | utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, DomainGoal, GenericArg, |
24 | ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, | ||
22 | ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause, | 25 | ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause, |
23 | }; | 26 | }; |
24 | 27 | ||
@@ -827,15 +830,35 @@ impl HirDisplay for WhereClause { | |||
827 | } | 830 | } |
828 | } | 831 | } |
829 | 832 | ||
833 | impl HirDisplay for LifetimeOutlives { | ||
834 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
835 | self.a.hir_fmt(f)?; | ||
836 | write!(f, ": ")?; | ||
837 | self.b.hir_fmt(f) | ||
838 | } | ||
839 | } | ||
840 | |||
830 | impl HirDisplay for Lifetime { | 841 | impl HirDisplay for Lifetime { |
831 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 842 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
843 | self.interned().hir_fmt(f) | ||
844 | } | ||
845 | } | ||
846 | |||
847 | impl HirDisplay for LifetimeData { | ||
848 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
832 | match self { | 849 | match self { |
833 | Lifetime::Parameter(id) => { | 850 | LifetimeData::BoundVar(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index), |
851 | LifetimeData::InferenceVar(_) => write!(f, "_"), | ||
852 | LifetimeData::Placeholder(idx) => { | ||
853 | let id = lt_from_placeholder_idx(f.db, *idx); | ||
834 | let generics = generics(f.db.upcast(), id.parent); | 854 | let generics = generics(f.db.upcast(), id.parent); |
835 | let param_data = &generics.params.lifetimes[id.local_id]; | 855 | let param_data = &generics.params.lifetimes[id.local_id]; |
836 | write!(f, "{}", ¶m_data.name) | 856 | write!(f, "{}", param_data.name) |
837 | } | 857 | } |
838 | Lifetime::Static => write!(f, "'static"), | 858 | LifetimeData::Static => write!(f, "'static"), |
859 | LifetimeData::Empty(_) => Ok(()), | ||
860 | LifetimeData::Erased => Ok(()), | ||
861 | LifetimeData::Phantom(_, _) => Ok(()), | ||
839 | } | 862 | } |
840 | } | 863 | } |
841 | } | 864 | } |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index daf379ef8..a3addc8e9 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -35,8 +35,8 @@ use smallvec::SmallVec; | |||
35 | 35 | ||
36 | use base_db::salsa; | 36 | use base_db::salsa; |
37 | use hir_def::{ | 37 | use hir_def::{ |
38 | expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, GenericDefId, HasModule, Lookup, | 38 | expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, GenericDefId, HasModule, |
39 | TraitId, TypeAliasId, TypeParamId, | 39 | LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId, |
40 | }; | 40 | }; |
41 | 41 | ||
42 | use crate::{db::HirDatabase, display::HirDisplay, utils::generics}; | 42 | use crate::{db::HirDatabase, display::HirDisplay, utils::generics}; |
@@ -70,6 +70,10 @@ pub type VariableKind = chalk_ir::VariableKind<Interner>; | |||
70 | pub type VariableKinds = chalk_ir::VariableKinds<Interner>; | 70 | pub type VariableKinds = chalk_ir::VariableKinds<Interner>; |
71 | pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>; | 71 | pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>; |
72 | 72 | ||
73 | pub type Lifetime = chalk_ir::Lifetime<Interner>; | ||
74 | pub type LifetimeData = chalk_ir::LifetimeData<Interner>; | ||
75 | pub type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>; | ||
76 | |||
73 | pub type ChalkTraitId = chalk_ir::TraitId<Interner>; | 77 | pub type ChalkTraitId = chalk_ir::TraitId<Interner>; |
74 | 78 | ||
75 | impl ProjectionTy { | 79 | impl ProjectionTy { |
@@ -546,6 +550,12 @@ pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderI | |||
546 | } | 550 | } |
547 | } | 551 | } |
548 | 552 | ||
553 | pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId { | ||
554 | assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT); | ||
555 | let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx)); | ||
556 | db.lookup_intern_lifetime_param_id(interned_id) | ||
557 | } | ||
558 | |||
549 | pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId { | 559 | pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId { |
550 | chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id)) | 560 | chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id)) |
551 | } | 561 | } |
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index 46c705a76..dc64e6e2b 100644 --- a/crates/hir_ty/src/types.rs +++ b/crates/hir_ty/src/types.rs | |||
@@ -7,7 +7,6 @@ use chalk_ir::{ | |||
7 | cast::{CastTo, Caster}, | 7 | cast::{CastTo, Caster}, |
8 | BoundVar, Mutability, Scalar, TyVariableKind, | 8 | BoundVar, Mutability, Scalar, TyVariableKind, |
9 | }; | 9 | }; |
10 | use hir_def::LifetimeParamId; | ||
11 | use smallvec::SmallVec; | 10 | use smallvec::SmallVec; |
12 | 11 | ||
13 | use crate::{ | 12 | use crate::{ |
@@ -16,12 +15,6 @@ use crate::{ | |||
16 | }; | 15 | }; |
17 | 16 | ||
18 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 17 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
19 | pub enum Lifetime { | ||
20 | Parameter(LifetimeParamId), | ||
21 | Static, | ||
22 | } | ||
23 | |||
24 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||
25 | pub struct OpaqueTy { | 18 | pub struct OpaqueTy { |
26 | pub opaque_ty_id: OpaqueTyId, | 19 | pub opaque_ty_id: OpaqueTyId, |
27 | pub substitution: Substitution, | 20 | pub substitution: Substitution, |