aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs49
1 files changed, 41 insertions, 8 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 3859dbfa1..2afcb5413 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -45,7 +45,7 @@ pub use lower::{
45 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, 45 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
46 TyDefId, TyLoweringContext, ValueTyDefId, 46 TyDefId, TyLoweringContext, ValueTyDefId,
47}; 47};
48pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; 48pub use traits::{AliasEq, InEnvironment, Obligation, TraitEnvironment};
49 49
50pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind}; 50pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind};
51 51
@@ -72,6 +72,20 @@ pub struct OpaqueTy {
72 pub substitution: Substitution, 72 pub substitution: Substitution,
73} 73}
74 74
75impl TypeWalk for OpaqueTy {
76 fn walk(&self, f: &mut impl FnMut(&Ty)) {
77 self.substitution.walk(f);
78 }
79
80 fn walk_mut_binders(
81 &mut self,
82 f: &mut impl FnMut(&mut Ty, DebruijnIndex),
83 binders: DebruijnIndex,
84 ) {
85 self.substitution.walk_mut_binders(f, binders);
86 }
87}
88
75/// A "projection" type corresponds to an (unnormalized) 89/// A "projection" type corresponds to an (unnormalized)
76/// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the 90/// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the
77/// trait and all its parameters are fully known. 91/// trait and all its parameters are fully known.
@@ -133,6 +147,25 @@ pub enum AliasTy {
133 Opaque(OpaqueTy), 147 Opaque(OpaqueTy),
134} 148}
135 149
150impl TypeWalk for AliasTy {
151 fn walk(&self, f: &mut impl FnMut(&Ty)) {
152 match self {
153 AliasTy::Projection(it) => it.walk(f),
154 AliasTy::Opaque(it) => it.walk(f),
155 }
156 }
157
158 fn walk_mut_binders(
159 &mut self,
160 f: &mut impl FnMut(&mut Ty, DebruijnIndex),
161 binders: DebruijnIndex,
162 ) {
163 match self {
164 AliasTy::Projection(it) => it.walk_mut_binders(f, binders),
165 AliasTy::Opaque(it) => it.walk_mut_binders(f, binders),
166 }
167 }
168}
136/// A type. 169/// A type.
137/// 170///
138/// See also the `TyKind` enum in rustc (librustc/ty/sty.rs), which represents 171/// See also the `TyKind` enum in rustc (librustc/ty/sty.rs), which represents
@@ -535,7 +568,7 @@ pub enum GenericPredicate {
535 /// The given trait needs to be implemented for its type parameters. 568 /// The given trait needs to be implemented for its type parameters.
536 Implemented(TraitRef), 569 Implemented(TraitRef),
537 /// An associated type bindings like in `Iterator<Item = T>`. 570 /// An associated type bindings like in `Iterator<Item = T>`.
538 Projection(ProjectionPredicate), 571 AliasEq(AliasEq),
539 /// We couldn't resolve the trait reference. (If some type parameters can't 572 /// We couldn't resolve the trait reference. (If some type parameters can't
540 /// be resolved, they will just be Unknown). 573 /// be resolved, they will just be Unknown).
541 Error, 574 Error,
@@ -553,8 +586,10 @@ impl GenericPredicate {
553 pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> { 586 pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> {
554 match self { 587 match self {
555 GenericPredicate::Implemented(tr) => Some(tr.clone()), 588 GenericPredicate::Implemented(tr) => Some(tr.clone()),
556 GenericPredicate::Projection(proj) => Some(proj.projection_ty.trait_ref(db)), 589 GenericPredicate::AliasEq(AliasEq { alias: AliasTy::Projection(proj), .. }) => {
557 GenericPredicate::Error => None, 590 Some(proj.trait_ref(db))
591 }
592 GenericPredicate::AliasEq(_) | GenericPredicate::Error => None,
558 } 593 }
559 } 594 }
560} 595}
@@ -563,7 +598,7 @@ impl TypeWalk for GenericPredicate {
563 fn walk(&self, f: &mut impl FnMut(&Ty)) { 598 fn walk(&self, f: &mut impl FnMut(&Ty)) {
564 match self { 599 match self {
565 GenericPredicate::Implemented(trait_ref) => trait_ref.walk(f), 600 GenericPredicate::Implemented(trait_ref) => trait_ref.walk(f),
566 GenericPredicate::Projection(projection_pred) => projection_pred.walk(f), 601 GenericPredicate::AliasEq(alias_eq) => alias_eq.walk(f),
567 GenericPredicate::Error => {} 602 GenericPredicate::Error => {}
568 } 603 }
569 } 604 }
@@ -575,9 +610,7 @@ impl TypeWalk for GenericPredicate {
575 ) { 610 ) {
576 match self { 611 match self {
577 GenericPredicate::Implemented(trait_ref) => trait_ref.walk_mut_binders(f, binders), 612 GenericPredicate::Implemented(trait_ref) => trait_ref.walk_mut_binders(f, binders),
578 GenericPredicate::Projection(projection_pred) => { 613 GenericPredicate::AliasEq(alias_eq) => alias_eq.walk_mut_binders(f, binders),
579 projection_pred.walk_mut_binders(f, binders)
580 }
581 GenericPredicate::Error => {} 614 GenericPredicate::Error => {}
582 } 615 }
583 } 616 }