diff options
Diffstat (limited to 'crates/ra_hir/src/ty/infer')
-rw-r--r-- | crates/ra_hir/src/ty/infer/unify.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty/infer/unify.rs b/crates/ra_hir/src/ty/infer/unify.rs index 49bf5b946..a24e5eb5c 100644 --- a/crates/ra_hir/src/ty/infer/unify.rs +++ b/crates/ra_hir/src/ty/infer/unify.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use super::InferenceContext; | 3 | use super::InferenceContext; |
4 | use crate::db::HirDatabase; | 4 | use crate::db::HirDatabase; |
5 | use crate::ty::{Canonical, InferTy, TraitRef, Ty}; | 5 | use crate::ty::{Canonical, InferTy, ProjectionPredicate, ProjectionTy, TraitRef, Ty}; |
6 | 6 | ||
7 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 7 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { |
8 | pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D> | 8 | pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D> |
@@ -86,6 +86,25 @@ where | |||
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | fn do_canonicalize_projection_ty(&mut self, projection_ty: ProjectionTy) -> ProjectionTy { | ||
90 | let params = projection_ty | ||
91 | .parameters | ||
92 | .iter() | ||
93 | .map(|ty| self.do_canonicalize_ty(ty.clone())) | ||
94 | .collect::<Vec<_>>(); | ||
95 | ProjectionTy { associated_ty: projection_ty.associated_ty, parameters: params.into() } | ||
96 | } | ||
97 | |||
98 | fn do_canonicalize_projection_predicate( | ||
99 | &mut self, | ||
100 | projection: ProjectionPredicate, | ||
101 | ) -> ProjectionPredicate { | ||
102 | let ty = self.do_canonicalize_ty(projection.ty); | ||
103 | let projection_ty = self.do_canonicalize_projection_ty(projection.projection_ty); | ||
104 | |||
105 | ProjectionPredicate { ty, projection_ty } | ||
106 | } | ||
107 | |||
89 | pub fn canonicalize_ty(mut self, ty: Ty) -> Canonicalized<Ty> { | 108 | pub fn canonicalize_ty(mut self, ty: Ty) -> Canonicalized<Ty> { |
90 | let result = self.do_canonicalize_ty(ty); | 109 | let result = self.do_canonicalize_ty(ty); |
91 | self.into_canonicalized(result) | 110 | self.into_canonicalized(result) |
@@ -95,6 +114,14 @@ where | |||
95 | let result = self.do_canonicalize_trait_ref(trait_ref); | 114 | let result = self.do_canonicalize_trait_ref(trait_ref); |
96 | self.into_canonicalized(result) | 115 | self.into_canonicalized(result) |
97 | } | 116 | } |
117 | |||
118 | pub fn canonicalize_projection( | ||
119 | mut self, | ||
120 | projection: ProjectionPredicate, | ||
121 | ) -> Canonicalized<ProjectionPredicate> { | ||
122 | let result = self.do_canonicalize_projection_predicate(projection); | ||
123 | self.into_canonicalized(result) | ||
124 | } | ||
98 | } | 125 | } |
99 | 126 | ||
100 | impl<T> Canonicalized<T> { | 127 | impl<T> Canonicalized<T> { |