diff options
author | Lukas Wirth <[email protected]> | 2021-02-20 17:51:42 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-02-20 18:08:20 +0000 |
commit | 9e5192d917e998d78fd25c4013eb8117f7401068 (patch) | |
tree | 7b086dc1856824008099a1f4533bf4987383b076 /crates/hir_ty/src | |
parent | ba3a5c518a4e20ddacad05d7a8a67704ca2b2a9a (diff) |
Don't lower TypeBound::Lifetime as GenericPredicate::Error
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/lower.rs | 34 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/method_resolution.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 6 |
3 files changed, 21 insertions, 23 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index f9dc832bd..99b0ecf3b 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -655,17 +655,6 @@ impl TraitRef { | |||
655 | ) -> Substs { | 655 | ) -> Substs { |
656 | substs_from_path_segment(ctx, segment, Some(resolved.into()), false) | 656 | substs_from_path_segment(ctx, segment, Some(resolved.into()), false) |
657 | } | 657 | } |
658 | |||
659 | pub(crate) fn from_type_bound( | ||
660 | ctx: &TyLoweringContext<'_>, | ||
661 | bound: &TypeBound, | ||
662 | self_ty: Ty, | ||
663 | ) -> Option<TraitRef> { | ||
664 | match bound { | ||
665 | TypeBound::Path(path) => TraitRef::from_path(ctx, path, Some(self_ty)), | ||
666 | TypeBound::Lifetime(_) | TypeBound::Error => None, | ||
667 | } | ||
668 | } | ||
669 | } | 658 | } |
670 | 659 | ||
671 | impl GenericPredicate { | 660 | impl GenericPredicate { |
@@ -705,13 +694,22 @@ impl GenericPredicate { | |||
705 | bound: &'a TypeBound, | 694 | bound: &'a TypeBound, |
706 | self_ty: Ty, | 695 | self_ty: Ty, |
707 | ) -> impl Iterator<Item = GenericPredicate> + 'a { | 696 | ) -> impl Iterator<Item = GenericPredicate> + 'a { |
708 | let trait_ref = TraitRef::from_type_bound(ctx, bound, self_ty); | 697 | let mut bindings = None; |
709 | iter::once(trait_ref.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented)) | 698 | let trait_ref = match bound { |
710 | .chain( | 699 | TypeBound::Path(path) => { |
711 | trait_ref | 700 | bindings = TraitRef::from_path(ctx, path, Some(self_ty)); |
712 | .into_iter() | 701 | Some( |
713 | .flat_map(move |tr| assoc_type_bindings_from_type_bound(ctx, bound, tr)), | 702 | bindings.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented), |
714 | ) | 703 | ) |
704 | } | ||
705 | TypeBound::Lifetime(_) => None, | ||
706 | TypeBound::Error => Some(GenericPredicate::Error), | ||
707 | }; | ||
708 | trait_ref.into_iter().chain( | ||
709 | bindings | ||
710 | .into_iter() | ||
711 | .flat_map(move |tr| assoc_type_bindings_from_type_bound(ctx, bound, tr)), | ||
712 | ) | ||
715 | } | 713 | } |
716 | } | 714 | } |
717 | 715 | ||
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index 80e795fbf..659b8fce9 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs | |||
@@ -1114,14 +1114,14 @@ fn method_on_dyn_impl() { | |||
1114 | trait Foo {} | 1114 | trait Foo {} |
1115 | 1115 | ||
1116 | impl Foo for u32 {} | 1116 | impl Foo for u32 {} |
1117 | impl dyn Foo { | 1117 | impl dyn Foo + '_ { |
1118 | pub fn dyn_foo(&self) -> u32 { | 1118 | pub fn dyn_foo(&self) -> u32 { |
1119 | 0 | 1119 | 0 |
1120 | } | 1120 | } |
1121 | } | 1121 | } |
1122 | 1122 | ||
1123 | fn main() { | 1123 | fn main() { |
1124 | let f = &42u32 as &dyn Foo<u32>; | 1124 | let f = &42u32 as &dyn Foo; |
1125 | f.dyn_foo(); | 1125 | f.dyn_foo(); |
1126 | // ^u32 | 1126 | // ^u32 |
1127 | } | 1127 | } |
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 7fce441f2..744fb5ff2 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -1409,10 +1409,10 @@ fn weird_bounds() { | |||
1409 | fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) {} | 1409 | fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) {} |
1410 | "#, | 1410 | "#, |
1411 | expect![[r#" | 1411 | expect![[r#" |
1412 | 23..24 'a': impl Trait + {error} | 1412 | 23..24 'a': impl Trait |
1413 | 50..51 'b': impl {error} | 1413 | 50..51 'b': impl |
1414 | 69..70 'c': impl Trait | 1414 | 69..70 'c': impl Trait |
1415 | 86..87 'd': impl {error} | 1415 | 86..87 'd': impl |
1416 | 107..108 'e': impl {error} | 1416 | 107..108 'e': impl {error} |
1417 | 123..124 'f': impl Trait + {error} | 1417 | 123..124 'f': impl Trait + {error} |
1418 | 147..149 '{}': () | 1418 | 147..149 '{}': () |