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