diff options
Diffstat (limited to 'crates/ra_hir_ty/src/traits')
-rw-r--r-- | crates/ra_hir_ty/src/traits/builtin.rs | 53 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 153 |
2 files changed, 152 insertions, 54 deletions
diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index 73e3c5c78..ccab246bf 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs | |||
@@ -8,7 +8,8 @@ use super::{AssocTyValue, Impl, UnsizeToSuperTraitObjectData}; | |||
8 | use crate::{ | 8 | use crate::{ |
9 | db::HirDatabase, | 9 | db::HirDatabase, |
10 | utils::{all_super_traits, generics}, | 10 | utils::{all_super_traits, generics}, |
11 | ApplicationTy, Binders, GenericPredicate, Substs, TraitRef, Ty, TypeCtor, | 11 | ApplicationTy, Binders, BoundVar, DebruijnIndex, GenericPredicate, Substs, TraitRef, Ty, |
12 | TypeCtor, TypeWalk, | ||
12 | }; | 13 | }; |
13 | 14 | ||
14 | pub(super) struct BuiltinImplData { | 15 | pub(super) struct BuiltinImplData { |
@@ -164,11 +165,15 @@ fn closure_fn_trait_impl_datum( | |||
164 | 165 | ||
165 | let arg_ty = Ty::apply( | 166 | let arg_ty = Ty::apply( |
166 | TypeCtor::Tuple { cardinality: num_args }, | 167 | TypeCtor::Tuple { cardinality: num_args }, |
167 | Substs::builder(num_args as usize).fill_with_bound_vars(0).build(), | 168 | Substs::builder(num_args as usize) |
169 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, 0) | ||
170 | .build(), | ||
168 | ); | 171 | ); |
169 | let sig_ty = Ty::apply( | 172 | let sig_ty = Ty::apply( |
170 | TypeCtor::FnPtr { num_args }, | 173 | TypeCtor::FnPtr { num_args }, |
171 | Substs::builder(num_args as usize + 1).fill_with_bound_vars(0).build(), | 174 | Substs::builder(num_args as usize + 1) |
175 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, 0) | ||
176 | .build(), | ||
172 | ); | 177 | ); |
173 | 178 | ||
174 | let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty); | 179 | let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty); |
@@ -203,7 +208,7 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
203 | } | 208 | } |
204 | }; | 209 | }; |
205 | 210 | ||
206 | let output_ty = Ty::Bound(num_args.into()); | 211 | let output_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, num_args.into())); |
207 | 212 | ||
208 | let fn_once_trait = | 213 | let fn_once_trait = |
209 | get_fn_trait(db, krate, super::FnTrait::FnOnce).expect("assoc ty value should not exist"); | 214 | get_fn_trait(db, krate, super::FnTrait::FnOnce).expect("assoc ty value should not exist"); |
@@ -241,7 +246,7 @@ fn array_unsize_impl_datum(db: &dyn HirDatabase, krate: CrateId) -> BuiltinImplD | |||
241 | // the existence of the Unsize trait has been checked before | 246 | // the existence of the Unsize trait has been checked before |
242 | .expect("Unsize trait missing"); | 247 | .expect("Unsize trait missing"); |
243 | 248 | ||
244 | let var = Ty::Bound(0); | 249 | let var = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); |
245 | let substs = Substs::builder(2) | 250 | let substs = Substs::builder(2) |
246 | .push(Ty::apply_one(TypeCtor::Array, var.clone())) | 251 | .push(Ty::apply_one(TypeCtor::Array, var.clone())) |
247 | .push(Ty::apply_one(TypeCtor::Slice, var)) | 252 | .push(Ty::apply_one(TypeCtor::Slice, var)) |
@@ -270,19 +275,18 @@ fn trait_object_unsize_impl_datum( | |||
270 | // the existence of the Unsize trait has been checked before | 275 | // the existence of the Unsize trait has been checked before |
271 | .expect("Unsize trait missing"); | 276 | .expect("Unsize trait missing"); |
272 | 277 | ||
273 | let self_ty = Ty::Bound(0); | 278 | let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); |
274 | 279 | ||
275 | let target_substs = Substs::build_for_def(db, trait_) | 280 | let target_substs = Substs::build_for_def(db, trait_) |
276 | .push(Ty::Bound(0)) | 281 | .push(Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0))) |
277 | // starting from ^2 because we want to start with ^1 outside of the | 282 | .fill_with_bound_vars(DebruijnIndex::ONE, 1) |
278 | // `dyn`, which is ^2 inside | ||
279 | .fill_with_bound_vars(2) | ||
280 | .build(); | 283 | .build(); |
281 | let num_vars = target_substs.len(); | 284 | let num_vars = target_substs.len(); |
282 | let target_trait_ref = TraitRef { trait_, substs: target_substs }; | 285 | let target_trait_ref = TraitRef { trait_, substs: target_substs }; |
283 | let target_bounds = vec![GenericPredicate::Implemented(target_trait_ref)]; | 286 | let target_bounds = vec![GenericPredicate::Implemented(target_trait_ref)]; |
284 | 287 | ||
285 | let self_substs = Substs::build_for_def(db, trait_).fill_with_bound_vars(0).build(); | 288 | let self_substs = |
289 | Substs::build_for_def(db, trait_).fill_with_bound_vars(DebruijnIndex::INNERMOST, 0).build(); | ||
286 | let self_trait_ref = TraitRef { trait_, substs: self_substs }; | 290 | let self_trait_ref = TraitRef { trait_, substs: self_substs }; |
287 | let where_clauses = vec![GenericPredicate::Implemented(self_trait_ref)]; | 291 | let where_clauses = vec![GenericPredicate::Implemented(self_trait_ref)]; |
288 | 292 | ||
@@ -305,24 +309,26 @@ fn super_trait_object_unsize_impl_datum( | |||
305 | // the existence of the Unsize trait has been checked before | 309 | // the existence of the Unsize trait has been checked before |
306 | .expect("Unsize trait missing"); | 310 | .expect("Unsize trait missing"); |
307 | 311 | ||
308 | let self_substs = Substs::build_for_def(db, data.trait_).fill_with_bound_vars(0).build(); | 312 | let self_substs = Substs::build_for_def(db, data.trait_) |
313 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, 0) | ||
314 | .build(); | ||
315 | let self_trait_ref = TraitRef { trait_: data.trait_, substs: self_substs.clone() }; | ||
309 | 316 | ||
310 | let num_vars = self_substs.len() - 1; | 317 | let num_vars = self_substs.len() - 1; |
311 | 318 | ||
312 | let self_trait_ref = TraitRef { trait_: data.trait_, substs: self_substs.clone() }; | ||
313 | let self_bounds = vec![GenericPredicate::Implemented(self_trait_ref.clone())]; | ||
314 | |||
315 | // we need to go from our trait to the super trait, substituting type parameters | 319 | // we need to go from our trait to the super trait, substituting type parameters |
316 | let path = crate::utils::find_super_trait_path(db.upcast(), data.trait_, data.super_trait); | 320 | let path = crate::utils::find_super_trait_path(db.upcast(), data.trait_, data.super_trait); |
317 | 321 | ||
318 | let mut current_trait_ref = self_trait_ref; | 322 | let mut current_trait_ref = self_trait_ref.clone(); |
319 | for t in path.into_iter().skip(1) { | 323 | for t in path.into_iter().skip(1) { |
320 | let bounds = db.generic_predicates(current_trait_ref.trait_.into()); | 324 | let bounds = db.generic_predicates(current_trait_ref.trait_.into()); |
321 | let super_trait_ref = bounds | 325 | let super_trait_ref = bounds |
322 | .iter() | 326 | .iter() |
323 | .find_map(|b| match &b.value { | 327 | .find_map(|b| match &b.value { |
324 | GenericPredicate::Implemented(tr) | 328 | GenericPredicate::Implemented(tr) |
325 | if tr.trait_ == t && tr.substs[0] == Ty::Bound(0) => | 329 | if tr.trait_ == t |
330 | && tr.substs[0] | ||
331 | == Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)) => | ||
326 | { | 332 | { |
327 | Some(Binders { value: tr, num_binders: b.num_binders }) | 333 | Some(Binders { value: tr, num_binders: b.num_binders }) |
328 | } | 334 | } |
@@ -332,7 +338,18 @@ fn super_trait_object_unsize_impl_datum( | |||
332 | current_trait_ref = super_trait_ref.cloned().subst(¤t_trait_ref.substs); | 338 | current_trait_ref = super_trait_ref.cloned().subst(¤t_trait_ref.substs); |
333 | } | 339 | } |
334 | 340 | ||
335 | let super_bounds = vec![GenericPredicate::Implemented(current_trait_ref)]; | 341 | // We need to renumber the variables a bit now: from ^0.0, ^0.1, ^0.2, ... |
342 | // to ^0.0, ^1.0, ^1.1. The reason for this is that the first variable comes | ||
343 | // from the dyn Trait binder, while the other variables come from the impl. | ||
344 | let new_substs = Substs::builder(num_vars + 1) | ||
345 | .push(Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0))) | ||
346 | .fill_with_bound_vars(DebruijnIndex::ONE, 0) | ||
347 | .build(); | ||
348 | |||
349 | let self_bounds = | ||
350 | vec![GenericPredicate::Implemented(self_trait_ref.subst_bound_vars(&new_substs))]; | ||
351 | let super_bounds = | ||
352 | vec![GenericPredicate::Implemented(current_trait_ref.subst_bound_vars(&new_substs))]; | ||
336 | 353 | ||
337 | let substs = Substs::builder(2) | 354 | let substs = Substs::builder(2) |
338 | .push(Ty::Dyn(self_bounds.into())) | 355 | .push(Ty::Dyn(self_bounds.into())) |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 943d5f125..53ce362ea 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -3,7 +3,10 @@ use std::{fmt, sync::Arc}; | |||
3 | 3 | ||
4 | use log::debug; | 4 | use log::debug; |
5 | 5 | ||
6 | use chalk_ir::{cast::Cast, Goal, GoalData, Parameter, PlaceholderIndex, TypeName, UniverseIndex}; | 6 | use chalk_ir::{ |
7 | cast::Cast, fold::shift::Shift, Goal, GoalData, Parameter, PlaceholderIndex, TypeName, | ||
8 | UniverseIndex, | ||
9 | }; | ||
7 | 10 | ||
8 | use hir_def::{AssocContainerId, AssocItemId, GenericDefId, HasModule, Lookup, TypeAliasId}; | 11 | use hir_def::{AssocContainerId, AssocItemId, GenericDefId, HasModule, Lookup, TypeAliasId}; |
9 | use ra_db::{ | 12 | use ra_db::{ |
@@ -59,53 +62,126 @@ impl chalk_ir::interner::Interner for Interner { | |||
59 | None | 62 | None |
60 | } | 63 | } |
61 | 64 | ||
65 | fn debug_ty(_ty: &chalk_ir::Ty<Self>, _fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { | ||
66 | None | ||
67 | } | ||
68 | |||
69 | fn debug_lifetime( | ||
70 | _lifetime: &chalk_ir::Lifetime<Self>, | ||
71 | _fmt: &mut fmt::Formatter<'_>, | ||
72 | ) -> Option<fmt::Result> { | ||
73 | None | ||
74 | } | ||
75 | |||
76 | fn debug_parameter( | ||
77 | _parameter: &Parameter<Self>, | ||
78 | _fmt: &mut fmt::Formatter<'_>, | ||
79 | ) -> Option<fmt::Result> { | ||
80 | None | ||
81 | } | ||
82 | |||
83 | fn debug_goal(_goal: &Goal<Self>, _fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { | ||
84 | None | ||
85 | } | ||
86 | |||
87 | fn debug_goals( | ||
88 | _goals: &chalk_ir::Goals<Self>, | ||
89 | _fmt: &mut fmt::Formatter<'_>, | ||
90 | ) -> Option<fmt::Result> { | ||
91 | None | ||
92 | } | ||
93 | |||
94 | fn debug_program_clause_implication( | ||
95 | _pci: &chalk_ir::ProgramClauseImplication<Self>, | ||
96 | _fmt: &mut fmt::Formatter<'_>, | ||
97 | ) -> Option<fmt::Result> { | ||
98 | None | ||
99 | } | ||
100 | |||
101 | fn debug_application_ty( | ||
102 | _application_ty: &chalk_ir::ApplicationTy<Self>, | ||
103 | _fmt: &mut fmt::Formatter<'_>, | ||
104 | ) -> Option<fmt::Result> { | ||
105 | None | ||
106 | } | ||
107 | |||
108 | fn debug_substitution( | ||
109 | _substitution: &chalk_ir::Substitution<Self>, | ||
110 | _fmt: &mut fmt::Formatter<'_>, | ||
111 | ) -> Option<fmt::Result> { | ||
112 | None | ||
113 | } | ||
114 | |||
115 | fn debug_separator_trait_ref( | ||
116 | _separator_trait_ref: &chalk_ir::SeparatorTraitRef<Self>, | ||
117 | _fmt: &mut fmt::Formatter<'_>, | ||
118 | ) -> Option<fmt::Result> { | ||
119 | None | ||
120 | } | ||
121 | |||
62 | fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> { | 122 | fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> { |
63 | Box::new(ty) | 123 | Box::new(ty) |
64 | } | 124 | } |
65 | 125 | ||
66 | fn ty_data(ty: &Box<chalk_ir::TyData<Self>>) -> &chalk_ir::TyData<Self> { | 126 | fn ty_data<'a>(&self, ty: &'a Box<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> { |
67 | ty | 127 | ty |
68 | } | 128 | } |
69 | 129 | ||
70 | fn intern_lifetime(lifetime: chalk_ir::LifetimeData<Self>) -> chalk_ir::LifetimeData<Self> { | 130 | fn intern_lifetime( |
131 | &self, | ||
132 | lifetime: chalk_ir::LifetimeData<Self>, | ||
133 | ) -> chalk_ir::LifetimeData<Self> { | ||
71 | lifetime | 134 | lifetime |
72 | } | 135 | } |
73 | 136 | ||
74 | fn lifetime_data(lifetime: &chalk_ir::LifetimeData<Self>) -> &chalk_ir::LifetimeData<Self> { | 137 | fn lifetime_data<'a>( |
138 | &self, | ||
139 | lifetime: &'a chalk_ir::LifetimeData<Self>, | ||
140 | ) -> &'a chalk_ir::LifetimeData<Self> { | ||
75 | lifetime | 141 | lifetime |
76 | } | 142 | } |
77 | 143 | ||
78 | fn intern_parameter(parameter: chalk_ir::ParameterData<Self>) -> chalk_ir::ParameterData<Self> { | 144 | fn intern_parameter( |
145 | &self, | ||
146 | parameter: chalk_ir::ParameterData<Self>, | ||
147 | ) -> chalk_ir::ParameterData<Self> { | ||
79 | parameter | 148 | parameter |
80 | } | 149 | } |
81 | 150 | ||
82 | fn parameter_data(parameter: &chalk_ir::ParameterData<Self>) -> &chalk_ir::ParameterData<Self> { | 151 | fn parameter_data<'a>( |
152 | &self, | ||
153 | parameter: &'a chalk_ir::ParameterData<Self>, | ||
154 | ) -> &'a chalk_ir::ParameterData<Self> { | ||
83 | parameter | 155 | parameter |
84 | } | 156 | } |
85 | 157 | ||
86 | fn intern_goal(goal: GoalData<Self>) -> Arc<GoalData<Self>> { | 158 | fn intern_goal(&self, goal: GoalData<Self>) -> Arc<GoalData<Self>> { |
87 | Arc::new(goal) | 159 | Arc::new(goal) |
88 | } | 160 | } |
89 | 161 | ||
90 | fn intern_goals(data: impl IntoIterator<Item = Goal<Self>>) -> Self::InternedGoals { | 162 | fn intern_goals(&self, data: impl IntoIterator<Item = Goal<Self>>) -> Self::InternedGoals { |
91 | data.into_iter().collect() | 163 | data.into_iter().collect() |
92 | } | 164 | } |
93 | 165 | ||
94 | fn goal_data(goal: &Arc<GoalData<Self>>) -> &GoalData<Self> { | 166 | fn goal_data<'a>(&self, goal: &'a Arc<GoalData<Self>>) -> &'a GoalData<Self> { |
95 | goal | 167 | goal |
96 | } | 168 | } |
97 | 169 | ||
98 | fn goals_data(goals: &Vec<Goal<Interner>>) -> &[Goal<Interner>] { | 170 | fn goals_data<'a>(&self, goals: &'a Vec<Goal<Interner>>) -> &'a [Goal<Interner>] { |
99 | goals | 171 | goals |
100 | } | 172 | } |
101 | 173 | ||
102 | fn intern_substitution<E>( | 174 | fn intern_substitution<E>( |
175 | &self, | ||
103 | data: impl IntoIterator<Item = Result<Parameter<Self>, E>>, | 176 | data: impl IntoIterator<Item = Result<Parameter<Self>, E>>, |
104 | ) -> Result<Vec<Parameter<Self>>, E> { | 177 | ) -> Result<Vec<Parameter<Self>>, E> { |
105 | data.into_iter().collect() | 178 | data.into_iter().collect() |
106 | } | 179 | } |
107 | 180 | ||
108 | fn substitution_data(substitution: &Vec<Parameter<Self>>) -> &[Parameter<Self>] { | 181 | fn substitution_data<'a>( |
182 | &self, | ||
183 | substitution: &'a Vec<Parameter<Self>>, | ||
184 | ) -> &'a [Parameter<Self>] { | ||
109 | substitution | 185 | substitution |
110 | } | 186 | } |
111 | } | 187 | } |
@@ -145,12 +221,14 @@ impl ToChalk for Ty { | |||
145 | Ty::Apply(apply_ty) => { | 221 | Ty::Apply(apply_ty) => { |
146 | let name = apply_ty.ctor.to_chalk(db); | 222 | let name = apply_ty.ctor.to_chalk(db); |
147 | let substitution = apply_ty.parameters.to_chalk(db); | 223 | let substitution = apply_ty.parameters.to_chalk(db); |
148 | chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner) | 224 | chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) |
149 | } | 225 | } |
150 | Ty::Projection(proj_ty) => { | 226 | Ty::Projection(proj_ty) => { |
151 | let associated_ty_id = proj_ty.associated_ty.to_chalk(db); | 227 | let associated_ty_id = proj_ty.associated_ty.to_chalk(db); |
152 | let substitution = proj_ty.parameters.to_chalk(db); | 228 | let substitution = proj_ty.parameters.to_chalk(db); |
153 | chalk_ir::AliasTy { associated_ty_id, substitution }.cast().intern(&Interner) | 229 | chalk_ir::AliasTy { associated_ty_id, substitution } |
230 | .cast(&Interner) | ||
231 | .intern(&Interner) | ||
154 | } | 232 | } |
155 | Ty::Placeholder(id) => { | 233 | Ty::Placeholder(id) => { |
156 | let interned_id = db.intern_type_param_id(id); | 234 | let interned_id = db.intern_type_param_id(id); |
@@ -160,7 +238,7 @@ impl ToChalk for Ty { | |||
160 | } | 238 | } |
161 | .to_ty::<Interner>(&Interner) | 239 | .to_ty::<Interner>(&Interner) |
162 | } | 240 | } |
163 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(&Interner), | 241 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner), |
164 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), | 242 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), |
165 | Ty::Dyn(predicates) => { | 243 | Ty::Dyn(predicates) => { |
166 | let where_clauses = predicates | 244 | let where_clauses = predicates |
@@ -173,14 +251,14 @@ impl ToChalk for Ty { | |||
173 | chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) | 251 | chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) |
174 | } | 252 | } |
175 | Ty::Opaque(_) | Ty::Unknown => { | 253 | Ty::Opaque(_) | Ty::Unknown => { |
176 | let substitution = chalk_ir::Substitution::empty(); | 254 | let substitution = chalk_ir::Substitution::empty(&Interner); |
177 | let name = TypeName::Error; | 255 | let name = TypeName::Error; |
178 | chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner) | 256 | chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) |
179 | } | 257 | } |
180 | } | 258 | } |
181 | } | 259 | } |
182 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { | 260 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { |
183 | match chalk.data().clone() { | 261 | match chalk.data(&Interner).clone() { |
184 | chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { | 262 | chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { |
185 | TypeName::Error => Ty::Unknown, | 263 | TypeName::Error => Ty::Unknown, |
186 | _ => { | 264 | _ => { |
@@ -202,7 +280,7 @@ impl ToChalk for Ty { | |||
202 | Ty::Projection(ProjectionTy { associated_ty, parameters }) | 280 | Ty::Projection(ProjectionTy { associated_ty, parameters }) |
203 | } | 281 | } |
204 | chalk_ir::TyData::Function(_) => unimplemented!(), | 282 | chalk_ir::TyData::Function(_) => unimplemented!(), |
205 | chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx as u32), | 283 | chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx), |
206 | chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, | 284 | chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, |
207 | chalk_ir::TyData::Dyn(where_clauses) => { | 285 | chalk_ir::TyData::Dyn(where_clauses) => { |
208 | assert_eq!(where_clauses.bounds.binders.len(), 1); | 286 | assert_eq!(where_clauses.bounds.binders.len(), 1); |
@@ -218,13 +296,13 @@ impl ToChalk for Substs { | |||
218 | type Chalk = chalk_ir::Substitution<Interner>; | 296 | type Chalk = chalk_ir::Substitution<Interner>; |
219 | 297 | ||
220 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { | 298 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { |
221 | chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db))) | 299 | chalk_ir::Substitution::from(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) |
222 | } | 300 | } |
223 | 301 | ||
224 | fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs { | 302 | fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs { |
225 | let tys = parameters | 303 | let tys = parameters |
226 | .into_iter() | 304 | .iter(&Interner) |
227 | .map(|p| match p.ty() { | 305 | .map(|p| match p.ty(&Interner) { |
228 | Some(ty) => from_chalk(db, ty.clone()), | 306 | Some(ty) => from_chalk(db, ty.clone()), |
229 | None => unimplemented!(), | 307 | None => unimplemented!(), |
230 | }) | 308 | }) |
@@ -332,15 +410,15 @@ impl ToChalk for GenericPredicate { | |||
332 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> { | 410 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> { |
333 | match self { | 411 | match self { |
334 | GenericPredicate::Implemented(trait_ref) => { | 412 | GenericPredicate::Implemented(trait_ref) => { |
335 | make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0) | 413 | let chalk_trait_ref = trait_ref.to_chalk(db); |
414 | let chalk_trait_ref = chalk_trait_ref.shifted_in(&Interner); | ||
415 | make_binders(chalk_ir::WhereClause::Implemented(chalk_trait_ref), 0) | ||
416 | } | ||
417 | GenericPredicate::Projection(projection_pred) => { | ||
418 | let ty = projection_pred.ty.to_chalk(db).shifted_in(&Interner); | ||
419 | let alias = projection_pred.projection_ty.to_chalk(db).shifted_in(&Interner); | ||
420 | make_binders(chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq { alias, ty }), 0) | ||
336 | } | 421 | } |
337 | GenericPredicate::Projection(projection_pred) => make_binders( | ||
338 | chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq { | ||
339 | alias: projection_pred.projection_ty.to_chalk(db), | ||
340 | ty: projection_pred.ty.to_chalk(db), | ||
341 | }), | ||
342 | 0, | ||
343 | ), | ||
344 | GenericPredicate::Error => panic!("tried passing GenericPredicate::Error to Chalk"), | 422 | GenericPredicate::Error => panic!("tried passing GenericPredicate::Error to Chalk"), |
345 | } | 423 | } |
346 | } | 424 | } |
@@ -400,8 +478,8 @@ impl ToChalk for Obligation { | |||
400 | 478 | ||
401 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> { | 479 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> { |
402 | match self { | 480 | match self { |
403 | Obligation::Trait(tr) => tr.to_chalk(db).cast(), | 481 | Obligation::Trait(tr) => tr.to_chalk(db).cast(&Interner), |
404 | Obligation::Projection(pr) => pr.to_chalk(db).cast(), | 482 | Obligation::Projection(pr) => pr.to_chalk(db).cast(&Interner), |
405 | } | 483 | } |
406 | } | 484 | } |
407 | 485 | ||
@@ -438,8 +516,8 @@ impl ToChalk for Arc<super::TraitEnvironment> { | |||
438 | continue; | 516 | continue; |
439 | } | 517 | } |
440 | let program_clause: chalk_ir::ProgramClause<Interner> = | 518 | let program_clause: chalk_ir::ProgramClause<Interner> = |
441 | pred.clone().to_chalk(db).cast(); | 519 | pred.clone().to_chalk(db).cast(&Interner); |
442 | clauses.push(program_clause.into_from_env_clause()); | 520 | clauses.push(program_clause.into_from_env_clause(&Interner)); |
443 | } | 521 | } |
444 | chalk_ir::Environment::new().add_clauses(clauses) | 522 | chalk_ir::Environment::new().add_clauses(clauses) |
445 | } | 523 | } |
@@ -504,7 +582,8 @@ impl ToChalk for builtin::BuiltinImplAssocTyValueData { | |||
504 | type Chalk = AssociatedTyValue; | 582 | type Chalk = AssociatedTyValue; |
505 | 583 | ||
506 | fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue { | 584 | fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue { |
507 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: self.value.to_chalk(db) }; | 585 | let ty = self.value.to_chalk(db); |
586 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty }; | ||
508 | 587 | ||
509 | chalk_rust_ir::AssociatedTyValue { | 588 | chalk_rust_ir::AssociatedTyValue { |
510 | associated_ty_id: self.assoc_ty_id.to_chalk(db), | 589 | associated_ty_id: self.assoc_ty_id.to_chalk(db), |
@@ -578,9 +657,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
578 | .map(|impl_| impl_.to_chalk(self.db)) | 657 | .map(|impl_| impl_.to_chalk(self.db)) |
579 | .collect(); | 658 | .collect(); |
580 | 659 | ||
581 | let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref().clone()); | 660 | let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); |
582 | let arg: Option<Ty> = | 661 | let arg: Option<Ty> = |
583 | parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref().clone())); | 662 | parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref(&Interner).clone())); |
584 | 663 | ||
585 | builtin::get_builtin_impls(self.db, self.krate, &ty, &arg, trait_, |i| { | 664 | builtin::get_builtin_impls(self.db, self.krate, &ty, &arg, trait_, |i| { |
586 | result.push(i.to_chalk(self.db)) | 665 | result.push(i.to_chalk(self.db)) |
@@ -663,11 +742,13 @@ pub(crate) fn trait_datum_query( | |||
663 | let associated_ty_ids = | 742 | let associated_ty_ids = |
664 | trait_data.associated_types().map(|type_alias| type_alias.to_chalk(db)).collect(); | 743 | trait_data.associated_types().map(|type_alias| type_alias.to_chalk(db)).collect(); |
665 | let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses }; | 744 | let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses }; |
745 | let well_known = None; // FIXME set this (depending on lang items) | ||
666 | let trait_datum = TraitDatum { | 746 | let trait_datum = TraitDatum { |
667 | id: trait_id, | 747 | id: trait_id, |
668 | binders: make_binders(trait_datum_bound, bound_vars.len()), | 748 | binders: make_binders(trait_datum_bound, bound_vars.len()), |
669 | flags, | 749 | flags, |
670 | associated_ty_ids, | 750 | associated_ty_ids, |
751 | well_known, | ||
671 | }; | 752 | }; |
672 | Arc::new(trait_datum) | 753 | Arc::new(trait_datum) |
673 | } | 754 | } |