aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r--crates/hir_ty/src/traits/chalk.rs16
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs41
2 files changed, 23 insertions, 34 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 080764e76..734679414 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -21,8 +21,8 @@ use crate::{
21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, 21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
22 to_assoc_type_id, to_chalk_trait_id, 22 to_assoc_type_id, to_chalk_trait_id,
23 utils::generics, 23 utils::generics,
24 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, 24 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, ProjectionTy,
25 GenericPredicate, ProjectionTy, Substitution, TraitRef, Ty, TyKind, 25 Substitution, TraitRef, Ty, TyKind, WhereClause,
26}; 26};
27use mapping::{ 27use mapping::{
28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, 28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
@@ -187,13 +187,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
187 let data = &datas.value.impl_traits[idx as usize]; 187 let data = &datas.value.impl_traits[idx as usize];
188 let bound = OpaqueTyDatumBound { 188 let bound = OpaqueTyDatumBound {
189 bounds: make_binders( 189 bounds: make_binders(
190 data.bounds 190 data.bounds.value.iter().cloned().map(|b| b.to_chalk(self.db)).collect(),
191 .value
192 .iter()
193 .cloned()
194 .filter(|b| !b.is_error())
195 .map(|b| b.to_chalk(self.db))
196 .collect(),
197 1, 191 1,
198 ), 192 ),
199 where_clauses: make_binders(vec![], 0), 193 where_clauses: make_binders(vec![], 0),
@@ -218,7 +212,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
218 // |-------------OpaqueTyDatumBound--------------| 212 // |-------------OpaqueTyDatumBound--------------|
219 // for<T> <Self> [Future<Self>, Future::Output<Self> = T] 213 // for<T> <Self> [Future<Self>, Future::Output<Self> = T]
220 // ^1 ^0 ^0 ^0 ^1 214 // ^1 ^0 ^0 ^0 ^1
221 let impl_bound = GenericPredicate::Implemented(TraitRef { 215 let impl_bound = WhereClause::Implemented(TraitRef {
222 trait_id: to_chalk_trait_id(future_trait), 216 trait_id: to_chalk_trait_id(future_trait),
223 // Self type as the first parameter. 217 // Self type as the first parameter.
224 substitution: Substitution::single( 218 substitution: Substitution::single(
@@ -229,7 +223,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
229 .intern(&Interner), 223 .intern(&Interner),
230 ), 224 ),
231 }); 225 });
232 let proj_bound = GenericPredicate::AliasEq(AliasEq { 226 let proj_bound = WhereClause::AliasEq(AliasEq {
233 alias: AliasTy::Projection(ProjectionTy { 227 alias: AliasTy::Projection(ProjectionTy {
234 associated_ty_id: to_assoc_type_id(future_output), 228 associated_ty_id: to_assoc_type_id(future_output),
235 // Self type as the first parameter. 229 // Self type as the first parameter.
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 62b779008..65feb82e5 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -13,9 +13,9 @@ use crate::{
13 db::HirDatabase, 13 db::HirDatabase,
14 from_assoc_type_id, 14 from_assoc_type_id,
15 primitive::UintTy, 15 primitive::UintTy,
16 traits::{Canonical, Obligation}, 16 traits::{Canonical, DomainGoal},
17 AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, ProjectionTy, 17 AliasTy, CallableDefId, FnPointer, InEnvironment, OpaqueTy, ProjectionTy, Scalar, Substitution,
18 Scalar, Substitution, TraitRef, Ty, 18 TraitRef, Ty, WhereClause,
19}; 19};
20 20
21use super::interner::*; 21use super::interner::*;
@@ -98,7 +98,7 @@ impl ToChalk for Ty {
98 TyKind::Dyn(predicates) => { 98 TyKind::Dyn(predicates) => {
99 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( 99 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter(
100 &Interner, 100 &Interner,
101 predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), 101 predicates.iter().cloned().map(|p| p.to_chalk(db)),
102 ); 102 );
103 let bounded_ty = chalk_ir::DynTy { 103 let bounded_ty = chalk_ir::DynTy {
104 bounds: make_binders(where_clauses, 1), 104 bounds: make_binders(where_clauses, 1),
@@ -304,28 +304,27 @@ impl ToChalk for TypeAliasAsValue {
304 } 304 }
305} 305}
306 306
307impl ToChalk for GenericPredicate { 307impl ToChalk for WhereClause {
308 type Chalk = chalk_ir::QuantifiedWhereClause<Interner>; 308 type Chalk = chalk_ir::QuantifiedWhereClause<Interner>;
309 309
310 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> { 310 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> {
311 match self { 311 match self {
312 GenericPredicate::Implemented(trait_ref) => { 312 WhereClause::Implemented(trait_ref) => {
313 let chalk_trait_ref = trait_ref.to_chalk(db); 313 let chalk_trait_ref = trait_ref.to_chalk(db);
314 let chalk_trait_ref = chalk_trait_ref.shifted_in(&Interner); 314 let chalk_trait_ref = chalk_trait_ref.shifted_in(&Interner);
315 make_binders(chalk_ir::WhereClause::Implemented(chalk_trait_ref), 0) 315 make_binders(chalk_ir::WhereClause::Implemented(chalk_trait_ref), 0)
316 } 316 }
317 GenericPredicate::AliasEq(alias_eq) => make_binders( 317 WhereClause::AliasEq(alias_eq) => make_binders(
318 chalk_ir::WhereClause::AliasEq(alias_eq.to_chalk(db).shifted_in(&Interner)), 318 chalk_ir::WhereClause::AliasEq(alias_eq.to_chalk(db).shifted_in(&Interner)),
319 0, 319 0,
320 ), 320 ),
321 GenericPredicate::Error => panic!("tried passing GenericPredicate::Error to Chalk"),
322 } 321 }
323 } 322 }
324 323
325 fn from_chalk( 324 fn from_chalk(
326 db: &dyn HirDatabase, 325 db: &dyn HirDatabase,
327 where_clause: chalk_ir::QuantifiedWhereClause<Interner>, 326 where_clause: chalk_ir::QuantifiedWhereClause<Interner>,
328 ) -> GenericPredicate { 327 ) -> WhereClause {
329 // we don't produce any where clauses with binders and can't currently deal with them 328 // we don't produce any where clauses with binders and can't currently deal with them
330 match where_clause 329 match where_clause
331 .skip_binders() 330 .skip_binders()
@@ -333,11 +332,9 @@ impl ToChalk for GenericPredicate {
333 .shifted_out(&Interner) 332 .shifted_out(&Interner)
334 .expect("unexpected bound vars in where clause") 333 .expect("unexpected bound vars in where clause")
335 { 334 {
336 chalk_ir::WhereClause::Implemented(tr) => { 335 chalk_ir::WhereClause::Implemented(tr) => WhereClause::Implemented(from_chalk(db, tr)),
337 GenericPredicate::Implemented(from_chalk(db, tr))
338 }
339 chalk_ir::WhereClause::AliasEq(alias_eq) => { 336 chalk_ir::WhereClause::AliasEq(alias_eq) => {
340 GenericPredicate::AliasEq(from_chalk(db, alias_eq)) 337 WhereClause::AliasEq(from_chalk(db, alias_eq))
341 } 338 }
342 339
343 chalk_ir::WhereClause::LifetimeOutlives(_) => { 340 chalk_ir::WhereClause::LifetimeOutlives(_) => {
@@ -425,13 +422,15 @@ impl ToChalk for AliasEq {
425 } 422 }
426} 423}
427 424
428impl ToChalk for Obligation { 425impl ToChalk for DomainGoal {
429 type Chalk = chalk_ir::DomainGoal<Interner>; 426 type Chalk = chalk_ir::DomainGoal<Interner>;
430 427
431 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> { 428 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> {
432 match self { 429 match self {
433 Obligation::Trait(tr) => tr.to_chalk(db).cast(&Interner), 430 DomainGoal::Holds(WhereClause::Implemented(tr)) => tr.to_chalk(db).cast(&Interner),
434 Obligation::AliasEq(alias_eq) => alias_eq.to_chalk(db).cast(&Interner), 431 DomainGoal::Holds(WhereClause::AliasEq(alias_eq)) => {
432 alias_eq.to_chalk(db).cast(&Interner)
433 }
435 } 434 }
436 } 435 }
437 436
@@ -523,10 +522,6 @@ pub(super) fn convert_where_clauses(
523 let generic_predicates = db.generic_predicates(def); 522 let generic_predicates = db.generic_predicates(def);
524 let mut result = Vec::with_capacity(generic_predicates.len()); 523 let mut result = Vec::with_capacity(generic_predicates.len());
525 for pred in generic_predicates.iter() { 524 for pred in generic_predicates.iter() {
526 if pred.value.is_error() {
527 // skip errored predicates completely
528 continue;
529 }
530 result.push(pred.clone().subst(substs).to_chalk(db)); 525 result.push(pred.clone().subst(substs).to_chalk(db));
531 } 526 }
532 result 527 result
@@ -534,13 +529,13 @@ pub(super) fn convert_where_clauses(
534 529
535pub(super) fn generic_predicate_to_inline_bound( 530pub(super) fn generic_predicate_to_inline_bound(
536 db: &dyn HirDatabase, 531 db: &dyn HirDatabase,
537 pred: &GenericPredicate, 532 pred: &WhereClause,
538 self_ty: &Ty, 533 self_ty: &Ty,
539) -> Option<rust_ir::InlineBound<Interner>> { 534) -> Option<rust_ir::InlineBound<Interner>> {
540 // An InlineBound is like a GenericPredicate, except the self type is left out. 535 // An InlineBound is like a GenericPredicate, except the self type is left out.
541 // We don't have a special type for this, but Chalk does. 536 // We don't have a special type for this, but Chalk does.
542 match pred { 537 match pred {
543 GenericPredicate::Implemented(trait_ref) => { 538 WhereClause::Implemented(trait_ref) => {
544 if &trait_ref.substitution[0] != self_ty { 539 if &trait_ref.substitution[0] != self_ty {
545 // we can only convert predicates back to type bounds if they 540 // we can only convert predicates back to type bounds if they
546 // have the expected self type 541 // have the expected self type
@@ -553,7 +548,7 @@ pub(super) fn generic_predicate_to_inline_bound(
553 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; 548 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self };
554 Some(rust_ir::InlineBound::TraitBound(trait_bound)) 549 Some(rust_ir::InlineBound::TraitBound(trait_bound))
555 } 550 }
556 GenericPredicate::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { 551 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
557 if &projection_ty.substitution[0] != self_ty { 552 if &projection_ty.substitution[0] != self_ty {
558 return None; 553 return None;
559 } 554 }