diff options
author | Florian Diebold <[email protected]> | 2021-03-13 19:05:47 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-03-13 19:05:47 +0000 |
commit | b035c314b4b0ecd2477fde216dbe7e8801f94d0d (patch) | |
tree | a2e152f5f16dd92f4c4be011be2399998dc7eb6f /crates | |
parent | 1bf6b7360c3f1d0e20dece5227979bc4d74a352f (diff) |
Use chalk_ir::OpaqueTyId
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/db.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 42 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 7 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 16 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 12 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 7 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 28 |
7 files changed, 53 insertions, 63 deletions
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index c198f6903..8a3cc0283 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs | |||
@@ -12,7 +12,7 @@ use la_arena::ArenaMap; | |||
12 | use crate::{ | 12 | use crate::{ |
13 | method_resolution::{InherentImpls, TraitImpls}, | 13 | method_resolution::{InherentImpls, TraitImpls}, |
14 | traits::chalk, | 14 | traits::chalk, |
15 | Binders, CallableDefId, FnDefId, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, | 15 | Binders, CallableDefId, FnDefId, GenericPredicate, ImplTraitId, InferenceResult, PolyFnSig, |
16 | ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, | 16 | ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, |
17 | }; | 17 | }; |
18 | use hir_expand::name::Name; | 18 | use hir_expand::name::Name; |
@@ -83,7 +83,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> { | |||
83 | #[salsa::interned] | 83 | #[salsa::interned] |
84 | fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId; | 84 | fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId; |
85 | #[salsa::interned] | 85 | #[salsa::interned] |
86 | fn intern_impl_trait_id(&self, id: OpaqueTyId) -> InternedOpaqueTyId; | 86 | fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId; |
87 | #[salsa::interned] | 87 | #[salsa::interned] |
88 | fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId; | 88 | fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId; |
89 | 89 | ||
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 0a13c8636..e6473586b 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -13,7 +13,7 @@ use hir_expand::name::Name; | |||
13 | use crate::{ | 13 | use crate::{ |
14 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, | 14 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, |
15 | to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, | 15 | to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, |
16 | CallableSig, GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, OpaqueTyId, | 16 | CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy, |
17 | ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind, | 17 | ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind, |
18 | }; | 18 | }; |
19 | 19 | ||
@@ -313,22 +313,26 @@ impl HirDisplay for Ty { | |||
313 | )?; | 313 | )?; |
314 | } | 314 | } |
315 | 315 | ||
316 | // FIXME: all this just to decide whether to use parentheses... | ||
316 | let datas; | 317 | let datas; |
317 | let predicates = match t.interned(&Interner) { | 318 | let predicates = match t.interned(&Interner) { |
318 | TyKind::Dyn(predicates) if predicates.len() > 1 => { | 319 | TyKind::Dyn(predicates) if predicates.len() > 1 => { |
319 | Cow::Borrowed(predicates.as_ref()) | 320 | Cow::Borrowed(predicates.as_ref()) |
320 | } | 321 | } |
321 | &TyKind::Alias(AliasTy::Opaque(OpaqueTy { | 322 | &TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, ref parameters })) => { |
322 | opaque_ty_id: OpaqueTyId::ReturnTypeImplTrait(func, idx), | 323 | let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into()); |
323 | ref parameters, | 324 | if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id { |
324 | })) => { | 325 | datas = |
325 | datas = | 326 | f.db.return_type_impl_traits(func) |
326 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); | 327 | .expect("impl trait id without data"); |
327 | let data = (*datas) | 328 | let data = (*datas) |
328 | .as_ref() | 329 | .as_ref() |
329 | .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); | 330 | .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); |
330 | let bounds = data.subst(parameters); | 331 | let bounds = data.subst(parameters); |
331 | Cow::Owned(bounds.value) | 332 | Cow::Owned(bounds.value) |
333 | } else { | ||
334 | Cow::Borrowed(&[][..]) | ||
335 | } | ||
332 | } | 336 | } |
333 | _ => Cow::Borrowed(&[][..]), | 337 | _ => Cow::Borrowed(&[][..]), |
334 | }; | 338 | }; |
@@ -499,8 +503,9 @@ impl HirDisplay for Ty { | |||
499 | write!(f, "{}", type_alias.name)?; | 503 | write!(f, "{}", type_alias.name)?; |
500 | } | 504 | } |
501 | TyKind::OpaqueType(opaque_ty_id, parameters) => { | 505 | TyKind::OpaqueType(opaque_ty_id, parameters) => { |
502 | match opaque_ty_id { | 506 | let impl_trait_id = f.db.lookup_intern_impl_trait_id((*opaque_ty_id).into()); |
503 | &OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 507 | match impl_trait_id { |
508 | ImplTraitId::ReturnTypeImplTrait(func, idx) => { | ||
504 | let datas = | 509 | let datas = |
505 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); | 510 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); |
506 | let data = (*datas) | 511 | let data = (*datas) |
@@ -510,7 +515,7 @@ impl HirDisplay for Ty { | |||
510 | write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; | 515 | write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; |
511 | // FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution | 516 | // FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution |
512 | } | 517 | } |
513 | OpaqueTyId::AsyncBlockTypeImplTrait(..) => { | 518 | ImplTraitId::AsyncBlockTypeImplTrait(..) => { |
514 | write!(f, "impl Future<Output = ")?; | 519 | write!(f, "impl Future<Output = ")?; |
515 | parameters[0].hir_fmt(f)?; | 520 | parameters[0].hir_fmt(f)?; |
516 | write!(f, ">")?; | 521 | write!(f, ">")?; |
@@ -566,8 +571,9 @@ impl HirDisplay for Ty { | |||
566 | } | 571 | } |
567 | TyKind::Alias(AliasTy::Projection(p_ty)) => p_ty.hir_fmt(f)?, | 572 | TyKind::Alias(AliasTy::Projection(p_ty)) => p_ty.hir_fmt(f)?, |
568 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { | 573 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
569 | match opaque_ty.opaque_ty_id { | 574 | let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty.opaque_ty_id.into()); |
570 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 575 | match impl_trait_id { |
576 | ImplTraitId::ReturnTypeImplTrait(func, idx) => { | ||
571 | let datas = | 577 | let datas = |
572 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); | 578 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); |
573 | let data = (*datas) | 579 | let data = (*datas) |
@@ -576,7 +582,7 @@ impl HirDisplay for Ty { | |||
576 | let bounds = data.subst(&opaque_ty.parameters); | 582 | let bounds = data.subst(&opaque_ty.parameters); |
577 | write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; | 583 | write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; |
578 | } | 584 | } |
579 | OpaqueTyId::AsyncBlockTypeImplTrait(..) => { | 585 | ImplTraitId::AsyncBlockTypeImplTrait(..) => { |
580 | write!(f, "{{async block}}")?; | 586 | write!(f, "{{async block}}")?; |
581 | } | 587 | } |
582 | }; | 588 | }; |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 2e21d796c..eee3e6ec5 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -21,8 +21,8 @@ use crate::{ | |||
21 | to_assoc_type_id, | 21 | to_assoc_type_id, |
22 | traits::{chalk::from_chalk, FnTrait, InEnvironment}, | 22 | traits::{chalk::from_chalk, FnTrait, InEnvironment}, |
23 | utils::{generics, variant_data, Generics}, | 23 | utils::{generics, variant_data, Generics}, |
24 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, OpaqueTyId, Rawness, | 24 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, Substs, |
25 | Scalar, Substs, TraitRef, Ty, TyKind, | 25 | TraitRef, Ty, TyKind, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | use super::{ | 28 | use super::{ |
@@ -179,7 +179,8 @@ impl<'a> InferenceContext<'a> { | |||
179 | // Use the first type parameter as the output type of future. | 179 | // Use the first type parameter as the output type of future. |
180 | // existenail type AsyncBlockImplTrait<InnerType>: Future<Output = InnerType> | 180 | // existenail type AsyncBlockImplTrait<InnerType>: Future<Output = InnerType> |
181 | let inner_ty = self.infer_expr(*body, &Expectation::none()); | 181 | let inner_ty = self.infer_expr(*body, &Expectation::none()); |
182 | let opaque_ty_id = OpaqueTyId::AsyncBlockTypeImplTrait(self.owner, *body); | 182 | let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body); |
183 | let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); | ||
183 | TyKind::OpaqueType(opaque_ty_id, Substs::single(inner_ty)).intern(&Interner) | 184 | TyKind::OpaqueType(opaque_ty_id, Substs::single(inner_ty)).intern(&Interner) |
184 | } | 185 | } |
185 | Expr::Loop { body, label } => { | 186 | Expr::Loop { body, label } => { |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index d1c018283..d6ff968f0 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -54,6 +54,7 @@ pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | |||
54 | pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | 54 | pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; |
55 | pub type FnDefId = chalk_ir::FnDefId<Interner>; | 55 | pub type FnDefId = chalk_ir::FnDefId<Interner>; |
56 | pub type ClosureId = chalk_ir::ClosureId<Interner>; | 56 | pub type ClosureId = chalk_ir::ClosureId<Interner>; |
57 | pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; | ||
57 | pub type PlaceholderIndex = chalk_ir::PlaceholderIndex; | 58 | pub type PlaceholderIndex = chalk_ir::PlaceholderIndex; |
58 | 59 | ||
59 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 60 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
@@ -875,8 +876,8 @@ impl Ty { | |||
875 | pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<GenericPredicate>> { | 876 | pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<GenericPredicate>> { |
876 | match self.interned(&Interner) { | 877 | match self.interned(&Interner) { |
877 | TyKind::OpaqueType(opaque_ty_id, ..) => { | 878 | TyKind::OpaqueType(opaque_ty_id, ..) => { |
878 | match opaque_ty_id { | 879 | match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) { |
879 | OpaqueTyId::AsyncBlockTypeImplTrait(def, _expr) => { | 880 | ImplTraitId::AsyncBlockTypeImplTrait(def, _expr) => { |
880 | let krate = def.module(db.upcast()).krate(); | 881 | let krate = def.module(db.upcast()).krate(); |
881 | if let Some(future_trait) = db | 882 | if let Some(future_trait) = db |
882 | .lang_item(krate, "future_trait".into()) | 883 | .lang_item(krate, "future_trait".into()) |
@@ -894,12 +895,13 @@ impl Ty { | |||
894 | None | 895 | None |
895 | } | 896 | } |
896 | } | 897 | } |
897 | OpaqueTyId::ReturnTypeImplTrait(..) => None, | 898 | ImplTraitId::ReturnTypeImplTrait(..) => None, |
898 | } | 899 | } |
899 | } | 900 | } |
900 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { | 901 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
901 | let predicates = match opaque_ty.opaque_ty_id { | 902 | let predicates = match db.lookup_intern_impl_trait_id(opaque_ty.opaque_ty_id.into()) |
902 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 903 | { |
904 | ImplTraitId::ReturnTypeImplTrait(func, idx) => { | ||
903 | db.return_type_impl_traits(func).map(|it| { | 905 | db.return_type_impl_traits(func).map(|it| { |
904 | let data = (*it) | 906 | let data = (*it) |
905 | .as_ref() | 907 | .as_ref() |
@@ -908,7 +910,7 @@ impl Ty { | |||
908 | }) | 910 | }) |
909 | } | 911 | } |
910 | // It always has an parameter for Future::Output type. | 912 | // It always has an parameter for Future::Output type. |
911 | OpaqueTyId::AsyncBlockTypeImplTrait(..) => unreachable!(), | 913 | ImplTraitId::AsyncBlockTypeImplTrait(..) => unreachable!(), |
912 | }; | 914 | }; |
913 | 915 | ||
914 | predicates.map(|it| it.value) | 916 | predicates.map(|it| it.value) |
@@ -1123,7 +1125,7 @@ impl<T: TypeWalk> TypeWalk for Vec<T> { | |||
1123 | } | 1125 | } |
1124 | 1126 | ||
1125 | #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] | 1127 | #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] |
1126 | pub enum OpaqueTyId { | 1128 | pub enum ImplTraitId { |
1127 | ReturnTypeImplTrait(hir_def::FunctionId, u16), | 1129 | ReturnTypeImplTrait(hir_def::FunctionId, u16), |
1128 | AsyncBlockTypeImplTrait(hir_def::DefWithBodyId, ExprId), | 1130 | AsyncBlockTypeImplTrait(hir_def::DefWithBodyId, ExprId), |
1129 | } | 1131 | } |
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 78a914cac..e57d5970f 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -34,7 +34,7 @@ use crate::{ | |||
34 | make_mut_slice, variant_data, | 34 | make_mut_slice, variant_data, |
35 | }, | 35 | }, |
36 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, | 36 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, |
37 | OpaqueTy, OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, | 37 | ImplTraitId, OpaqueTy, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, |
38 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, | 38 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, |
39 | }; | 39 | }; |
40 | 40 | ||
@@ -228,14 +228,12 @@ impl Ty { | |||
228 | Some(GenericDefId::FunctionId(f)) => f, | 228 | Some(GenericDefId::FunctionId(f)) => f, |
229 | _ => panic!("opaque impl trait lowering in non-function"), | 229 | _ => panic!("opaque impl trait lowering in non-function"), |
230 | }; | 230 | }; |
231 | let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); | 231 | let impl_trait_id = ImplTraitId::ReturnTypeImplTrait(func, idx); |
232 | let opaque_ty_id = ctx.db.intern_impl_trait_id(impl_trait_id).into(); | ||
232 | let generics = generics(ctx.db.upcast(), func.into()); | 233 | let generics = generics(ctx.db.upcast(), func.into()); |
233 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); | 234 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); |
234 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { | 235 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) |
235 | opaque_ty_id: impl_trait_id, | 236 | .intern(&Interner) |
236 | parameters, | ||
237 | })) | ||
238 | .intern(&Interner) | ||
239 | } | 237 | } |
240 | ImplTraitLoweringMode::Param => { | 238 | ImplTraitLoweringMode::Param => { |
241 | let idx = ctx.impl_trait_counter.get(); | 239 | let idx = ctx.impl_trait_counter.get(); |
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index e7217bc11..1f3e1c07a 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -177,10 +177,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
177 | } | 177 | } |
178 | 178 | ||
179 | fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> { | 179 | fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> { |
180 | let interned_id = crate::db::InternedOpaqueTyId::from(id); | 180 | let full_id = self.db.lookup_intern_impl_trait_id(id.into()); |
181 | let full_id = self.db.lookup_intern_impl_trait_id(interned_id); | ||
182 | let bound = match full_id { | 181 | let bound = match full_id { |
183 | crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 182 | crate::ImplTraitId::ReturnTypeImplTrait(func, idx) => { |
184 | let datas = self | 183 | let datas = self |
185 | .db | 184 | .db |
186 | .return_type_impl_traits(func) | 185 | .return_type_impl_traits(func) |
@@ -202,7 +201,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
202 | let num_vars = datas.num_binders; | 201 | let num_vars = datas.num_binders; |
203 | make_binders(bound, num_vars) | 202 | make_binders(bound, num_vars) |
204 | } | 203 | } |
205 | crate::OpaqueTyId::AsyncBlockTypeImplTrait(..) => { | 204 | crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => { |
206 | if let Some((future_trait, future_output)) = self | 205 | if let Some((future_trait, future_output)) = self |
207 | .db | 206 | .db |
208 | .lang_item(self.krate, "future_trait".into()) | 207 | .lang_item(self.krate, "future_trait".into()) |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 460955756..2a66a2310 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -15,7 +15,7 @@ use crate::{ | |||
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, FnSig, GenericPredicate, InEnvironment, OpaqueTy, |
18 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, | 18 | ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | use super::interner::*; | 21 | use super::interner::*; |
@@ -41,8 +41,7 @@ impl ToChalk for Ty { | |||
41 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) | 41 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) |
42 | } | 42 | } |
43 | 43 | ||
44 | TyKind::OpaqueType(impl_trait_id, substs) => { | 44 | TyKind::OpaqueType(id, substs) => { |
45 | let id = impl_trait_id.to_chalk(db); | ||
46 | let substitution = substs.to_chalk(db); | 45 | let substitution = substs.to_chalk(db); |
47 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) | 46 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) |
48 | } | 47 | } |
@@ -103,7 +102,7 @@ impl ToChalk for Ty { | |||
103 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) | 102 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
104 | } | 103 | } |
105 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { | 104 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
106 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); | 105 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
107 | let substitution = opaque_ty.parameters.to_chalk(db); | 106 | let substitution = opaque_ty.parameters.to_chalk(db); |
108 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | 107 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { |
109 | opaque_ty_id, | 108 | opaque_ty_id, |
@@ -125,9 +124,9 @@ impl ToChalk for Ty { | |||
125 | TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) | 124 | TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) |
126 | } | 125 | } |
127 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { | 126 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { |
128 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); | 127 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
129 | let parameters = from_chalk(db, opaque_ty.substitution); | 128 | let parameters = from_chalk(db, opaque_ty.substitution); |
130 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })) | 129 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) |
131 | } | 130 | } |
132 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 131 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
133 | num_binders, | 132 | num_binders, |
@@ -165,7 +164,7 @@ impl ToChalk for Ty { | |||
165 | } | 164 | } |
166 | 165 | ||
167 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { | 166 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { |
168 | TyKind::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) | 167 | TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst)) |
169 | } | 168 | } |
170 | 169 | ||
171 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), | 170 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), |
@@ -268,21 +267,6 @@ impl ToChalk for hir_def::TraitId { | |||
268 | } | 267 | } |
269 | } | 268 | } |
270 | 269 | ||
271 | impl ToChalk for OpaqueTyId { | ||
272 | type Chalk = chalk_ir::OpaqueTyId<Interner>; | ||
273 | |||
274 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::OpaqueTyId<Interner> { | ||
275 | db.intern_impl_trait_id(self).into() | ||
276 | } | ||
277 | |||
278 | fn from_chalk( | ||
279 | db: &dyn HirDatabase, | ||
280 | opaque_ty_id: chalk_ir::OpaqueTyId<Interner>, | ||
281 | ) -> OpaqueTyId { | ||
282 | db.lookup_intern_impl_trait_id(opaque_ty_id.into()) | ||
283 | } | ||
284 | } | ||
285 | |||
286 | impl ToChalk for hir_def::ImplId { | 270 | impl ToChalk for hir_def::ImplId { |
287 | type Chalk = ImplId; | 271 | type Chalk = ImplId; |
288 | 272 | ||