aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-02-20 17:51:42 +0000
committerLukas Wirth <[email protected]>2021-02-20 18:08:20 +0000
commit9e5192d917e998d78fd25c4013eb8117f7401068 (patch)
tree7b086dc1856824008099a1f4533bf4987383b076 /crates
parentba3a5c518a4e20ddacad05d7a8a67704ca2b2a9a (diff)
Don't lower TypeBound::Lifetime as GenericPredicate::Error
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/lower.rs34
-rw-r--r--crates/hir_ty/src/tests/method_resolution.rs4
-rw-r--r--crates/hir_ty/src/tests/traits.rs6
-rw-r--r--crates/ide/src/hover.rs4
4 files changed, 23 insertions, 25 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
671impl GenericPredicate { 660impl 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() {
1114trait Foo {} 1114trait Foo {}
1115 1115
1116impl Foo for u32 {} 1116impl Foo for u32 {}
1117impl dyn Foo { 1117impl 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
1123fn main() { 1123fn 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 '{}': ()
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 69b828f47..9a605b09d 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -3417,7 +3417,7 @@ impl<T> Foo<T$0> {}
3417 ``` 3417 ```
3418 "#]], 3418 "#]],
3419 ); 3419 );
3420 // lifetimes aren't being substituted yet 3420 // lifetimes bounds arent being tracked yet
3421 check( 3421 check(
3422 r#" 3422 r#"
3423struct Foo<T>(T); 3423struct Foo<T>(T);
@@ -3427,7 +3427,7 @@ impl<T: 'static> Foo<T$0> {}
3427 *T* 3427 *T*
3428 3428
3429 ```rust 3429 ```rust
3430 T: {error} 3430 T
3431 ``` 3431 ```
3432 "#]], 3432 "#]],
3433 ); 3433 );