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.rs41
1 files changed, 18 insertions, 23 deletions
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 }