aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-03-14 16:40:55 +0000
committerFlorian Diebold <[email protected]>2021-03-14 19:21:05 +0000
commit42217738e0b121a8e5d48a9a55cb51ef6c98975f (patch)
tree63b3fc22a011ae0ee37a91cb19f5dcfe390507f1
parentaf466f8542173002361eb134e66102908c7cd024 (diff)
Don't use Substs for Ref/Raw/Array/Slice
-rw-r--r--crates/hir/src/lib.rs34
-rw-r--r--crates/hir_ty/src/display.rs9
-rw-r--r--crates/hir_ty/src/infer/coerce.rs10
-rw-r--r--crates/hir_ty/src/infer/expr.rs19
-rw-r--r--crates/hir_ty/src/infer/pat.rs10
-rw-r--r--crates/hir_ty/src/infer/unify.rs24
-rw-r--r--crates/hir_ty/src/lib.rs67
-rw-r--r--crates/hir_ty/src/lower.rs10
-rw-r--r--crates/hir_ty/src/method_resolution.rs6
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs30
10 files changed, 103 insertions, 116 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index eb1cd66fb..c0810c69b 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1598,7 +1598,7 @@ impl Type {
1598 1598
1599 pub fn remove_ref(&self) -> Option<Type> { 1599 pub fn remove_ref(&self) -> Option<Type> {
1600 match &self.ty.value.interned(&Interner) { 1600 match &self.ty.value.interned(&Interner) {
1601 TyKind::Ref(.., substs) => Some(self.derived(substs[0].clone())), 1601 TyKind::Ref(.., ty) => Some(self.derived(ty.clone())),
1602 _ => None, 1602 _ => None,
1603 } 1603 }
1604 } 1604 }
@@ -1752,10 +1752,30 @@ impl Type {
1752 return go(&self.ty.value); 1752 return go(&self.ty.value);
1753 1753
1754 fn go(ty: &Ty) -> bool { 1754 fn go(ty: &Ty) -> bool {
1755 if ty.is_unknown() { 1755 match ty.interned(&Interner) {
1756 true 1756 TyKind::Unknown => true,
1757 } else { 1757
1758 ty.substs().map_or(false, |substs| substs.iter().any(go)) 1758 TyKind::Adt(_, substs)
1759 | TyKind::AssociatedType(_, substs)
1760 | TyKind::Tuple(_, substs)
1761 | TyKind::OpaqueType(_, substs)
1762 | TyKind::FnDef(_, substs)
1763 | TyKind::Closure(_, substs) => substs.iter().any(go),
1764
1765 TyKind::Array(ty) | TyKind::Slice(ty) | TyKind::Raw(_, ty) | TyKind::Ref(_, ty) => {
1766 go(ty)
1767 }
1768
1769 TyKind::Scalar(_)
1770 | TyKind::Str
1771 | TyKind::Never
1772 | TyKind::Placeholder(_)
1773 | TyKind::BoundVar(_)
1774 | TyKind::InferenceVar(_, _)
1775 | TyKind::Dyn(_)
1776 | TyKind::Function(_)
1777 | TyKind::Alias(_)
1778 | TyKind::ForeignType(_) => false,
1759 } 1779 }
1760 } 1780 }
1761 } 1781 }
@@ -1990,6 +2010,10 @@ impl Type {
1990 walk_bounds(db, &type_.derived(ty.clone()), bounds.as_ref(), cb); 2010 walk_bounds(db, &type_.derived(ty.clone()), bounds.as_ref(), cb);
1991 } 2011 }
1992 2012
2013 TyKind::Ref(_, ty) | TyKind::Raw(_, ty) | TyKind::Array(ty) | TyKind::Slice(ty) => {
2014 walk_type(db, &type_.derived(ty.clone()), cb);
2015 }
2016
1993 _ => {} 2017 _ => {}
1994 } 2018 }
1995 if let Some(substs) = ty.substs() { 2019 if let Some(substs) = ty.substs() {
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index 378c951c5..c1062387e 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -276,20 +276,17 @@ impl HirDisplay for Ty {
276 &TyKind::Scalar(Scalar::Float(t)) => write!(f, "{}", primitive::float_ty_to_string(t))?, 276 &TyKind::Scalar(Scalar::Float(t)) => write!(f, "{}", primitive::float_ty_to_string(t))?,
277 &TyKind::Scalar(Scalar::Int(t)) => write!(f, "{}", primitive::int_ty_to_string(t))?, 277 &TyKind::Scalar(Scalar::Int(t)) => write!(f, "{}", primitive::int_ty_to_string(t))?,
278 &TyKind::Scalar(Scalar::Uint(t)) => write!(f, "{}", primitive::uint_ty_to_string(t))?, 278 &TyKind::Scalar(Scalar::Uint(t)) => write!(f, "{}", primitive::uint_ty_to_string(t))?,
279 TyKind::Slice(parameters) => { 279 TyKind::Slice(t) => {
280 let t = parameters.as_single();
281 write!(f, "[")?; 280 write!(f, "[")?;
282 t.hir_fmt(f)?; 281 t.hir_fmt(f)?;
283 write!(f, "]")?; 282 write!(f, "]")?;
284 } 283 }
285 TyKind::Array(parameters) => { 284 TyKind::Array(t) => {
286 let t = parameters.as_single();
287 write!(f, "[")?; 285 write!(f, "[")?;
288 t.hir_fmt(f)?; 286 t.hir_fmt(f)?;
289 write!(f, "; _]")?; 287 write!(f, "; _]")?;
290 } 288 }
291 TyKind::Raw(m, parameters) | TyKind::Ref(m, parameters) => { 289 TyKind::Raw(m, t) | TyKind::Ref(m, t) => {
292 let t = parameters.as_single();
293 let ty_display = 290 let ty_display =
294 t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); 291 t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target);
295 292
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs
index 435f7d0db..137419264 100644
--- a/crates/hir_ty/src/infer/coerce.rs
+++ b/crates/hir_ty/src/infer/coerce.rs
@@ -111,9 +111,7 @@ impl<'a> InferenceContext<'a> {
111 // Auto Deref if cannot coerce 111 // Auto Deref if cannot coerce
112 match (from_ty.interned(&Interner), to_ty.interned(&Interner)) { 112 match (from_ty.interned(&Interner), to_ty.interned(&Interner)) {
113 // FIXME: DerefMut 113 // FIXME: DerefMut
114 (TyKind::Ref(_, st1), TyKind::Ref(_, st2)) => { 114 (TyKind::Ref(_, st1), TyKind::Ref(_, st2)) => self.unify_autoderef_behind_ref(st1, st2),
115 self.unify_autoderef_behind_ref(&st1[0], &st2[0])
116 }
117 115
118 // Otherwise, normal unify 116 // Otherwise, normal unify
119 _ => self.unify(&from_ty, to_ty), 117 _ => self.unify(&from_ty, to_ty),
@@ -178,11 +176,7 @@ impl<'a> InferenceContext<'a> {
178 // Stop when constructor matches. 176 // Stop when constructor matches.
179 if from_ty.equals_ctor(&to_ty) { 177 if from_ty.equals_ctor(&to_ty) {
180 // It will not recurse to `coerce`. 178 // It will not recurse to `coerce`.
181 return match (from_ty.substs(), to_ty.substs()) { 179 return self.table.unify(&from_ty, &to_ty);
182 (Some(st1), Some(st2)) => self.table.unify_substs(st1, st2, 0),
183 (None, None) => true,
184 _ => false,
185 };
186 } else if self.table.unify_inner_trivial(&derefed_ty, &to_ty, 0) { 180 } else if self.table.unify_inner_trivial(&derefed_ty, &to_ty, 0) {
187 return true; 181 return true;
188 } 182 }
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index e9ca2b86f..8c58a1b6c 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -504,8 +504,8 @@ impl<'a> InferenceContext<'a> {
504 }; 504 };
505 let inner_ty = self.infer_expr_inner(*expr, &expectation); 505 let inner_ty = self.infer_expr_inner(*expr, &expectation);
506 match rawness { 506 match rawness {
507 Rawness::RawPtr => TyKind::Raw(mutability, Substs::single(inner_ty)), 507 Rawness::RawPtr => TyKind::Raw(mutability, inner_ty),
508 Rawness::Ref => TyKind::Ref(mutability, Substs::single(inner_ty)), 508 Rawness::Ref => TyKind::Ref(mutability, inner_ty),
509 } 509 }
510 .intern(&Interner) 510 .intern(&Interner)
511 } 511 }
@@ -686,7 +686,7 @@ impl<'a> InferenceContext<'a> {
686 } 686 }
687 Expr::Array(array) => { 687 Expr::Array(array) => {
688 let elem_ty = match expected.ty.interned(&Interner) { 688 let elem_ty = match expected.ty.interned(&Interner) {
689 TyKind::Array(st) | TyKind::Slice(st) => st.as_single().clone(), 689 TyKind::Array(st) | TyKind::Slice(st) => st.clone(),
690 _ => self.table.new_type_var(), 690 _ => self.table.new_type_var(),
691 }; 691 };
692 692
@@ -710,18 +710,17 @@ impl<'a> InferenceContext<'a> {
710 } 710 }
711 } 711 }
712 712
713 TyKind::Array(Substs::single(elem_ty)).intern(&Interner) 713 TyKind::Array(elem_ty).intern(&Interner)
714 } 714 }
715 Expr::Literal(lit) => match lit { 715 Expr::Literal(lit) => match lit {
716 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), 716 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
717 Literal::String(..) => { 717 Literal::String(..) => {
718 TyKind::Ref(Mutability::Not, Substs::single(TyKind::Str.intern(&Interner))) 718 TyKind::Ref(Mutability::Not, TyKind::Str.intern(&Interner)).intern(&Interner)
719 .intern(&Interner)
720 } 719 }
721 Literal::ByteString(..) => { 720 Literal::ByteString(..) => {
722 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); 721 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
723 let array_type = TyKind::Array(Substs::single(byte_type)).intern(&Interner); 722 let array_type = TyKind::Array(byte_type).intern(&Interner);
724 TyKind::Ref(Mutability::Not, Substs::single(array_type)).intern(&Interner) 723 TyKind::Ref(Mutability::Not, array_type).intern(&Interner)
725 } 724 }
726 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), 725 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
727 Literal::Int(_v, ty) => match ty { 726 Literal::Int(_v, ty) => match ty {
@@ -855,9 +854,7 @@ impl<'a> InferenceContext<'a> {
855 // Apply autoref so the below unification works correctly 854 // Apply autoref so the below unification works correctly
856 // FIXME: return correct autorefs from lookup_method 855 // FIXME: return correct autorefs from lookup_method
857 let actual_receiver_ty = match expected_receiver_ty.as_reference() { 856 let actual_receiver_ty = match expected_receiver_ty.as_reference() {
858 Some((_, mutability)) => { 857 Some((_, mutability)) => TyKind::Ref(mutability, derefed_receiver_ty).intern(&Interner),
859 TyKind::Ref(mutability, Substs::single(derefed_receiver_ty)).intern(&Interner)
860 }
861 _ => derefed_receiver_ty, 858 _ => derefed_receiver_ty,
862 }; 859 };
863 self.unify(&expected_receiver_ty, &actual_receiver_ty); 860 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 2e812ab94..9e8ca18ef 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -163,7 +163,7 @@ impl<'a> InferenceContext<'a> {
163 _ => self.result.standard_types.unknown.clone(), 163 _ => self.result.standard_types.unknown.clone(),
164 }; 164 };
165 let subty = self.infer_pat(*pat, &expectation, default_bm); 165 let subty = self.infer_pat(*pat, &expectation, default_bm);
166 TyKind::Ref(mutability, Substs::single(subty)).intern(&Interner) 166 TyKind::Ref(mutability, subty).intern(&Interner)
167 } 167 }
168 Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( 168 Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat(
169 p.as_ref(), 169 p.as_ref(),
@@ -196,7 +196,7 @@ impl<'a> InferenceContext<'a> {
196 196
197 let bound_ty = match mode { 197 let bound_ty = match mode {
198 BindingMode::Ref(mutability) => { 198 BindingMode::Ref(mutability) => {
199 TyKind::Ref(mutability, Substs::single(inner_ty.clone())).intern(&Interner) 199 TyKind::Ref(mutability, inner_ty.clone()).intern(&Interner)
200 } 200 }
201 BindingMode::Move => inner_ty.clone(), 201 BindingMode::Move => inner_ty.clone(),
202 }; 202 };
@@ -206,8 +206,8 @@ impl<'a> InferenceContext<'a> {
206 } 206 }
207 Pat::Slice { prefix, slice, suffix } => { 207 Pat::Slice { prefix, slice, suffix } => {
208 let (container_ty, elem_ty): (fn(_) -> _, _) = match expected.interned(&Interner) { 208 let (container_ty, elem_ty): (fn(_) -> _, _) = match expected.interned(&Interner) {
209 TyKind::Array(st) => (TyKind::Array, st.as_single().clone()), 209 TyKind::Array(st) => (TyKind::Array, st.clone()),
210 TyKind::Slice(st) => (TyKind::Slice, st.as_single().clone()), 210 TyKind::Slice(st) => (TyKind::Slice, st.clone()),
211 _ => (TyKind::Slice, self.err_ty()), 211 _ => (TyKind::Slice, self.err_ty()),
212 }; 212 };
213 213
@@ -215,7 +215,7 @@ impl<'a> InferenceContext<'a> {
215 self.infer_pat(*pat_id, &elem_ty, default_bm); 215 self.infer_pat(*pat_id, &elem_ty, default_bm);
216 } 216 }
217 217
218 let pat_ty = container_ty(Substs::single(elem_ty)).intern(&Interner); 218 let pat_ty = container_ty(elem_ty).intern(&Interner);
219 if let Some(slice_pat_id) = slice { 219 if let Some(slice_pat_id) = slice {
220 self.infer_pat(*slice_pat_id, &pat_ty, default_bm); 220 self.infer_pat(*slice_pat_id, &pat_ty, default_bm);
221 } 221 }
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 2501a4e0a..66f8fe8a3 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -7,8 +7,8 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
7 7
8use super::{InferenceContext, Obligation}; 8use super::{InferenceContext, Obligation};
9use crate::{ 9use crate::{
10 BoundVar, Canonical, DebruijnIndex, GenericPredicate, InEnvironment, InferenceVar, Interner, 10 BoundVar, Canonical, DebruijnIndex, FnPointer, GenericPredicate, InEnvironment, InferenceVar,
11 Scalar, Substs, Ty, TyKind, TypeWalk, 11 Interner, Scalar, Substs, Ty, TyKind, TypeWalk,
12}; 12};
13 13
14impl<'a> InferenceContext<'a> { 14impl<'a> InferenceContext<'a> {
@@ -283,9 +283,23 @@ impl InferenceTable {
283 let ty1 = self.resolve_ty_shallow(ty1); 283 let ty1 = self.resolve_ty_shallow(ty1);
284 let ty2 = self.resolve_ty_shallow(ty2); 284 let ty2 = self.resolve_ty_shallow(ty2);
285 if ty1.equals_ctor(&ty2) { 285 if ty1.equals_ctor(&ty2) {
286 match (ty1.substs(), ty2.substs()) { 286 match (ty1.interned(&Interner), ty2.interned(&Interner)) {
287 (Some(st1), Some(st2)) => self.unify_substs(st1, st2, depth + 1), 287 (TyKind::Adt(_, substs1), TyKind::Adt(_, substs2))
288 (None, None) => true, 288 | (TyKind::FnDef(_, substs1), TyKind::FnDef(_, substs2))
289 | (
290 TyKind::Function(FnPointer { substs: substs1, .. }),
291 TyKind::Function(FnPointer { substs: substs2, .. }),
292 )
293 | (TyKind::Tuple(_, substs1), TyKind::Tuple(_, substs2))
294 | (TyKind::OpaqueType(_, substs1), TyKind::OpaqueType(_, substs2))
295 | (TyKind::AssociatedType(_, substs1), TyKind::AssociatedType(_, substs2))
296 | (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) => {
297 self.unify_substs(substs1, substs2, depth + 1)
298 }
299 (TyKind::Ref(_, ty1), TyKind::Ref(_, ty2))
300 | (TyKind::Raw(_, ty1), TyKind::Raw(_, ty2))
301 | (TyKind::Array(ty1), TyKind::Array(ty2))
302 | (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1),
289 _ => false, 303 _ => false,
290 } 304 }
291 } else { 305 } else {
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 0b2da8971..503910dde 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -151,17 +151,17 @@ pub enum TyKind {
151 Tuple(usize, Substs), 151 Tuple(usize, Substs),
152 152
153 /// An array with the given length. Written as `[T; n]`. 153 /// An array with the given length. Written as `[T; n]`.
154 Array(Substs), 154 Array(Ty),
155 155
156 /// The pointee of an array slice. Written as `[T]`. 156 /// The pointee of an array slice. Written as `[T]`.
157 Slice(Substs), 157 Slice(Ty),
158 158
159 /// A raw pointer. Written as `*mut T` or `*const T` 159 /// A raw pointer. Written as `*mut T` or `*const T`
160 Raw(Mutability, Substs), 160 Raw(Mutability, Ty),
161 161
162 /// A reference; a pointer with an associated lifetime. Written as 162 /// A reference; a pointer with an associated lifetime. Written as
163 /// `&'a mut T` or `&'a T`. 163 /// `&'a mut T` or `&'a T`.
164 Ref(Mutability, Substs), 164 Ref(Mutability, Ty),
165 165
166 /// This represents a placeholder for an opaque type in situations where we 166 /// This represents a placeholder for an opaque type in situations where we
167 /// don't know the hidden type (i.e. currently almost always). This is 167 /// don't know the hidden type (i.e. currently almost always). This is
@@ -673,19 +673,15 @@ impl Ty {
673 673
674 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { 674 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> {
675 match self.interned(&Interner) { 675 match self.interned(&Interner) {
676 TyKind::Ref(mutability, parameters) => Some((parameters.as_single(), *mutability)), 676 TyKind::Ref(mutability, ty) => Some((ty, *mutability)),
677 _ => None, 677 _ => None,
678 } 678 }
679 } 679 }
680 680
681 pub fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)> { 681 pub fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)> {
682 match self.interned(&Interner) { 682 match self.interned(&Interner) {
683 TyKind::Ref(mutability, parameters) => { 683 TyKind::Ref(mutability, ty) => Some((ty, Rawness::Ref, *mutability)),
684 Some((parameters.as_single(), Rawness::Ref, *mutability)) 684 TyKind::Raw(mutability, ty) => Some((ty, Rawness::RawPtr, *mutability)),
685 }
686 TyKind::Raw(mutability, parameters) => {
687 Some((parameters.as_single(), Rawness::RawPtr, *mutability))
688 }
689 _ => None, 685 _ => None,
690 } 686 }
691 } 687 }
@@ -693,8 +689,8 @@ impl Ty {
693 pub fn strip_references(&self) -> &Ty { 689 pub fn strip_references(&self) -> &Ty {
694 let mut t: &Ty = self; 690 let mut t: &Ty = self;
695 691
696 while let TyKind::Ref(_mutability, parameters) = t.interned(&Interner) { 692 while let TyKind::Ref(_mutability, ty) = t.interned(&Interner) {
697 t = parameters.as_single(); 693 t = ty;
698 } 694 }
699 695
700 t 696 t
@@ -780,8 +776,8 @@ impl Ty {
780 776
781 fn builtin_deref(&self) -> Option<Ty> { 777 fn builtin_deref(&self) -> Option<Ty> {
782 match self.interned(&Interner) { 778 match self.interned(&Interner) {
783 TyKind::Ref(.., parameters) => Some(Ty::clone(parameters.as_single())), 779 TyKind::Ref(.., ty) => Some(ty.clone()),
784 TyKind::Raw(.., parameters) => Some(Ty::clone(parameters.as_single())), 780 TyKind::Raw(.., ty) => Some(ty.clone()),
785 _ => None, 781 _ => None,
786 } 782 }
787 } 783 }
@@ -817,40 +813,11 @@ impl Ty {
817 } 813 }
818 } 814 }
819 815
820 /// If this is a type with type parameters (an ADT or function), replaces
821 /// the `Substs` for these type parameters with the given ones. (So e.g. if
822 /// `self` is `Option<_>` and the substs contain `u32`, we'll have
823 /// `Option<u32>` afterwards.)
824 pub fn apply_substs(mut self, new_substs: Substs) -> Ty {
825 match self.interned_mut() {
826 TyKind::Adt(_, substs)
827 | TyKind::Slice(substs)
828 | TyKind::Array(substs)
829 | TyKind::Raw(_, substs)
830 | TyKind::Ref(_, substs)
831 | TyKind::FnDef(_, substs)
832 | TyKind::Function(FnPointer { substs, .. })
833 | TyKind::Tuple(_, substs)
834 | TyKind::OpaqueType(_, substs)
835 | TyKind::AssociatedType(_, substs)
836 | TyKind::Closure(.., substs) => {
837 assert_eq!(substs.len(), new_substs.len());
838 *substs = new_substs;
839 }
840 _ => (),
841 }
842 self
843 }
844
845 /// Returns the type parameters of this type if it has some (i.e. is an ADT 816 /// Returns the type parameters of this type if it has some (i.e. is an ADT
846 /// or function); so if `self` is `Option<u32>`, this returns the `u32`. 817 /// or function); so if `self` is `Option<u32>`, this returns the `u32`.
847 pub fn substs(&self) -> Option<&Substs> { 818 pub fn substs(&self) -> Option<&Substs> {
848 match self.interned(&Interner) { 819 match self.interned(&Interner) {
849 TyKind::Adt(_, substs) 820 TyKind::Adt(_, substs)
850 | TyKind::Slice(substs)
851 | TyKind::Array(substs)
852 | TyKind::Raw(_, substs)
853 | TyKind::Ref(_, substs)
854 | TyKind::FnDef(_, substs) 821 | TyKind::FnDef(_, substs)
855 | TyKind::Function(FnPointer { substs, .. }) 822 | TyKind::Function(FnPointer { substs, .. })
856 | TyKind::Tuple(_, substs) 823 | TyKind::Tuple(_, substs)
@@ -861,13 +828,9 @@ impl Ty {
861 } 828 }
862 } 829 }
863 830
864 pub fn substs_mut(&mut self) -> Option<&mut Substs> { 831 fn substs_mut(&mut self) -> Option<&mut Substs> {
865 match self.interned_mut() { 832 match self.interned_mut() {
866 TyKind::Adt(_, substs) 833 TyKind::Adt(_, substs)
867 | TyKind::Slice(substs)
868 | TyKind::Array(substs)
869 | TyKind::Raw(_, substs)
870 | TyKind::Ref(_, substs)
871 | TyKind::FnDef(_, substs) 834 | TyKind::FnDef(_, substs)
872 | TyKind::Function(FnPointer { substs, .. }) 835 | TyKind::Function(FnPointer { substs, .. })
873 | TyKind::Tuple(_, substs) 836 | TyKind::Tuple(_, substs)
@@ -1076,6 +1039,9 @@ impl TypeWalk for Ty {
1076 p.walk(f); 1039 p.walk(f);
1077 } 1040 }
1078 } 1041 }
1042 TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, ty) | TyKind::Raw(_, ty) => {
1043 ty.walk(f);
1044 }
1079 _ => { 1045 _ => {
1080 if let Some(substs) = self.substs() { 1046 if let Some(substs) = self.substs() {
1081 for t in substs.iter() { 1047 for t in substs.iter() {
@@ -1104,6 +1070,9 @@ impl TypeWalk for Ty {
1104 TyKind::Alias(AliasTy::Opaque(o_ty)) => { 1070 TyKind::Alias(AliasTy::Opaque(o_ty)) => {
1105 o_ty.substitution.walk_mut_binders(f, binders); 1071 o_ty.substitution.walk_mut_binders(f, binders);
1106 } 1072 }
1073 TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, ty) | TyKind::Raw(_, ty) => {
1074 ty.walk_mut_binders(f, binders);
1075 }
1107 _ => { 1076 _ => {
1108 if let Some(substs) = self.substs_mut() { 1077 if let Some(substs) = self.substs_mut() {
1109 substs.walk_mut_binders(f, binders); 1078 substs.walk_mut_binders(f, binders);
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 2a4ad9172..b4c650fa1 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -160,21 +160,19 @@ impl<'a> TyLoweringContext<'a> {
160 } 160 }
161 TypeRef::RawPtr(inner, mutability) => { 161 TypeRef::RawPtr(inner, mutability) => {
162 let inner_ty = self.lower_ty(inner); 162 let inner_ty = self.lower_ty(inner);
163 TyKind::Raw(lower_to_chalk_mutability(*mutability), Substs::single(inner_ty)) 163 TyKind::Raw(lower_to_chalk_mutability(*mutability), inner_ty).intern(&Interner)
164 .intern(&Interner)
165 } 164 }
166 TypeRef::Array(inner) => { 165 TypeRef::Array(inner) => {
167 let inner_ty = self.lower_ty(inner); 166 let inner_ty = self.lower_ty(inner);
168 TyKind::Array(Substs::single(inner_ty)).intern(&Interner) 167 TyKind::Array(inner_ty).intern(&Interner)
169 } 168 }
170 TypeRef::Slice(inner) => { 169 TypeRef::Slice(inner) => {
171 let inner_ty = self.lower_ty(inner); 170 let inner_ty = self.lower_ty(inner);
172 TyKind::Slice(Substs::single(inner_ty)).intern(&Interner) 171 TyKind::Slice(inner_ty).intern(&Interner)
173 } 172 }
174 TypeRef::Reference(inner, _, mutability) => { 173 TypeRef::Reference(inner, _, mutability) => {
175 let inner_ty = self.lower_ty(inner); 174 let inner_ty = self.lower_ty(inner);
176 TyKind::Ref(lower_to_chalk_mutability(*mutability), Substs::single(inner_ty)) 175 TyKind::Ref(lower_to_chalk_mutability(*mutability), inner_ty).intern(&Interner)
177 .intern(&Interner)
178 } 176 }
179 TypeRef::Placeholder => TyKind::Unknown.intern(&Interner), 177 TypeRef::Placeholder => TyKind::Unknown.intern(&Interner),
180 TypeRef::Fn(params, is_varargs) => { 178 TypeRef::Fn(params, is_varargs) => {
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index c7055bee5..741440006 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -435,8 +435,7 @@ fn iterate_method_candidates_with_autoref(
435 } 435 }
436 let refed = Canonical { 436 let refed = Canonical {
437 kinds: deref_chain[0].kinds.clone(), 437 kinds: deref_chain[0].kinds.clone(),
438 value: TyKind::Ref(Mutability::Not, Substs::single(deref_chain[0].value.clone())) 438 value: TyKind::Ref(Mutability::Not, deref_chain[0].value.clone()).intern(&Interner),
439 .intern(&Interner),
440 }; 439 };
441 if iterate_method_candidates_by_receiver( 440 if iterate_method_candidates_by_receiver(
442 &refed, 441 &refed,
@@ -452,8 +451,7 @@ fn iterate_method_candidates_with_autoref(
452 } 451 }
453 let ref_muted = Canonical { 452 let ref_muted = Canonical {
454 kinds: deref_chain[0].kinds.clone(), 453 kinds: deref_chain[0].kinds.clone(),
455 value: TyKind::Ref(Mutability::Mut, Substs::single(deref_chain[0].value.clone())) 454 value: TyKind::Ref(Mutability::Mut, deref_chain[0].value.clone()).intern(&Interner),
456 .intern(&Interner),
457 }; 455 };
458 if iterate_method_candidates_by_receiver( 456 if iterate_method_candidates_by_receiver(
459 &ref_muted, 457 &ref_muted,
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 2ab976190..6a8b6752e 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -25,8 +25,8 @@ impl ToChalk for Ty {
25 type Chalk = chalk_ir::Ty<Interner>; 25 type Chalk = chalk_ir::Ty<Interner>;
26 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { 26 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
27 match self.into_inner() { 27 match self.into_inner() {
28 TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters), 28 TyKind::Ref(m, ty) => ref_to_chalk(db, m, ty),
29 TyKind::Array(parameters) => array_to_chalk(db, parameters), 29 TyKind::Array(ty) => array_to_chalk(db, ty),
30 TyKind::Function(FnPointer { sig, substs, .. }) => { 30 TyKind::Function(FnPointer { sig, substs, .. }) => {
31 let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); 31 let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner));
32 chalk_ir::TyKind::Function(chalk_ir::FnPointer { 32 chalk_ir::TyKind::Function(chalk_ir::FnPointer {
@@ -54,13 +54,11 @@ impl ToChalk for Ty {
54 let substitution = substs.to_chalk(db); 54 let substitution = substs.to_chalk(db);
55 chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) 55 chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner)
56 } 56 }
57 TyKind::Raw(mutability, substs) => { 57 TyKind::Raw(mutability, ty) => {
58 let ty = substs[0].clone().to_chalk(db); 58 let ty = ty.to_chalk(db);
59 chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner) 59 chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner)
60 } 60 }
61 TyKind::Slice(substs) => { 61 TyKind::Slice(ty) => chalk_ir::TyKind::Slice(ty.to_chalk(db)).intern(&Interner),
62 chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner)
63 }
64 TyKind::Str => chalk_ir::TyKind::Str.intern(&Interner), 62 TyKind::Str => chalk_ir::TyKind::Str.intern(&Interner),
65 TyKind::FnDef(id, substs) => { 63 TyKind::FnDef(id, substs) => {
66 let substitution = substs.to_chalk(db); 64 let substitution = substs.to_chalk(db);
@@ -114,7 +112,7 @@ impl ToChalk for Ty {
114 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { 112 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
115 match chalk.data(&Interner).kind.clone() { 113 match chalk.data(&Interner).kind.clone() {
116 chalk_ir::TyKind::Error => TyKind::Unknown, 114 chalk_ir::TyKind::Error => TyKind::Unknown,
117 chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))), 115 chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(from_chalk(db, ty)),
118 chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx), 116 chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx),
119 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { 117 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
120 let associated_ty = proj.associated_ty_id; 118 let associated_ty = proj.associated_ty_id;
@@ -168,12 +166,10 @@ impl ToChalk for Ty {
168 chalk_ir::TyKind::Tuple(cardinality, subst) => { 166 chalk_ir::TyKind::Tuple(cardinality, subst) => {
169 TyKind::Tuple(cardinality, from_chalk(db, subst)) 167 TyKind::Tuple(cardinality, from_chalk(db, subst))
170 } 168 }
171 chalk_ir::TyKind::Raw(mutability, ty) => { 169 chalk_ir::TyKind::Raw(mutability, ty) => TyKind::Raw(mutability, from_chalk(db, ty)),
172 TyKind::Raw(mutability, Substs::single(from_chalk(db, ty))) 170 chalk_ir::TyKind::Slice(ty) => TyKind::Slice(from_chalk(db, ty)),
173 }
174 chalk_ir::TyKind::Slice(ty) => TyKind::Slice(Substs::single(from_chalk(db, ty))),
175 chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { 171 chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => {
176 TyKind::Ref(mutability, Substs::single(from_chalk(db, ty))) 172 TyKind::Ref(mutability, from_chalk(db, ty))
177 } 173 }
178 chalk_ir::TyKind::Str => TyKind::Str, 174 chalk_ir::TyKind::Str => TyKind::Str,
179 chalk_ir::TyKind::Never => TyKind::Never, 175 chalk_ir::TyKind::Never => TyKind::Never,
@@ -197,17 +193,17 @@ impl ToChalk for Ty {
197fn ref_to_chalk( 193fn ref_to_chalk(
198 db: &dyn HirDatabase, 194 db: &dyn HirDatabase,
199 mutability: chalk_ir::Mutability, 195 mutability: chalk_ir::Mutability,
200 subst: Substs, 196 ty: Ty,
201) -> chalk_ir::Ty<Interner> { 197) -> chalk_ir::Ty<Interner> {
202 let arg = subst[0].clone().to_chalk(db); 198 let arg = ty.to_chalk(db);
203 let lifetime = LifetimeData::Static.intern(&Interner); 199 let lifetime = LifetimeData::Static.intern(&Interner);
204 chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) 200 chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner)
205} 201}
206 202
207/// We currently don't model constants, but Chalk does. So, we have to insert a 203/// We currently don't model constants, but Chalk does. So, we have to insert a
208/// fake constant here, because Chalks built-in logic may expect it to be there. 204/// fake constant here, because Chalks built-in logic may expect it to be there.
209fn array_to_chalk(db: &dyn HirDatabase, subst: Substs) -> chalk_ir::Ty<Interner> { 205fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> {
210 let arg = subst[0].clone().to_chalk(db); 206 let arg = ty.to_chalk(db);
211 let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner); 207 let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner);
212 let const_ = chalk_ir::ConstData { 208 let const_ = chalk_ir::ConstData {
213 ty: usize_ty, 209 ty: usize_ty,