aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir/src/lib.rs6
-rw-r--r--crates/hir_ty/src/autoderef.rs5
-rw-r--r--crates/hir_ty/src/display.rs23
-rw-r--r--crates/hir_ty/src/infer.rs4
-rw-r--r--crates/hir_ty/src/infer/expr.rs6
-rw-r--r--crates/hir_ty/src/infer/unify.rs6
-rw-r--r--crates/hir_ty/src/lib.rs37
-rw-r--r--crates/hir_ty/src/lower.rs23
-rw-r--r--crates/hir_ty/src/traits.rs2
-rw-r--r--crates/hir_ty/src/traits/chalk.rs4
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs57
11 files changed, 89 insertions, 84 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 10b8171be..eb1cd66fb 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1686,8 +1686,8 @@ impl Type {
1686 .build(); 1686 .build();
1687 let predicate = ProjectionPredicate { 1687 let predicate = ProjectionPredicate {
1688 projection_ty: ProjectionTy { 1688 projection_ty: ProjectionTy {
1689 associated_ty: to_assoc_type_id(alias.id), 1689 associated_ty_id: to_assoc_type_id(alias.id),
1690 parameters: subst, 1690 substitution: subst,
1691 }, 1691 },
1692 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner), 1692 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner),
1693 }; 1693 };
@@ -1979,7 +1979,7 @@ impl Type {
1979 walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb); 1979 walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb);
1980 } 1980 }
1981 1981
1982 walk_substs(db, type_, &opaque_ty.parameters, cb); 1982 walk_substs(db, type_, &opaque_ty.substitution, cb);
1983 } 1983 }
1984 TyKind::Placeholder(_) => { 1984 TyKind::Placeholder(_) => {
1985 if let Some(bounds) = ty.impl_trait_bounds(db) { 1985 if let Some(bounds) = ty.impl_trait_bounds(db) {
diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs
index d739d5d60..56c6b92d4 100644
--- a/crates/hir_ty/src/autoderef.rs
+++ b/crates/hir_ty/src/autoderef.rs
@@ -84,7 +84,10 @@ fn deref_by_trait(
84 let projection = super::traits::ProjectionPredicate { 84 let projection = super::traits::ProjectionPredicate {
85 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())) 85 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len()))
86 .intern(&Interner), 86 .intern(&Interner),
87 projection_ty: super::ProjectionTy { associated_ty: to_assoc_type_id(target), parameters }, 87 projection_ty: super::ProjectionTy {
88 associated_ty_id: to_assoc_type_id(target),
89 substitution: parameters,
90 },
88 }; 91 };
89 92
90 let obligation = super::Obligation::Projection(projection); 93 let obligation = super::Obligation::Projection(projection);
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index e6473586b..378c951c5 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -245,19 +245,19 @@ impl HirDisplay for ProjectionTy {
245 } 245 }
246 246
247 let trait_ = f.db.trait_data(self.trait_(f.db)); 247 let trait_ = f.db.trait_data(self.trait_(f.db));
248 let first_parameter = self.parameters[0].into_displayable( 248 let first_parameter = self.substitution[0].into_displayable(
249 f.db, 249 f.db,
250 f.max_size, 250 f.max_size,
251 f.omit_verbose_types, 251 f.omit_verbose_types,
252 f.display_target, 252 f.display_target,
253 ); 253 );
254 write!(f, "<{} as {}", first_parameter, trait_.name)?; 254 write!(f, "<{} as {}", first_parameter, trait_.name)?;
255 if self.parameters.len() > 1 { 255 if self.substitution.len() > 1 {
256 write!(f, "<")?; 256 write!(f, "<")?;
257 f.write_joined(&self.parameters[1..], ", ")?; 257 f.write_joined(&self.substitution[1..], ", ")?;
258 write!(f, ">")?; 258 write!(f, ">")?;
259 } 259 }
260 write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty)).name)?; 260 write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?;
261 Ok(()) 261 Ok(())
262 } 262 }
263} 263}
@@ -319,7 +319,10 @@ impl HirDisplay for Ty {
319 TyKind::Dyn(predicates) if predicates.len() > 1 => { 319 TyKind::Dyn(predicates) if predicates.len() > 1 => {
320 Cow::Borrowed(predicates.as_ref()) 320 Cow::Borrowed(predicates.as_ref())
321 } 321 }
322 &TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, ref parameters })) => { 322 &TyKind::Alias(AliasTy::Opaque(OpaqueTy {
323 opaque_ty_id,
324 substitution: ref parameters,
325 })) => {
323 let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into()); 326 let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into());
324 if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id { 327 if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id {
325 datas = 328 datas =
@@ -491,8 +494,8 @@ impl HirDisplay for Ty {
491 } 494 }
492 } else { 495 } else {
493 let projection_ty = ProjectionTy { 496 let projection_ty = ProjectionTy {
494 associated_ty: to_assoc_type_id(type_alias), 497 associated_ty_id: to_assoc_type_id(type_alias),
495 parameters: parameters.clone(), 498 substitution: parameters.clone(),
496 }; 499 };
497 500
498 projection_ty.hir_fmt(f)?; 501 projection_ty.hir_fmt(f)?;
@@ -579,7 +582,7 @@ impl HirDisplay for Ty {
579 let data = (*datas) 582 let data = (*datas)
580 .as_ref() 583 .as_ref()
581 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); 584 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
582 let bounds = data.subst(&opaque_ty.parameters); 585 let bounds = data.subst(&opaque_ty.substitution);
583 write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; 586 write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?;
584 } 587 }
585 ImplTraitId::AsyncBlockTypeImplTrait(..) => { 588 ImplTraitId::AsyncBlockTypeImplTrait(..) => {
@@ -709,7 +712,7 @@ fn write_bounds_like_dyn_trait(
709 angle_open = true; 712 angle_open = true;
710 } 713 }
711 let type_alias = f.db.type_alias_data(from_assoc_type_id( 714 let type_alias = f.db.type_alias_data(from_assoc_type_id(
712 projection_pred.projection_ty.associated_ty, 715 projection_pred.projection_ty.associated_ty_id,
713 )); 716 ));
714 write!(f, "{} = ", type_alias.name)?; 717 write!(f, "{} = ", type_alias.name)?;
715 projection_pred.ty.hir_fmt(f)?; 718 projection_pred.ty.hir_fmt(f)?;
@@ -782,7 +785,7 @@ impl HirDisplay for GenericPredicate {
782 f, 785 f,
783 ">::{} = ", 786 ">::{} = ",
784 f.db.type_alias_data(from_assoc_type_id( 787 f.db.type_alias_data(from_assoc_type_id(
785 projection_pred.projection_ty.associated_ty 788 projection_pred.projection_ty.associated_ty_id
786 )) 789 ))
787 .name, 790 .name,
788 )?; 791 )?;
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index 8cf59821f..fbfedb4e6 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -385,8 +385,8 @@ impl<'a> InferenceContext<'a> {
385 let projection = ProjectionPredicate { 385 let projection = ProjectionPredicate {
386 ty: ty.clone(), 386 ty: ty.clone(),
387 projection_ty: ProjectionTy { 387 projection_ty: ProjectionTy {
388 associated_ty: to_assoc_type_id(res_assoc_ty), 388 associated_ty_id: to_assoc_type_id(res_assoc_ty),
389 parameters: substs, 389 substitution: substs,
390 }, 390 },
391 }; 391 };
392 self.obligations.push(Obligation::Trait(trait_ref)); 392 self.obligations.push(Obligation::Trait(trait_ref));
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index eee3e6ec5..55163c963 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -99,8 +99,8 @@ impl<'a> InferenceContext<'a> {
99 if self.db.trait_solve(krate, goal.value).is_some() { 99 if self.db.trait_solve(krate, goal.value).is_some() {
100 self.obligations.push(implements_fn_trait); 100 self.obligations.push(implements_fn_trait);
101 let output_proj_ty = crate::ProjectionTy { 101 let output_proj_ty = crate::ProjectionTy {
102 associated_ty: to_assoc_type_id(output_assoc_type), 102 associated_ty_id: to_assoc_type_id(output_assoc_type),
103 parameters: substs, 103 substitution: substs,
104 }; 104 };
105 let return_ty = self.normalize_projection_ty(output_proj_ty); 105 let return_ty = self.normalize_projection_ty(output_proj_ty);
106 Some((arg_tys, return_ty)) 106 Some((arg_tys, return_ty))
@@ -261,7 +261,7 @@ impl<'a> InferenceContext<'a> {
261 sig_tys.push(ret_ty.clone()); 261 sig_tys.push(ret_ty.clone());
262 let sig_ty = TyKind::Function(FnPointer { 262 let sig_ty = TyKind::Function(FnPointer {
263 num_args: sig_tys.len() - 1, 263 num_args: sig_tys.len() - 1,
264 sig: FnSig { variadic: false }, 264 sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false },
265 substs: Substs(sig_tys.clone().into()), 265 substs: Substs(sig_tys.clone().into()),
266 }) 266 })
267 .intern(&Interner); 267 .intern(&Interner);
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 16d89ed1b..ebc612ca9 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -381,11 +381,11 @@ impl InferenceTable {
381 self.unify_substs(&tr1.substs, &tr2.substs, depth + 1) 381 self.unify_substs(&tr1.substs, &tr2.substs, depth + 1)
382 } 382 }
383 (GenericPredicate::Projection(proj1), GenericPredicate::Projection(proj2)) 383 (GenericPredicate::Projection(proj1), GenericPredicate::Projection(proj2))
384 if proj1.projection_ty.associated_ty == proj2.projection_ty.associated_ty => 384 if proj1.projection_ty.associated_ty_id == proj2.projection_ty.associated_ty_id =>
385 { 385 {
386 self.unify_substs( 386 self.unify_substs(
387 &proj1.projection_ty.parameters, 387 &proj1.projection_ty.substitution,
388 &proj2.projection_ty.parameters, 388 &proj2.projection_ty.substitution,
389 depth + 1, 389 depth + 1,
390 ) && self.unify_inner(&proj1.ty, &proj2.ty, depth + 1) 390 ) && self.unify_inner(&proj1.ty, &proj2.ty, depth + 1)
391 } 391 }
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index d6ff968f0..484652073 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -46,7 +46,7 @@ pub use lower::{
46}; 46};
47pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; 47pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
48 48
49pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariableKind}; 49pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind};
50 50
51pub use crate::traits::chalk::Interner; 51pub use crate::traits::chalk::Interner;
52 52
@@ -66,7 +66,7 @@ pub enum Lifetime {
66#[derive(Clone, PartialEq, Eq, Debug, Hash)] 66#[derive(Clone, PartialEq, Eq, Debug, Hash)]
67pub struct OpaqueTy { 67pub struct OpaqueTy {
68 pub opaque_ty_id: OpaqueTyId, 68 pub opaque_ty_id: OpaqueTyId,
69 pub parameters: Substs, 69 pub substitution: Substs,
70} 70}
71 71
72/// A "projection" type corresponds to an (unnormalized) 72/// A "projection" type corresponds to an (unnormalized)
@@ -74,17 +74,17 @@ pub struct OpaqueTy {
74/// trait and all its parameters are fully known. 74/// trait and all its parameters are fully known.
75#[derive(Clone, PartialEq, Eq, Debug, Hash)] 75#[derive(Clone, PartialEq, Eq, Debug, Hash)]
76pub struct ProjectionTy { 76pub struct ProjectionTy {
77 pub associated_ty: AssocTypeId, 77 pub associated_ty_id: AssocTypeId,
78 pub parameters: Substs, 78 pub substitution: Substs,
79} 79}
80 80
81impl ProjectionTy { 81impl ProjectionTy {
82 pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef { 82 pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef {
83 TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } 83 TraitRef { trait_: self.trait_(db), substs: self.substitution.clone() }
84 } 84 }
85 85
86 fn trait_(&self, db: &dyn HirDatabase) -> TraitId { 86 fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
87 match from_assoc_type_id(self.associated_ty).lookup(db.upcast()).container { 87 match from_assoc_type_id(self.associated_ty_id).lookup(db.upcast()).container {
88 AssocContainerId::TraitId(it) => it, 88 AssocContainerId::TraitId(it) => it,
89 _ => panic!("projection ty without parent trait"), 89 _ => panic!("projection ty without parent trait"),
90 } 90 }
@@ -93,7 +93,7 @@ impl ProjectionTy {
93 93
94impl TypeWalk for ProjectionTy { 94impl TypeWalk for ProjectionTy {
95 fn walk(&self, f: &mut impl FnMut(&Ty)) { 95 fn walk(&self, f: &mut impl FnMut(&Ty)) {
96 self.parameters.walk(f); 96 self.substitution.walk(f);
97 } 97 }
98 98
99 fn walk_mut_binders( 99 fn walk_mut_binders(
@@ -101,14 +101,11 @@ impl TypeWalk for ProjectionTy {
101 f: &mut impl FnMut(&mut Ty, DebruijnIndex), 101 f: &mut impl FnMut(&mut Ty, DebruijnIndex),
102 binders: DebruijnIndex, 102 binders: DebruijnIndex,
103 ) { 103 ) {
104 self.parameters.walk_mut_binders(f, binders); 104 self.substitution.walk_mut_binders(f, binders);
105 } 105 }
106} 106}
107 107
108#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] 108pub type FnSig = chalk_ir::FnSig<Interner>;
109pub struct FnSig {
110 pub variadic: bool,
111}
112 109
113#[derive(Clone, PartialEq, Eq, Debug, Hash)] 110#[derive(Clone, PartialEq, Eq, Debug, Hash)]
114pub struct FnPointer { 111pub struct FnPointer {
@@ -643,7 +640,7 @@ impl Ty {
643 pub fn fn_ptr(sig: CallableSig) -> Self { 640 pub fn fn_ptr(sig: CallableSig) -> Self {
644 TyKind::Function(FnPointer { 641 TyKind::Function(FnPointer {
645 num_args: sig.params().len(), 642 num_args: sig.params().len(),
646 sig: FnSig { variadic: sig.is_varargs }, 643 sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs },
647 substs: Substs(sig.params_and_return), 644 substs: Substs(sig.params_and_return),
648 }) 645 })
649 .intern(&Interner) 646 .intern(&Interner)
@@ -906,7 +903,7 @@ impl Ty {
906 let data = (*it) 903 let data = (*it)
907 .as_ref() 904 .as_ref()
908 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); 905 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
909 data.subst(&opaque_ty.parameters) 906 data.subst(&opaque_ty.substitution)
910 }) 907 })
911 } 908 }
912 // It always has an parameter for Future::Output type. 909 // It always has an parameter for Future::Output type.
@@ -945,7 +942,9 @@ impl Ty {
945 } 942 }
946 } 943 }
947 TyKind::Alias(AliasTy::Projection(projection_ty)) => { 944 TyKind::Alias(AliasTy::Projection(projection_ty)) => {
948 match from_assoc_type_id(projection_ty.associated_ty).lookup(db.upcast()).container 945 match from_assoc_type_id(projection_ty.associated_ty_id)
946 .lookup(db.upcast())
947 .container
949 { 948 {
950 AssocContainerId::TraitId(trait_id) => Some(trait_id), 949 AssocContainerId::TraitId(trait_id) => Some(trait_id),
951 _ => None, 950 _ => None,
@@ -1055,12 +1054,12 @@ impl TypeWalk for Ty {
1055 fn walk(&self, f: &mut impl FnMut(&Ty)) { 1054 fn walk(&self, f: &mut impl FnMut(&Ty)) {
1056 match self.interned(&Interner) { 1055 match self.interned(&Interner) {
1057 TyKind::Alias(AliasTy::Projection(p_ty)) => { 1056 TyKind::Alias(AliasTy::Projection(p_ty)) => {
1058 for t in p_ty.parameters.iter() { 1057 for t in p_ty.substitution.iter() {
1059 t.walk(f); 1058 t.walk(f);
1060 } 1059 }
1061 } 1060 }
1062 TyKind::Alias(AliasTy::Opaque(o_ty)) => { 1061 TyKind::Alias(AliasTy::Opaque(o_ty)) => {
1063 for t in o_ty.parameters.iter() { 1062 for t in o_ty.substitution.iter() {
1064 t.walk(f); 1063 t.walk(f);
1065 } 1064 }
1066 } 1065 }
@@ -1087,7 +1086,7 @@ impl TypeWalk for Ty {
1087 ) { 1086 ) {
1088 match &mut self.0 { 1087 match &mut self.0 {
1089 TyKind::Alias(AliasTy::Projection(p_ty)) => { 1088 TyKind::Alias(AliasTy::Projection(p_ty)) => {
1090 p_ty.parameters.walk_mut_binders(f, binders); 1089 p_ty.substitution.walk_mut_binders(f, binders);
1091 } 1090 }
1092 TyKind::Dyn(predicates) => { 1091 TyKind::Dyn(predicates) => {
1093 for p in make_mut_slice(predicates) { 1092 for p in make_mut_slice(predicates) {
@@ -1095,7 +1094,7 @@ impl TypeWalk for Ty {
1095 } 1094 }
1096 } 1095 }
1097 TyKind::Alias(AliasTy::Opaque(o_ty)) => { 1096 TyKind::Alias(AliasTy::Opaque(o_ty)) => {
1098 o_ty.parameters.walk_mut_binders(f, binders); 1097 o_ty.substitution.walk_mut_binders(f, binders);
1099 } 1098 }
1100 _ => { 1099 _ => {
1101 if let Some(substs) = self.substs_mut() { 1100 if let Some(substs) = self.substs_mut() {
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index c32dca9d7..d026310f4 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -8,7 +8,7 @@
8use std::{iter, sync::Arc}; 8use std::{iter, sync::Arc};
9 9
10use base_db::CrateId; 10use base_db::CrateId;
11use chalk_ir::{cast::Cast, Mutability}; 11use chalk_ir::{cast::Cast, Mutability, Safety};
12use hir_def::{ 12use hir_def::{
13 adt::StructKind, 13 adt::StructKind,
14 builtin_type::BuiltinType, 14 builtin_type::BuiltinType,
@@ -181,7 +181,7 @@ impl<'a> TyLoweringContext<'a> {
181 let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect()); 181 let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect());
182 TyKind::Function(FnPointer { 182 TyKind::Function(FnPointer {
183 num_args: substs.len() - 1, 183 num_args: substs.len() - 1,
184 sig: FnSig { variadic: *is_varargs }, 184 sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs },
185 substs, 185 substs,
186 }) 186 })
187 .intern(&Interner) 187 .intern(&Interner)
@@ -230,8 +230,11 @@ impl<'a> TyLoweringContext<'a> {
230 let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); 230 let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into();
231 let generics = generics(self.db.upcast(), func.into()); 231 let generics = generics(self.db.upcast(), func.into());
232 let parameters = Substs::bound_vars(&generics, self.in_binders); 232 let parameters = Substs::bound_vars(&generics, self.in_binders);
233 TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) 233 TyKind::Alias(AliasTy::Opaque(OpaqueTy {
234 .intern(&Interner) 234 opaque_ty_id,
235 substitution: parameters,
236 }))
237 .intern(&Interner)
235 } 238 }
236 ImplTraitLoweringMode::Param => { 239 ImplTraitLoweringMode::Param => {
237 let idx = self.impl_trait_counter.get(); 240 let idx = self.impl_trait_counter.get();
@@ -357,8 +360,8 @@ impl<'a> TyLoweringContext<'a> {
357 Some((super_trait_ref, associated_ty)) => { 360 Some((super_trait_ref, associated_ty)) => {
358 // FIXME handle type parameters on the segment 361 // FIXME handle type parameters on the segment
359 TyKind::Alias(AliasTy::Projection(ProjectionTy { 362 TyKind::Alias(AliasTy::Projection(ProjectionTy {
360 associated_ty: to_assoc_type_id(associated_ty), 363 associated_ty_id: to_assoc_type_id(associated_ty),
361 parameters: super_trait_ref.substs, 364 substitution: super_trait_ref.substs,
362 })) 365 }))
363 .intern(&Interner) 366 .intern(&Interner)
364 } 367 }
@@ -478,8 +481,8 @@ impl<'a> TyLoweringContext<'a> {
478 // FIXME handle type parameters on the segment 481 // FIXME handle type parameters on the segment
479 return Some( 482 return Some(
480 TyKind::Alias(AliasTy::Projection(ProjectionTy { 483 TyKind::Alias(AliasTy::Projection(ProjectionTy {
481 associated_ty: to_assoc_type_id(associated_ty), 484 associated_ty_id: to_assoc_type_id(associated_ty),
482 parameters: substs, 485 substitution: substs,
483 })) 486 }))
484 .intern(&Interner), 487 .intern(&Interner),
485 ); 488 );
@@ -736,8 +739,8 @@ impl<'a> TyLoweringContext<'a> {
736 Some(t) => t, 739 Some(t) => t,
737 }; 740 };
738 let projection_ty = ProjectionTy { 741 let projection_ty = ProjectionTy {
739 associated_ty: to_assoc_type_id(associated_ty), 742 associated_ty_id: to_assoc_type_id(associated_ty),
740 parameters: super_trait_ref.substs, 743 substitution: super_trait_ref.substs,
741 }; 744 };
742 let mut preds = SmallVec::with_capacity( 745 let mut preds = SmallVec::with_capacity(
743 binding.type_ref.as_ref().map_or(0, |_| 1) + binding.bounds.len(), 746 binding.type_ref.as_ref().map_or(0, |_| 1) + binding.bounds.len(),
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs
index edfafdff8..a6a63c673 100644
--- a/crates/hir_ty/src/traits.rs
+++ b/crates/hir_ty/src/traits.rs
@@ -143,7 +143,7 @@ pub(crate) fn trait_solve_query(
143 log::info!("trait_solve_query({})", goal.value.value.display(db)); 143 log::info!("trait_solve_query({})", goal.value.value.display(db));
144 144
145 if let Obligation::Projection(pred) = &goal.value.value { 145 if let Obligation::Projection(pred) = &goal.value.value {
146 if let TyKind::BoundVar(_) = &pred.projection_ty.parameters[0].interned(&Interner) { 146 if let TyKind::BoundVar(_) = &pred.projection_ty.substitution[0].interned(&Interner) {
147 // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible 147 // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
148 return Some(Solution::Ambig(Guidance::Unknown)); 148 return Some(Solution::Ambig(Guidance::Unknown));
149 } 149 }
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index ef1e6b2df..232cf9cd0 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -234,9 +234,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
234 ty: TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }) 234 ty: TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 })
235 .intern(&Interner), 235 .intern(&Interner),
236 projection_ty: ProjectionTy { 236 projection_ty: ProjectionTy {
237 associated_ty: to_assoc_type_id(future_output), 237 associated_ty_id: to_assoc_type_id(future_output),
238 // Self type as the first parameter. 238 // Self type as the first parameter.
239 parameters: Substs::single( 239 substitution: Substs::single(
240 TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) 240 TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
241 .intern(&Interner), 241 .intern(&Interner),
242 ), 242 ),
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 2a66a2310..05a4bf0df 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -14,7 +14,7 @@ use crate::{
14 from_assoc_type_id, 14 from_assoc_type_id,
15 primitive::UintTy, 15 primitive::UintTy,
16 traits::{Canonical, Obligation}, 16 traits::{Canonical, Obligation},
17 AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, 17 AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy,
18 ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, 18 ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty,
19}; 19};
20 20
@@ -27,11 +27,11 @@ impl ToChalk for Ty {
27 match self.0 { 27 match self.0 {
28 TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters), 28 TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters),
29 TyKind::Array(parameters) => array_to_chalk(db, parameters), 29 TyKind::Array(parameters) => array_to_chalk(db, parameters),
30 TyKind::Function(FnPointer { sig: FnSig { variadic }, 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 {
33 num_binders: 0, 33 num_binders: 0,
34 sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic }, 34 sig,
35 substitution, 35 substitution,
36 }) 36 })
37 .intern(&Interner) 37 .intern(&Interner)
@@ -78,8 +78,8 @@ impl ToChalk for Ty {
78 chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) 78 chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner)
79 } 79 }
80 TyKind::Alias(AliasTy::Projection(proj_ty)) => { 80 TyKind::Alias(AliasTy::Projection(proj_ty)) => {
81 let associated_ty_id = proj_ty.associated_ty; 81 let associated_ty_id = proj_ty.associated_ty_id;
82 let substitution = proj_ty.parameters.to_chalk(db); 82 let substitution = proj_ty.substitution.to_chalk(db);
83 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { 83 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
84 associated_ty_id, 84 associated_ty_id,
85 substitution, 85 substitution,
@@ -87,6 +87,13 @@ impl ToChalk for Ty {
87 .cast(&Interner) 87 .cast(&Interner)
88 .intern(&Interner) 88 .intern(&Interner)
89 } 89 }
90 TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
91 let opaque_ty_id = opaque_ty.opaque_ty_id;
92 let substitution = opaque_ty.substitution.to_chalk(db);
93 chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id, substitution })
94 .cast(&Interner)
95 .intern(&Interner)
96 }
90 TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner), 97 TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner),
91 TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), 98 TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner),
92 TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), 99 TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"),
@@ -101,15 +108,6 @@ impl ToChalk for Ty {
101 }; 108 };
102 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) 109 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
103 } 110 }
104 TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
105 let opaque_ty_id = opaque_ty.opaque_ty_id;
106 let substitution = opaque_ty.parameters.to_chalk(db);
107 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
108 opaque_ty_id,
109 substitution,
110 }))
111 .intern(&Interner)
112 }
113 TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner), 111 TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner),
114 } 112 }
115 } 113 }
@@ -121,16 +119,19 @@ impl ToChalk for Ty {
121 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { 119 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
122 let associated_ty = proj.associated_ty_id; 120 let associated_ty = proj.associated_ty_id;
123 let parameters = from_chalk(db, proj.substitution); 121 let parameters = from_chalk(db, proj.substitution);
124 TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) 122 TyKind::Alias(AliasTy::Projection(ProjectionTy {
123 associated_ty_id: associated_ty,
124 substitution: parameters,
125 }))
125 } 126 }
126 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { 127 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => {
127 let opaque_ty_id = opaque_ty.opaque_ty_id; 128 let opaque_ty_id = opaque_ty.opaque_ty_id;
128 let parameters = from_chalk(db, opaque_ty.substitution); 129 let parameters = from_chalk(db, opaque_ty.substitution);
129 TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) 130 TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, substitution: parameters }))
130 } 131 }
131 chalk_ir::TyKind::Function(chalk_ir::FnPointer { 132 chalk_ir::TyKind::Function(chalk_ir::FnPointer {
132 num_binders, 133 num_binders,
133 sig: chalk_ir::FnSig { variadic, .. }, 134 sig,
134 substitution, 135 substitution,
135 .. 136 ..
136 }) => { 137 }) => {
@@ -139,11 +140,7 @@ impl ToChalk for Ty {
139 db, 140 db,
140 substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), 141 substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"),
141 ); 142 );
142 TyKind::Function(FnPointer { 143 TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs })
143 num_args: (substs.len() - 1),
144 sig: FnSig { variadic },
145 substs,
146 })
147 } 144 }
148 chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), 145 chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx),
149 chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, 146 chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown,
@@ -372,8 +369,8 @@ impl ToChalk for ProjectionTy {
372 369
373 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { 370 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
374 chalk_ir::ProjectionTy { 371 chalk_ir::ProjectionTy {
375 associated_ty_id: self.associated_ty, 372 associated_ty_id: self.associated_ty_id,
376 substitution: self.parameters.to_chalk(db), 373 substitution: self.substitution.to_chalk(db),
377 } 374 }
378 } 375 }
379 376
@@ -382,8 +379,8 @@ impl ToChalk for ProjectionTy {
382 projection_ty: chalk_ir::ProjectionTy<Interner>, 379 projection_ty: chalk_ir::ProjectionTy<Interner>,
383 ) -> ProjectionTy { 380 ) -> ProjectionTy {
384 ProjectionTy { 381 ProjectionTy {
385 associated_ty: projection_ty.associated_ty_id, 382 associated_ty_id: projection_ty.associated_ty_id,
386 parameters: from_chalk(db, projection_ty.substitution), 383 substitution: from_chalk(db, projection_ty.substitution),
387 } 384 }
388 } 385 }
389} 386}
@@ -533,24 +530,24 @@ pub(super) fn generic_predicate_to_inline_bound(
533 Some(rust_ir::InlineBound::TraitBound(trait_bound)) 530 Some(rust_ir::InlineBound::TraitBound(trait_bound))
534 } 531 }
535 GenericPredicate::Projection(proj) => { 532 GenericPredicate::Projection(proj) => {
536 if &proj.projection_ty.parameters[0] != self_ty { 533 if &proj.projection_ty.substitution[0] != self_ty {
537 return None; 534 return None;
538 } 535 }
539 let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty) 536 let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty_id)
540 .lookup(db.upcast()) 537 .lookup(db.upcast())
541 .container 538 .container
542 { 539 {
543 AssocContainerId::TraitId(t) => t, 540 AssocContainerId::TraitId(t) => t,
544 _ => panic!("associated type not in trait"), 541 _ => panic!("associated type not in trait"),
545 }; 542 };
546 let args_no_self = proj.projection_ty.parameters[1..] 543 let args_no_self = proj.projection_ty.substitution[1..]
547 .iter() 544 .iter()
548 .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) 545 .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
549 .collect(); 546 .collect();
550 let alias_eq_bound = rust_ir::AliasEqBound { 547 let alias_eq_bound = rust_ir::AliasEqBound {
551 value: proj.ty.clone().to_chalk(db), 548 value: proj.ty.clone().to_chalk(db),
552 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, 549 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
553 associated_ty_id: proj.projection_ty.associated_ty, 550 associated_ty_id: proj.projection_ty.associated_ty_id,
554 parameters: Vec::new(), // FIXME we don't support generic associated types yet 551 parameters: Vec::new(), // FIXME we don't support generic associated types yet
555 }; 552 };
556 Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) 553 Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound))