diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index b54c80318..035491bff 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -120,12 +120,32 @@ pub struct ProjectionTy { | |||
120 | pub parameters: Substs, | 120 | pub parameters: Substs, |
121 | } | 121 | } |
122 | 122 | ||
123 | impl ProjectionTy { | ||
124 | pub fn walk(&self, f: &mut impl FnMut(&Ty)) { | ||
125 | self.parameters.walk(f); | ||
126 | } | ||
127 | |||
128 | pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { | ||
129 | self.parameters.walk_mut(f); | ||
130 | } | ||
131 | } | ||
132 | |||
123 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 133 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
124 | pub struct UnselectedProjectionTy { | 134 | pub struct UnselectedProjectionTy { |
125 | pub type_name: Name, | 135 | pub type_name: Name, |
126 | pub parameters: Substs, | 136 | pub parameters: Substs, |
127 | } | 137 | } |
128 | 138 | ||
139 | impl UnselectedProjectionTy { | ||
140 | pub fn walk(&self, f: &mut impl FnMut(&Ty)) { | ||
141 | self.parameters.walk(f); | ||
142 | } | ||
143 | |||
144 | pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { | ||
145 | self.parameters.walk_mut(f); | ||
146 | } | ||
147 | } | ||
148 | |||
129 | /// A type. | 149 | /// A type. |
130 | /// | 150 | /// |
131 | /// See also the `TyKind` enum in rustc (librustc/ty/sty.rs), which represents | 151 | /// See also the `TyKind` enum in rustc (librustc/ty/sty.rs), which represents |
@@ -306,6 +326,8 @@ impl TraitRef { | |||
306 | pub enum GenericPredicate { | 326 | pub enum GenericPredicate { |
307 | /// The given trait needs to be implemented for its type parameters. | 327 | /// The given trait needs to be implemented for its type parameters. |
308 | Implemented(TraitRef), | 328 | Implemented(TraitRef), |
329 | /// An associated type bindings like in `Iterator<Item = T>`. | ||
330 | Projection(ProjectionPredicate), | ||
309 | /// We couldn't resolve the trait reference. (If some type parameters can't | 331 | /// We couldn't resolve the trait reference. (If some type parameters can't |
310 | /// be resolved, they will just be Unknown). | 332 | /// be resolved, they will just be Unknown). |
311 | Error, | 333 | Error, |
@@ -324,6 +346,9 @@ impl GenericPredicate { | |||
324 | GenericPredicate::Implemented(trait_ref) => { | 346 | GenericPredicate::Implemented(trait_ref) => { |
325 | GenericPredicate::Implemented(trait_ref.subst(substs)) | 347 | GenericPredicate::Implemented(trait_ref.subst(substs)) |
326 | } | 348 | } |
349 | GenericPredicate::Projection(projection_predicate) => { | ||
350 | GenericPredicate::Projection(projection_predicate.subst(substs)) | ||
351 | } | ||
327 | GenericPredicate::Error => self, | 352 | GenericPredicate::Error => self, |
328 | } | 353 | } |
329 | } | 354 | } |
@@ -331,6 +356,7 @@ impl GenericPredicate { | |||
331 | pub fn walk(&self, f: &mut impl FnMut(&Ty)) { | 356 | pub fn walk(&self, f: &mut impl FnMut(&Ty)) { |
332 | match self { | 357 | match self { |
333 | GenericPredicate::Implemented(trait_ref) => trait_ref.walk(f), | 358 | GenericPredicate::Implemented(trait_ref) => trait_ref.walk(f), |
359 | GenericPredicate::Projection(projection_pred) => projection_pred.walk(f), | ||
334 | GenericPredicate::Error => {} | 360 | GenericPredicate::Error => {} |
335 | } | 361 | } |
336 | } | 362 | } |
@@ -338,6 +364,7 @@ impl GenericPredicate { | |||
338 | pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { | 364 | pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { |
339 | match self { | 365 | match self { |
340 | GenericPredicate::Implemented(trait_ref) => trait_ref.walk_mut(f), | 366 | GenericPredicate::Implemented(trait_ref) => trait_ref.walk_mut(f), |
367 | GenericPredicate::Projection(projection_pred) => projection_pred.walk_mut(f), | ||
341 | GenericPredicate::Error => {} | 368 | GenericPredicate::Error => {} |
342 | } | 369 | } |
343 | } | 370 | } |
@@ -754,6 +781,9 @@ impl HirDisplay for Ty { | |||
754 | GenericPredicate::Implemented(trait_ref) => { | 781 | GenericPredicate::Implemented(trait_ref) => { |
755 | trait_ref.hir_fmt_ext(f, false)? | 782 | trait_ref.hir_fmt_ext(f, false)? |
756 | } | 783 | } |
784 | GenericPredicate::Projection(_projection_pred) => { | ||
785 | // TODO show something | ||
786 | } | ||
757 | GenericPredicate::Error => p.hir_fmt(f)?, | 787 | GenericPredicate::Error => p.hir_fmt(f)?, |
758 | } | 788 | } |
759 | } | 789 | } |
@@ -800,6 +830,9 @@ impl HirDisplay for GenericPredicate { | |||
800 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 830 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
801 | match self { | 831 | match self { |
802 | GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, | 832 | GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, |
833 | GenericPredicate::Projection(projection_pred) => { | ||
834 | // TODO print something | ||
835 | } | ||
803 | GenericPredicate::Error => write!(f, "{{error}}")?, | 836 | GenericPredicate::Error => write!(f, "{{error}}")?, |
804 | } | 837 | } |
805 | Ok(()) | 838 | Ok(()) |