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 | 22 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 20 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 18 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/types.rs | 5 | ||||
-rw-r--r-- | crates/hir_ty/src/walk.rs | 4 |
12 files changed, 66 insertions, 39 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..77fb36332 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -23,7 +23,7 @@ use crate::{ | |||
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 | ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeWalk, | 26 | LifetimeData, ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, |
27 | }; | 27 | }; |
28 | 28 | ||
29 | use super::{ | 29 | use super::{ |
@@ -527,7 +527,9 @@ 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 => { |
531 | TyKind::Ref(mutability, LifetimeData::Static.intern(&Interner), inner_ty) | ||
532 | } | ||
531 | } | 533 | } |
532 | .intern(&Interner) | 534 | .intern(&Interner) |
533 | } | 535 | } |
@@ -730,13 +732,17 @@ impl<'a> InferenceContext<'a> { | |||
730 | } | 732 | } |
731 | Expr::Literal(lit) => match lit { | 733 | Expr::Literal(lit) => match lit { |
732 | Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), | 734 | Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), |
733 | Literal::String(..) => { | 735 | Literal::String(..) => TyKind::Ref( |
734 | TyKind::Ref(Mutability::Not, TyKind::Str.intern(&Interner)).intern(&Interner) | 736 | Mutability::Not, |
735 | } | 737 | LifetimeData::Static.intern(&Interner), |
738 | TyKind::Str.intern(&Interner), | ||
739 | ) | ||
740 | .intern(&Interner), | ||
736 | Literal::ByteString(..) => { | 741 | Literal::ByteString(..) => { |
737 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); | 742 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); |
738 | let array_type = TyKind::Array(byte_type).intern(&Interner); | 743 | let array_type = TyKind::Array(byte_type).intern(&Interner); |
739 | TyKind::Ref(Mutability::Not, array_type).intern(&Interner) | 744 | TyKind::Ref(Mutability::Not, LifetimeData::Static.intern(&Interner), array_type) |
745 | .intern(&Interner) | ||
740 | } | 746 | } |
741 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), | 747 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), |
742 | Literal::Int(_v, ty) => match ty { | 748 | Literal::Int(_v, ty) => match ty { |
@@ -872,7 +878,9 @@ impl<'a> InferenceContext<'a> { | |||
872 | // Apply autoref so the below unification works correctly | 878 | // Apply autoref so the below unification works correctly |
873 | // FIXME: return correct autorefs from lookup_method | 879 | // FIXME: return correct autorefs from lookup_method |
874 | let actual_receiver_ty = match expected_receiver_ty.as_reference() { | 880 | let actual_receiver_ty = match expected_receiver_ty.as_reference() { |
875 | Some((_, mutability)) => TyKind::Ref(mutability, derefed_receiver_ty).intern(&Interner), | 881 | Some((_, lifetime, mutability)) => { |
882 | TyKind::Ref(mutability, lifetime, derefed_receiver_ty).intern(&Interner) | ||
883 | } | ||
876 | _ => derefed_receiver_ty, | 884 | _ => derefed_receiver_ty, |
877 | }; | 885 | }; |
878 | self.unify(&expected_receiver_ty, &actual_receiver_ty); | 886 | 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..b5e97cc8c 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, utils::variant_data, Interner, LifetimeData, 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,8 @@ 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, LifetimeData::Static.intern(&Interner), subty) |
175 | .intern(&Interner) | ||
175 | } | 176 | } |
176 | Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( | 177 | Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( |
177 | p.as_ref(), | 178 | p.as_ref(), |
@@ -203,9 +204,12 @@ impl<'a> InferenceContext<'a> { | |||
203 | let inner_ty = self.insert_type_vars_shallow(inner_ty); | 204 | let inner_ty = self.insert_type_vars_shallow(inner_ty); |
204 | 205 | ||
205 | let bound_ty = match mode { | 206 | let bound_ty = match mode { |
206 | BindingMode::Ref(mutability) => { | 207 | BindingMode::Ref(mutability) => TyKind::Ref( |
207 | TyKind::Ref(mutability, inner_ty.clone()).intern(&Interner) | 208 | mutability, |
208 | } | 209 | LifetimeData::Static.intern(&Interner), |
210 | inner_ty.clone(), | ||
211 | ) | ||
212 | .intern(&Interner), | ||
209 | BindingMode::Move => inner_ty.clone(), | 213 | BindingMode::Move => inner_ty.clone(), |
210 | }; | 214 | }; |
211 | let bound_ty = self.resolve_ty_as_possible(bound_ty); | 215 | let bound_ty = self.resolve_ty_as_possible(bound_ty); |
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..1dfe2075c 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 | ||
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 3cbb6ad54..5a769fa6a 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -34,7 +34,7 @@ use crate::{ | |||
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, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause, | 37 | FnSubst, ImplTraitId, LifetimeData, 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,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 = LifetimeData::Static.intern(&Interner); |
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) => { |
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 6d65d3eb9..427844c12 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -21,8 +21,8 @@ use crate::{ | |||
21 | primitive::{self, FloatTy, IntTy, UintTy}, | 21 | primitive::{self, FloatTy, IntTy, UintTy}, |
22 | utils::all_super_traits, | 22 | utils::all_super_traits, |
23 | AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId, | 23 | AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId, |
24 | InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, Ty, TyBuilder, TyKind, | 24 | InEnvironment, Interner, LifetimeData, Scalar, Substitution, TraitEnvironment, Ty, TyBuilder, |
25 | TypeWalk, | 25 | TyKind, TypeWalk, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | /// This is used as a key for indexing impls. | 28 | /// This is used as a key for indexing impls. |
@@ -453,7 +453,12 @@ fn iterate_method_candidates_with_autoref( | |||
453 | } | 453 | } |
454 | let refed = Canonical { | 454 | let refed = Canonical { |
455 | binders: deref_chain[0].binders.clone(), | 455 | binders: deref_chain[0].binders.clone(), |
456 | value: TyKind::Ref(Mutability::Not, deref_chain[0].value.clone()).intern(&Interner), | 456 | value: TyKind::Ref( |
457 | Mutability::Not, | ||
458 | LifetimeData::Static.intern(&Interner), | ||
459 | deref_chain[0].value.clone(), | ||
460 | ) | ||
461 | .intern(&Interner), | ||
457 | }; | 462 | }; |
458 | if iterate_method_candidates_by_receiver( | 463 | if iterate_method_candidates_by_receiver( |
459 | &refed, | 464 | &refed, |
@@ -470,7 +475,12 @@ fn iterate_method_candidates_with_autoref( | |||
470 | } | 475 | } |
471 | let ref_muted = Canonical { | 476 | let ref_muted = Canonical { |
472 | binders: deref_chain[0].binders.clone(), | 477 | binders: deref_chain[0].binders.clone(), |
473 | value: TyKind::Ref(Mutability::Mut, deref_chain[0].value.clone()).intern(&Interner), | 478 | value: TyKind::Ref( |
479 | Mutability::Mut, | ||
480 | LifetimeData::Static.intern(&Interner), | ||
481 | deref_chain[0].value.clone(), | ||
482 | ) | ||
483 | .intern(&Interner), | ||
474 | }; | 484 | }; |
475 | if iterate_method_candidates_by_receiver( | 485 | if iterate_method_candidates_by_receiver( |
476 | &ref_muted, | 486 | &ref_muted, |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 3047fbacb..26f8fdbdc 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -11,7 +11,7 @@ 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, AliasTy, CallableDefId, |
14 | Canonical, DomainGoal, FnPointer, GenericArg, InEnvironment, OpaqueTy, ProjectionTy, | 14 | Canonical, DomainGoal, FnPointer, GenericArg, InEnvironment, Lifetime, OpaqueTy, ProjectionTy, |
15 | QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause, | 15 | QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause, |
16 | }; | 16 | }; |
17 | 17 | ||
@@ -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)); |
@@ -167,8 +167,8 @@ impl ToChalk for Ty { | |||
167 | } | 167 | } |
168 | chalk_ir::TyKind::Raw(mutability, ty) => TyKind::Raw(mutability, from_chalk(db, ty)), | 168 | 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)), | 169 | chalk_ir::TyKind::Slice(ty) => TyKind::Slice(from_chalk(db, ty)), |
170 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { | 170 | chalk_ir::TyKind::Ref(mutability, lifetime, ty) => { |
171 | TyKind::Ref(mutability, from_chalk(db, ty)) | 171 | TyKind::Ref(mutability, lifetime, from_chalk(db, ty)) |
172 | } | 172 | } |
173 | chalk_ir::TyKind::Str => TyKind::Str, | 173 | chalk_ir::TyKind::Str => TyKind::Str, |
174 | chalk_ir::TyKind::Never => TyKind::Never, | 174 | chalk_ir::TyKind::Never => TyKind::Never, |
@@ -192,10 +192,10 @@ impl ToChalk for Ty { | |||
192 | fn ref_to_chalk( | 192 | fn ref_to_chalk( |
193 | db: &dyn HirDatabase, | 193 | db: &dyn HirDatabase, |
194 | mutability: chalk_ir::Mutability, | 194 | mutability: chalk_ir::Mutability, |
195 | lifetime: Lifetime, | ||
195 | ty: Ty, | 196 | ty: Ty, |
196 | ) -> chalk_ir::Ty<Interner> { | 197 | ) -> chalk_ir::Ty<Interner> { |
197 | let arg = ty.to_chalk(db); | 198 | let arg = ty.to_chalk(db); |
198 | let lifetime = LifetimeData::Static.intern(&Interner); | ||
199 | chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) | 199 | chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) |
200 | } | 200 | } |
201 | 201 | ||
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index d4e07a6b8..c984a31c8 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)] |
@@ -122,7 +123,7 @@ pub enum TyKind { | |||
122 | 123 | ||
123 | /// A reference; a pointer with an associated lifetime. Written as | 124 | /// A reference; a pointer with an associated lifetime. Written as |
124 | /// `&'a mut T` or `&'a T`. | 125 | /// `&'a mut T` or `&'a T`. |
125 | Ref(Mutability, Ty), | 126 | Ref(Mutability, Lifetime, Ty), |
126 | 127 | ||
127 | /// This represents a placeholder for an opaque type in situations where we | 128 | /// 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 | 129 | /// 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) => { |