aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits/chalk/mapping.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits/chalk/mapping.rs')
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs57
1 files changed, 27 insertions, 30 deletions
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))