aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/infer/expr.rs21
-rw-r--r--crates/hir_ty/src/infer/pat.rs15
-rw-r--r--crates/hir_ty/src/lib.rs4
-rw-r--r--crates/hir_ty/src/lower.rs11
-rw-r--r--crates/hir_ty/src/method_resolution.rs21
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs14
6 files changed, 37 insertions, 49 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 77fb36332..796487d02 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -19,11 +19,11 @@ use crate::{
19 lower::lower_to_chalk_mutability, 19 lower::lower_to_chalk_mutability,
20 method_resolution, op, 20 method_resolution, op,
21 primitive::{self, UintTy}, 21 primitive::{self, UintTy},
22 to_chalk_trait_id, 22 static_lifetime, to_chalk_trait_id,
23 traits::{chalk::from_chalk, FnTrait}, 23 traits::{chalk::from_chalk, FnTrait},
24 utils::{generics, variant_data, Generics}, 24 utils::{generics, variant_data, Generics},
25 AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, 25 AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner,
26 LifetimeData, ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, 26 ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeWalk,
27}; 27};
28 28
29use super::{ 29use super::{
@@ -527,9 +527,7 @@ impl<'a> InferenceContext<'a> {
527 let inner_ty = self.infer_expr_inner(*expr, &expectation); 527 let inner_ty = self.infer_expr_inner(*expr, &expectation);
528 match rawness { 528 match rawness {
529 Rawness::RawPtr => TyKind::Raw(mutability, inner_ty), 529 Rawness::RawPtr => TyKind::Raw(mutability, inner_ty),
530 Rawness::Ref => { 530 Rawness::Ref => TyKind::Ref(mutability, static_lifetime(), inner_ty),
531 TyKind::Ref(mutability, LifetimeData::Static.intern(&Interner), inner_ty)
532 }
533 } 531 }
534 .intern(&Interner) 532 .intern(&Interner)
535 } 533 }
@@ -732,17 +730,14 @@ impl<'a> InferenceContext<'a> {
732 } 730 }
733 Expr::Literal(lit) => match lit { 731 Expr::Literal(lit) => match lit {
734 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), 732 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
735 Literal::String(..) => TyKind::Ref( 733 Literal::String(..) => {
736 Mutability::Not, 734 TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(&Interner))
737 LifetimeData::Static.intern(&Interner), 735 .intern(&Interner)
738 TyKind::Str.intern(&Interner), 736 }
739 )
740 .intern(&Interner),
741 Literal::ByteString(..) => { 737 Literal::ByteString(..) => {
742 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); 738 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
743 let array_type = TyKind::Array(byte_type).intern(&Interner); 739 let array_type = TyKind::Array(byte_type).intern(&Interner);
744 TyKind::Ref(Mutability::Not, LifetimeData::Static.intern(&Interner), array_type) 740 TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner)
745 .intern(&Interner)
746 } 741 }
747 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), 742 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
748 Literal::Int(_v, ty) => match ty { 743 Literal::Int(_v, ty) => match ty {
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index b5e97cc8c..2848a393c 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -13,7 +13,7 @@ use hir_expand::name::Name;
13 13
14use super::{BindingMode, Expectation, InferenceContext}; 14use super::{BindingMode, Expectation, InferenceContext};
15use crate::{ 15use crate::{
16 lower::lower_to_chalk_mutability, utils::variant_data, Interner, LifetimeData, Substitution, 16 lower::lower_to_chalk_mutability, static_lifetime, utils::variant_data, Interner, Substitution,
17 Ty, TyBuilder, TyKind, 17 Ty, TyBuilder, TyKind,
18}; 18};
19 19
@@ -171,8 +171,7 @@ impl<'a> InferenceContext<'a> {
171 _ => self.result.standard_types.unknown.clone(), 171 _ => self.result.standard_types.unknown.clone(),
172 }; 172 };
173 let subty = self.infer_pat(*pat, &expectation, default_bm); 173 let subty = self.infer_pat(*pat, &expectation, default_bm);
174 TyKind::Ref(mutability, LifetimeData::Static.intern(&Interner), subty) 174 TyKind::Ref(mutability, static_lifetime(), subty).intern(&Interner)
175 .intern(&Interner)
176 } 175 }
177 Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( 176 Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat(
178 p.as_ref(), 177 p.as_ref(),
@@ -204,12 +203,10 @@ impl<'a> InferenceContext<'a> {
204 let inner_ty = self.insert_type_vars_shallow(inner_ty); 203 let inner_ty = self.insert_type_vars_shallow(inner_ty);
205 204
206 let bound_ty = match mode { 205 let bound_ty = match mode {
207 BindingMode::Ref(mutability) => TyKind::Ref( 206 BindingMode::Ref(mutability) => {
208 mutability, 207 TyKind::Ref(mutability, static_lifetime(), inner_ty.clone())
209 LifetimeData::Static.intern(&Interner), 208 .intern(&Interner)
210 inner_ty.clone(), 209 }
211 )
212 .intern(&Interner),
213 BindingMode::Move => inner_ty.clone(), 210 BindingMode::Move => inner_ty.clone(),
214 }; 211 };
215 let bound_ty = self.resolve_ty_as_possible(bound_ty); 212 let bound_ty = self.resolve_ty_as_possible(bound_ty);
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 1dfe2075c..bccc73449 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -495,3 +495,7 @@ pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
495pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId { 495pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId {
496 salsa::InternKey::from_intern_id(id.0) 496 salsa::InternKey::from_intern_id(id.0)
497} 497}
498
499pub fn static_lifetime() -> Lifetime {
500 LifetimeData::Static.intern(&Interner)
501}
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index ff795377a..df6619af3 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -27,14 +27,14 @@ use stdx::impl_from;
27 27
28use crate::{ 28use crate::{
29 db::HirDatabase, 29 db::HirDatabase,
30 to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx, 30 static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
31 traits::chalk::{Interner, ToChalk}, 31 traits::chalk::{Interner, ToChalk},
32 utils::{ 32 utils::{
33 all_super_trait_refs, associated_type_by_name_including_super_traits, generics, 33 all_super_trait_refs, associated_type_by_name_including_super_traits, generics,
34 variant_data, Generics, 34 variant_data, Generics,
35 }, 35 },
36 AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig, 36 AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig,
37 FnSubst, ImplTraitId, LifetimeData, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause, 37 FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause,
38 QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, 38 QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution,
39 TraitEnvironment, TraitRef, Ty, TyBuilder, TyKind, TypeWalk, WhereClause, 39 TraitEnvironment, TraitRef, Ty, TyBuilder, TyKind, TypeWalk, WhereClause,
40}; 40};
@@ -174,7 +174,7 @@ impl<'a> TyLoweringContext<'a> {
174 } 174 }
175 TypeRef::Reference(inner, _, mutability) => { 175 TypeRef::Reference(inner, _, mutability) => {
176 let inner_ty = self.lower_ty(inner); 176 let inner_ty = self.lower_ty(inner);
177 let lifetime = LifetimeData::Static.intern(&Interner); 177 let lifetime = static_lifetime();
178 TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty) 178 TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty)
179 .intern(&Interner) 179 .intern(&Interner)
180 } 180 }
@@ -200,8 +200,7 @@ impl<'a> TyLoweringContext<'a> {
200 ) 200 )
201 }); 201 });
202 let bounds = crate::make_only_type_binders(1, bounds); 202 let bounds = crate::make_only_type_binders(1, bounds);
203 TyKind::Dyn(DynTy { bounds, lifetime: LifetimeData::Static.intern(&Interner) }) 203 TyKind::Dyn(DynTy { bounds, lifetime: static_lifetime() }).intern(&Interner)
204 .intern(&Interner)
205 } 204 }
206 TypeRef::ImplTrait(bounds) => { 205 TypeRef::ImplTrait(bounds) => {
207 match self.impl_trait_mode { 206 match self.impl_trait_mode {
@@ -393,7 +392,7 @@ impl<'a> TyLoweringContext<'a> {
393 ))), 392 ))),
394 ), 393 ),
395 ), 394 ),
396 lifetime: LifetimeData::Static.intern(&Interner), 395 lifetime: static_lifetime(),
397 }; 396 };
398 TyKind::Dyn(dyn_ty).intern(&Interner) 397 TyKind::Dyn(dyn_ty).intern(&Interner)
399 }; 398 };
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index 427844c12..436dea22b 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -19,10 +19,11 @@ use crate::{
19 db::HirDatabase, 19 db::HirDatabase,
20 from_foreign_def_id, 20 from_foreign_def_id,
21 primitive::{self, FloatTy, IntTy, UintTy}, 21 primitive::{self, FloatTy, IntTy, UintTy},
22 static_lifetime,
22 utils::all_super_traits, 23 utils::all_super_traits,
23 AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId, 24 AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId,
24 InEnvironment, Interner, LifetimeData, Scalar, Substitution, TraitEnvironment, Ty, TyBuilder, 25 InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, Ty, TyBuilder, TyKind,
25 TyKind, TypeWalk, 26 TypeWalk,
26}; 27};
27 28
28/// This is used as a key for indexing impls. 29/// This is used as a key for indexing impls.
@@ -453,12 +454,8 @@ fn iterate_method_candidates_with_autoref(
453 } 454 }
454 let refed = Canonical { 455 let refed = Canonical {
455 binders: deref_chain[0].binders.clone(), 456 binders: deref_chain[0].binders.clone(),
456 value: TyKind::Ref( 457 value: TyKind::Ref(Mutability::Not, static_lifetime(), deref_chain[0].value.clone())
457 Mutability::Not, 458 .intern(&Interner),
458 LifetimeData::Static.intern(&Interner),
459 deref_chain[0].value.clone(),
460 )
461 .intern(&Interner),
462 }; 459 };
463 if iterate_method_candidates_by_receiver( 460 if iterate_method_candidates_by_receiver(
464 &refed, 461 &refed,
@@ -475,12 +472,8 @@ fn iterate_method_candidates_with_autoref(
475 } 472 }
476 let ref_muted = Canonical { 473 let ref_muted = Canonical {
477 binders: deref_chain[0].binders.clone(), 474 binders: deref_chain[0].binders.clone(),
478 value: TyKind::Ref( 475 value: TyKind::Ref(Mutability::Mut, static_lifetime(), deref_chain[0].value.clone())
479 Mutability::Mut, 476 .intern(&Interner),
480 LifetimeData::Static.intern(&Interner),
481 deref_chain[0].value.clone(),
482 )
483 .intern(&Interner),
484 }; 477 };
485 if iterate_method_candidates_by_receiver( 478 if iterate_method_candidates_by_receiver(
486 &ref_muted, 479 &ref_muted,
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 128ec166a..9267e32b5 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -3,16 +3,16 @@
3//! Chalk (in both directions); plus some helper functions for more specialized 3//! Chalk (in both directions); plus some helper functions for more specialized
4//! conversions. 4//! conversions.
5 5
6use chalk_ir::{cast::Cast, interner::HasInterner, LifetimeData}; 6use chalk_ir::{cast::Cast, interner::HasInterner};
7use chalk_solve::rust_ir; 7use chalk_solve::rust_ir;
8 8
9use base_db::salsa::InternKey; 9use base_db::salsa::InternKey;
10use hir_def::{GenericDefId, TypeAliasId}; 10use hir_def::{GenericDefId, TypeAliasId};
11 11
12use crate::{ 12use crate::{
13 chalk_ext::ProjectionTyExt, db::HirDatabase, primitive::UintTy, AliasTy, CallableDefId, 13 chalk_ext::ProjectionTyExt, db::HirDatabase, primitive::UintTy, static_lifetime, AliasTy,
14 Canonical, DomainGoal, FnPointer, GenericArg, InEnvironment, Lifetime, OpaqueTy, ProjectionTy, 14 CallableDefId, Canonical, DomainGoal, FnPointer, GenericArg, InEnvironment, Lifetime, OpaqueTy,
15 QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause, 15 ProjectionTy, QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause,
16}; 16};
17 17
18use super::interner::*; 18use super::interner::*;
@@ -100,7 +100,7 @@ impl ToChalk for Ty {
100 ); 100 );
101 let bounded_ty = chalk_ir::DynTy { 101 let bounded_ty = chalk_ir::DynTy {
102 bounds: chalk_ir::Binders::new(binders, where_clauses), 102 bounds: chalk_ir::Binders::new(binders, where_clauses),
103 lifetime: LifetimeData::Static.intern(&Interner), 103 lifetime: static_lifetime(),
104 }; 104 };
105 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) 105 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
106 } 106 }
@@ -149,7 +149,7 @@ impl ToChalk for Ty {
149 where_clauses.bounds.binders.clone(), 149 where_clauses.bounds.binders.clone(),
150 crate::QuantifiedWhereClauses::from_iter(&Interner, bounds), 150 crate::QuantifiedWhereClauses::from_iter(&Interner, bounds),
151 ), 151 ),
152 lifetime: LifetimeData::Static.intern(&Interner), 152 lifetime: static_lifetime(),
153 }) 153 })
154 } 154 }
155 155
@@ -197,7 +197,7 @@ fn ref_to_chalk(
197 ty: Ty, 197 ty: Ty,
198) -> chalk_ir::Ty<Interner> { 198) -> chalk_ir::Ty<Interner> {
199 let arg = ty.to_chalk(db); 199 let arg = ty.to_chalk(db);
200 let lifetime = LifetimeData::Static.intern(&Interner); 200 let lifetime = static_lifetime();
201 chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) 201 chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner)
202} 202}
203 203