diff options
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/diagnostics/expr.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 13 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 13 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 9 | ||||
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 7 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 20 | ||||
-rw-r--r-- | crates/hir_ty/src/types.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/walk.rs | 4 |
12 files changed, 58 insertions, 38 deletions
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index db278d0db..d7bf9fdf7 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs | |||
@@ -315,7 +315,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
315 | if pat_ty == match_expr_ty | 315 | if pat_ty == match_expr_ty |
316 | || match_expr_ty | 316 | || match_expr_ty |
317 | .as_reference() | 317 | .as_reference() |
318 | .map(|(match_expr_ty, _)| match_expr_ty == pat_ty) | 318 | .map(|(match_expr_ty, ..)| match_expr_ty == pat_ty) |
319 | .unwrap_or(false) | 319 | .unwrap_or(false) |
320 | { | 320 | { |
321 | // If we had a NotUsefulMatchArm diagnostic, we could | 321 | // If we had a NotUsefulMatchArm diagnostic, we could |
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 4ef8024d0..22416c0cf 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -314,7 +314,7 @@ impl HirDisplay for Ty { | |||
314 | t.hir_fmt(f)?; | 314 | t.hir_fmt(f)?; |
315 | write!(f, "; _]")?; | 315 | write!(f, "; _]")?; |
316 | } | 316 | } |
317 | TyKind::Raw(m, t) | TyKind::Ref(m, t) => { | 317 | TyKind::Raw(m, t) | TyKind::Ref(m, _, t) => { |
318 | let ty_display = | 318 | let ty_display = |
319 | t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); | 319 | t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); |
320 | 320 | ||
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 32c273afc..d6c48870a 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -81,7 +81,7 @@ impl<'a> InferenceContext<'a> { | |||
81 | // `&T` -> `*const T` | 81 | // `&T` -> `*const T` |
82 | // `&mut T` -> `*mut T`/`*const T` | 82 | // `&mut T` -> `*mut T`/`*const T` |
83 | (TyKind::Ref(.., substs), &TyKind::Raw(m2 @ Mutability::Not, ..)) | 83 | (TyKind::Ref(.., substs), &TyKind::Raw(m2 @ Mutability::Not, ..)) |
84 | | (TyKind::Ref(Mutability::Mut, substs), &TyKind::Raw(m2, ..)) => { | 84 | | (TyKind::Ref(Mutability::Mut, _, substs), &TyKind::Raw(m2, ..)) => { |
85 | from_ty = TyKind::Raw(m2, substs.clone()).intern(&Interner); | 85 | from_ty = TyKind::Raw(m2, substs.clone()).intern(&Interner); |
86 | } | 86 | } |
87 | 87 | ||
@@ -111,7 +111,9 @@ impl<'a> InferenceContext<'a> { | |||
111 | // Auto Deref if cannot coerce | 111 | // Auto Deref if cannot coerce |
112 | match (from_ty.kind(&Interner), to_ty.kind(&Interner)) { | 112 | match (from_ty.kind(&Interner), to_ty.kind(&Interner)) { |
113 | // FIXME: DerefMut | 113 | // FIXME: DerefMut |
114 | (TyKind::Ref(_, st1), TyKind::Ref(_, st2)) => self.unify_autoderef_behind_ref(st1, st2), | 114 | (TyKind::Ref(.., st1), TyKind::Ref(.., st2)) => { |
115 | self.unify_autoderef_behind_ref(st1, st2) | ||
116 | } | ||
115 | 117 | ||
116 | // Otherwise, normal unify | 118 | // Otherwise, normal unify |
117 | _ => self.unify(&from_ty, to_ty), | 119 | _ => self.unify(&from_ty, to_ty), |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index ff564106b..796487d02 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -19,7 +19,7 @@ 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, |
@@ -527,7 +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 => TyKind::Ref(mutability, inner_ty), | 530 | Rawness::Ref => TyKind::Ref(mutability, static_lifetime(), inner_ty), |
531 | } | 531 | } |
532 | .intern(&Interner) | 532 | .intern(&Interner) |
533 | } | 533 | } |
@@ -731,12 +731,13 @@ impl<'a> InferenceContext<'a> { | |||
731 | Expr::Literal(lit) => match lit { | 731 | Expr::Literal(lit) => match lit { |
732 | Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), | 732 | Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), |
733 | Literal::String(..) => { | 733 | Literal::String(..) => { |
734 | TyKind::Ref(Mutability::Not, TyKind::Str.intern(&Interner)).intern(&Interner) | 734 | TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(&Interner)) |
735 | .intern(&Interner) | ||
735 | } | 736 | } |
736 | Literal::ByteString(..) => { | 737 | Literal::ByteString(..) => { |
737 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); | 738 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); |
738 | let array_type = TyKind::Array(byte_type).intern(&Interner); | 739 | let array_type = TyKind::Array(byte_type).intern(&Interner); |
739 | TyKind::Ref(Mutability::Not, array_type).intern(&Interner) | 740 | TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner) |
740 | } | 741 | } |
741 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), | 742 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), |
742 | Literal::Int(_v, ty) => match ty { | 743 | Literal::Int(_v, ty) => match ty { |
@@ -872,7 +873,9 @@ impl<'a> InferenceContext<'a> { | |||
872 | // Apply autoref so the below unification works correctly | 873 | // Apply autoref so the below unification works correctly |
873 | // FIXME: return correct autorefs from lookup_method | 874 | // FIXME: return correct autorefs from lookup_method |
874 | let actual_receiver_ty = match expected_receiver_ty.as_reference() { | 875 | let actual_receiver_ty = match expected_receiver_ty.as_reference() { |
875 | Some((_, mutability)) => TyKind::Ref(mutability, derefed_receiver_ty).intern(&Interner), | 876 | Some((_, lifetime, mutability)) => { |
877 | TyKind::Ref(mutability, lifetime, derefed_receiver_ty).intern(&Interner) | ||
878 | } | ||
876 | _ => derefed_receiver_ty, | 879 | _ => derefed_receiver_ty, |
877 | }; | 880 | }; |
878 | self.unify(&expected_receiver_ty, &actual_receiver_ty); | 881 | self.unify(&expected_receiver_ty, &actual_receiver_ty); |
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 252ae914a..2848a393c 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -13,8 +13,8 @@ use hir_expand::name::Name; | |||
13 | 13 | ||
14 | use super::{BindingMode, Expectation, InferenceContext}; | 14 | use super::{BindingMode, Expectation, InferenceContext}; |
15 | use crate::{ | 15 | use crate::{ |
16 | lower::lower_to_chalk_mutability, utils::variant_data, Interner, Substitution, Ty, TyBuilder, | 16 | lower::lower_to_chalk_mutability, static_lifetime, utils::variant_data, Interner, Substitution, |
17 | TyKind, | 17 | Ty, TyBuilder, TyKind, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | impl<'a> InferenceContext<'a> { | 20 | impl<'a> InferenceContext<'a> { |
@@ -104,7 +104,7 @@ impl<'a> InferenceContext<'a> { | |||
104 | let body = Arc::clone(&self.body); // avoid borrow checker problem | 104 | let body = Arc::clone(&self.body); // avoid borrow checker problem |
105 | 105 | ||
106 | if is_non_ref_pat(&body, pat) { | 106 | if is_non_ref_pat(&body, pat) { |
107 | while let Some((inner, mutability)) = expected.as_reference() { | 107 | while let Some((inner, _lifetime, mutability)) = expected.as_reference() { |
108 | expected = inner; | 108 | expected = inner; |
109 | default_bm = match default_bm { | 109 | default_bm = match default_bm { |
110 | BindingMode::Move => BindingMode::Ref(mutability), | 110 | BindingMode::Move => BindingMode::Ref(mutability), |
@@ -162,7 +162,7 @@ impl<'a> InferenceContext<'a> { | |||
162 | Pat::Ref { pat, mutability } => { | 162 | Pat::Ref { pat, mutability } => { |
163 | let mutability = lower_to_chalk_mutability(*mutability); | 163 | let mutability = lower_to_chalk_mutability(*mutability); |
164 | let expectation = match expected.as_reference() { | 164 | let expectation = match expected.as_reference() { |
165 | Some((inner_ty, exp_mut)) => { | 165 | Some((inner_ty, _lifetime, exp_mut)) => { |
166 | if mutability != exp_mut { | 166 | if mutability != exp_mut { |
167 | // FIXME: emit type error? | 167 | // FIXME: emit type error? |
168 | } | 168 | } |
@@ -171,7 +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, subty).intern(&Interner) | 174 | TyKind::Ref(mutability, static_lifetime(), subty).intern(&Interner) |
175 | } | 175 | } |
176 | 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( |
177 | p.as_ref(), | 177 | p.as_ref(), |
@@ -204,7 +204,8 @@ impl<'a> InferenceContext<'a> { | |||
204 | 204 | ||
205 | let bound_ty = match mode { | 205 | let bound_ty = match mode { |
206 | BindingMode::Ref(mutability) => { | 206 | BindingMode::Ref(mutability) => { |
207 | TyKind::Ref(mutability, inner_ty.clone()).intern(&Interner) | 207 | TyKind::Ref(mutability, static_lifetime(), inner_ty.clone()) |
208 | .intern(&Interner) | ||
208 | } | 209 | } |
209 | BindingMode::Move => inner_ty.clone(), | 210 | BindingMode::Move => inner_ty.clone(), |
210 | }; | 211 | }; |
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 2f9523325..c7878ebfd 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs | |||
@@ -317,7 +317,7 @@ impl InferenceTable { | |||
317 | | (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) => { | 317 | | (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) => { |
318 | self.unify_substs(substs1, substs2, depth + 1) | 318 | self.unify_substs(substs1, substs2, depth + 1) |
319 | } | 319 | } |
320 | (TyKind::Ref(_, ty1), TyKind::Ref(_, ty2)) | 320 | (TyKind::Ref(_, _, ty1), TyKind::Ref(_, _, ty2)) |
321 | | (TyKind::Raw(_, ty1), TyKind::Raw(_, ty2)) | 321 | | (TyKind::Raw(_, ty1), TyKind::Raw(_, ty2)) |
322 | | (TyKind::Array(ty1), TyKind::Array(ty2)) | 322 | | (TyKind::Array(ty1), TyKind::Array(ty2)) |
323 | | (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1), | 323 | | (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1), |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index c3ec12352..bccc73449 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -165,16 +165,16 @@ impl CallableSig { | |||
165 | } | 165 | } |
166 | 166 | ||
167 | impl Ty { | 167 | impl Ty { |
168 | pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { | 168 | pub fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)> { |
169 | match self.kind(&Interner) { | 169 | match self.kind(&Interner) { |
170 | TyKind::Ref(mutability, ty) => Some((ty, *mutability)), | 170 | TyKind::Ref(mutability, lifetime, ty) => Some((ty, *lifetime, *mutability)), |
171 | _ => None, | 171 | _ => None, |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | pub fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)> { | 175 | pub fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)> { |
176 | match self.kind(&Interner) { | 176 | match self.kind(&Interner) { |
177 | TyKind::Ref(mutability, ty) => Some((ty, Rawness::Ref, *mutability)), | 177 | TyKind::Ref(mutability, _, ty) => Some((ty, Rawness::Ref, *mutability)), |
178 | TyKind::Raw(mutability, ty) => Some((ty, Rawness::RawPtr, *mutability)), | 178 | TyKind::Raw(mutability, ty) => Some((ty, Rawness::RawPtr, *mutability)), |
179 | _ => None, | 179 | _ => None, |
180 | } | 180 | } |
@@ -183,7 +183,7 @@ impl Ty { | |||
183 | pub fn strip_references(&self) -> &Ty { | 183 | pub fn strip_references(&self) -> &Ty { |
184 | let mut t: &Ty = self; | 184 | let mut t: &Ty = self; |
185 | 185 | ||
186 | while let TyKind::Ref(_mutability, ty) = t.kind(&Interner) { | 186 | while let TyKind::Ref(_mutability, _lifetime, ty) = t.kind(&Interner) { |
187 | t = ty; | 187 | t = ty; |
188 | } | 188 | } |
189 | 189 | ||
@@ -495,3 +495,7 @@ pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId { | |||
495 | pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId { | 495 | pub 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 | |||
499 | pub 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 3cbb6ad54..df6619af3 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -27,7 +27,7 @@ use stdx::impl_from; | |||
27 | 27 | ||
28 | use crate::{ | 28 | use 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, |
@@ -174,7 +174,9 @@ 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 | TyKind::Ref(lower_to_chalk_mutability(*mutability), inner_ty).intern(&Interner) | 177 | let lifetime = static_lifetime(); |
178 | TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty) | ||
179 | .intern(&Interner) | ||
178 | } | 180 | } |
179 | TypeRef::Placeholder => TyKind::Error.intern(&Interner), | 181 | TypeRef::Placeholder => TyKind::Error.intern(&Interner), |
180 | TypeRef::Fn(params, is_varargs) => { | 182 | TypeRef::Fn(params, is_varargs) => { |
@@ -198,7 +200,7 @@ impl<'a> TyLoweringContext<'a> { | |||
198 | ) | 200 | ) |
199 | }); | 201 | }); |
200 | let bounds = crate::make_only_type_binders(1, bounds); | 202 | let bounds = crate::make_only_type_binders(1, bounds); |
201 | TyKind::Dyn(DynTy { bounds }).intern(&Interner) | 203 | TyKind::Dyn(DynTy { bounds, lifetime: static_lifetime() }).intern(&Interner) |
202 | } | 204 | } |
203 | TypeRef::ImplTrait(bounds) => { | 205 | TypeRef::ImplTrait(bounds) => { |
204 | match self.impl_trait_mode { | 206 | match self.impl_trait_mode { |
@@ -390,6 +392,7 @@ impl<'a> TyLoweringContext<'a> { | |||
390 | ))), | 392 | ))), |
391 | ), | 393 | ), |
392 | ), | 394 | ), |
395 | lifetime: static_lifetime(), | ||
393 | }; | 396 | }; |
394 | TyKind::Dyn(dyn_ty).intern(&Interner) | 397 | TyKind::Dyn(dyn_ty).intern(&Interner) |
395 | }; | 398 | }; |
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 6d65d3eb9..436dea22b 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -19,6 +19,7 @@ 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, Scalar, Substitution, TraitEnvironment, Ty, TyBuilder, TyKind, | 25 | InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, Ty, TyBuilder, TyKind, |
@@ -453,7 +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(Mutability::Not, deref_chain[0].value.clone()).intern(&Interner), | 457 | value: TyKind::Ref(Mutability::Not, static_lifetime(), deref_chain[0].value.clone()) |
458 | .intern(&Interner), | ||
457 | }; | 459 | }; |
458 | if iterate_method_candidates_by_receiver( | 460 | if iterate_method_candidates_by_receiver( |
459 | &refed, | 461 | &refed, |
@@ -470,7 +472,8 @@ fn iterate_method_candidates_with_autoref( | |||
470 | } | 472 | } |
471 | let ref_muted = Canonical { | 473 | let ref_muted = Canonical { |
472 | binders: deref_chain[0].binders.clone(), | 474 | binders: deref_chain[0].binders.clone(), |
473 | value: TyKind::Ref(Mutability::Mut, deref_chain[0].value.clone()).intern(&Interner), | 475 | value: TyKind::Ref(Mutability::Mut, static_lifetime(), deref_chain[0].value.clone()) |
476 | .intern(&Interner), | ||
474 | }; | 477 | }; |
475 | if iterate_method_candidates_by_receiver( | 478 | if iterate_method_candidates_by_receiver( |
476 | &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 3047fbacb..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 | ||
6 | use chalk_ir::{cast::Cast, interner::HasInterner, LifetimeData}; | 6 | use chalk_ir::{cast::Cast, interner::HasInterner}; |
7 | use chalk_solve::rust_ir; | 7 | use chalk_solve::rust_ir; |
8 | 8 | ||
9 | use base_db::salsa::InternKey; | 9 | use base_db::salsa::InternKey; |
10 | use hir_def::{GenericDefId, TypeAliasId}; | 10 | use hir_def::{GenericDefId, TypeAliasId}; |
11 | 11 | ||
12 | use crate::{ | 12 | use 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, 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 | ||
18 | use super::interner::*; | 18 | use super::interner::*; |
@@ -22,7 +22,7 @@ impl ToChalk for Ty { | |||
22 | type Chalk = chalk_ir::Ty<Interner>; | 22 | type Chalk = chalk_ir::Ty<Interner>; |
23 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { | 23 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { |
24 | match self.into_inner() { | 24 | match self.into_inner() { |
25 | TyKind::Ref(m, ty) => ref_to_chalk(db, m, ty), | 25 | TyKind::Ref(m, lt, ty) => ref_to_chalk(db, m, lt, ty), |
26 | TyKind::Array(ty) => array_to_chalk(db, ty), | 26 | TyKind::Array(ty) => array_to_chalk(db, ty), |
27 | TyKind::Function(FnPointer { sig, substitution: substs, .. }) => { | 27 | TyKind::Function(FnPointer { sig, substitution: substs, .. }) => { |
28 | let substitution = chalk_ir::FnSubst(substs.0.to_chalk(db)); | 28 | let substitution = chalk_ir::FnSubst(substs.0.to_chalk(db)); |
@@ -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,6 +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: static_lifetime(), | ||
152 | }) | 153 | }) |
153 | } | 154 | } |
154 | 155 | ||
@@ -167,8 +168,8 @@ impl ToChalk for Ty { | |||
167 | } | 168 | } |
168 | chalk_ir::TyKind::Raw(mutability, ty) => TyKind::Raw(mutability, from_chalk(db, ty)), | 169 | chalk_ir::TyKind::Raw(mutability, ty) => TyKind::Raw(mutability, from_chalk(db, ty)), |
169 | chalk_ir::TyKind::Slice(ty) => TyKind::Slice(from_chalk(db, ty)), | 170 | chalk_ir::TyKind::Slice(ty) => TyKind::Slice(from_chalk(db, ty)), |
170 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { | 171 | chalk_ir::TyKind::Ref(mutability, lifetime, ty) => { |
171 | TyKind::Ref(mutability, from_chalk(db, ty)) | 172 | TyKind::Ref(mutability, lifetime, from_chalk(db, ty)) |
172 | } | 173 | } |
173 | chalk_ir::TyKind::Str => TyKind::Str, | 174 | chalk_ir::TyKind::Str => TyKind::Str, |
174 | chalk_ir::TyKind::Never => TyKind::Never, | 175 | chalk_ir::TyKind::Never => TyKind::Never, |
@@ -192,10 +193,11 @@ impl ToChalk for Ty { | |||
192 | fn ref_to_chalk( | 193 | fn ref_to_chalk( |
193 | db: &dyn HirDatabase, | 194 | db: &dyn HirDatabase, |
194 | mutability: chalk_ir::Mutability, | 195 | mutability: chalk_ir::Mutability, |
196 | _lifetime: Lifetime, | ||
195 | ty: Ty, | 197 | ty: Ty, |
196 | ) -> chalk_ir::Ty<Interner> { | 198 | ) -> chalk_ir::Ty<Interner> { |
197 | let arg = ty.to_chalk(db); | 199 | let arg = ty.to_chalk(db); |
198 | let lifetime = LifetimeData::Static.intern(&Interner); | 200 | let lifetime = static_lifetime(); |
199 | chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) | 201 | chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) |
200 | } | 202 | } |
201 | 203 | ||
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index d4e07a6b8..844e57896 100644 --- a/crates/hir_ty/src/types.rs +++ b/crates/hir_ty/src/types.rs | |||
@@ -11,7 +11,8 @@ use smallvec::SmallVec; | |||
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId, | 13 | AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId, |
14 | InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKind, VariableKinds, | 14 | InferenceVar, Interner, Lifetime, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKind, |
15 | VariableKinds, | ||
15 | }; | 16 | }; |
16 | 17 | ||
17 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 18 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
@@ -39,6 +40,7 @@ impl ProjectionTy { | |||
39 | pub struct DynTy { | 40 | pub struct DynTy { |
40 | /// The unknown self type. | 41 | /// The unknown self type. |
41 | pub bounds: Binders<QuantifiedWhereClauses>, | 42 | pub bounds: Binders<QuantifiedWhereClauses>, |
43 | pub lifetime: Lifetime, | ||
42 | } | 44 | } |
43 | 45 | ||
44 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 46 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
@@ -122,7 +124,7 @@ pub enum TyKind { | |||
122 | 124 | ||
123 | /// A reference; a pointer with an associated lifetime. Written as | 125 | /// A reference; a pointer with an associated lifetime. Written as |
124 | /// `&'a mut T` or `&'a T`. | 126 | /// `&'a mut T` or `&'a T`. |
125 | Ref(Mutability, Ty), | 127 | Ref(Mutability, Lifetime, Ty), |
126 | 128 | ||
127 | /// This represents a placeholder for an opaque type in situations where we | 129 | /// This represents a placeholder for an opaque type in situations where we |
128 | /// don't know the hidden type (i.e. currently almost always). This is | 130 | /// don't know the hidden type (i.e. currently almost always). This is |
diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs index e1e77ba37..4cc4e24fd 100644 --- a/crates/hir_ty/src/walk.rs +++ b/crates/hir_ty/src/walk.rs | |||
@@ -153,7 +153,7 @@ impl TypeWalk for Ty { | |||
153 | p.walk(f); | 153 | p.walk(f); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, ty) | TyKind::Raw(_, ty) => { | 156 | TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, _, ty) | TyKind::Raw(_, ty) => { |
157 | ty.walk(f); | 157 | ty.walk(f); |
158 | } | 158 | } |
159 | TyKind::Function(fn_pointer) => { | 159 | TyKind::Function(fn_pointer) => { |
@@ -187,7 +187,7 @@ impl TypeWalk for Ty { | |||
187 | TyKind::Alias(AliasTy::Opaque(o_ty)) => { | 187 | TyKind::Alias(AliasTy::Opaque(o_ty)) => { |
188 | o_ty.substitution.walk_mut_binders(f, binders); | 188 | o_ty.substitution.walk_mut_binders(f, binders); |
189 | } | 189 | } |
190 | TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, ty) | TyKind::Raw(_, ty) => { | 190 | TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, _, ty) | TyKind::Raw(_, ty) => { |
191 | ty.walk_mut_binders(f, binders); | 191 | ty.walk_mut_binders(f, binders); |
192 | } | 192 | } |
193 | TyKind::Function(fn_pointer) => { | 193 | TyKind::Function(fn_pointer) => { |