]> git.lizzy.rs Git - rust.git/commitdiff
Don't lower TypeBound::Lifetime as GenericPredicate::Error
authorLukas Wirth <lukastw97@gmail.com>
Sat, 20 Feb 2021 17:51:42 +0000 (18:51 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Sat, 20 Feb 2021 18:08:20 +0000 (19:08 +0100)
crates/hir_ty/src/lower.rs
crates/hir_ty/src/tests/method_resolution.rs
crates/hir_ty/src/tests/traits.rs
crates/ide/src/hover.rs

index f9dc832bd25a094423f5efc13de46f2eb626e6bd..99b0ecf3b55f163c95075c09c9fed604e21e95f9 100644 (file)
@@ -655,17 +655,6 @@ fn substs_from_path(
     ) -> Substs {
         substs_from_path_segment(ctx, segment, Some(resolved.into()), false)
     }
-
-    pub(crate) fn from_type_bound(
-        ctx: &TyLoweringContext<'_>,
-        bound: &TypeBound,
-        self_ty: Ty,
-    ) -> Option<TraitRef> {
-        match bound {
-            TypeBound::Path(path) => TraitRef::from_path(ctx, path, Some(self_ty)),
-            TypeBound::Lifetime(_) | TypeBound::Error => None,
-        }
-    }
 }
 
 impl GenericPredicate {
@@ -705,13 +694,22 @@ pub(crate) fn from_type_bound<'a>(
         bound: &'a TypeBound,
         self_ty: Ty,
     ) -> impl Iterator<Item = GenericPredicate> + 'a {
-        let trait_ref = TraitRef::from_type_bound(ctx, bound, self_ty);
-        iter::once(trait_ref.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented))
-            .chain(
-                trait_ref
-                    .into_iter()
-                    .flat_map(move |tr| assoc_type_bindings_from_type_bound(ctx, bound, tr)),
-            )
+        let mut bindings = None;
+        let trait_ref = match bound {
+            TypeBound::Path(path) => {
+                bindings = TraitRef::from_path(ctx, path, Some(self_ty));
+                Some(
+                    bindings.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented),
+                )
+            }
+            TypeBound::Lifetime(_) => None,
+            TypeBound::Error => Some(GenericPredicate::Error),
+        };
+        trait_ref.into_iter().chain(
+            bindings
+                .into_iter()
+                .flat_map(move |tr| assoc_type_bindings_from_type_bound(ctx, bound, tr)),
+        )
     }
 }
 
index 80e795fbfd4a72aa2a96bea7ed054c78c196602c..659b8fce9ce5e126529591cb2381e1b0961df3c6 100644 (file)
@@ -1114,14 +1114,14 @@ fn method_on_dyn_impl() {
 trait Foo {}
 
 impl Foo for u32 {}
-impl dyn Foo {
+impl dyn Foo + '_ {
     pub fn dyn_foo(&self) -> u32 {
         0
     }
 }
 
 fn main() {
-    let f = &42u32 as &dyn Foo<u32>;
+    let f = &42u32 as &dyn Foo;
     f.dyn_foo();
   // ^u32
 }
index 7fce441f24d4b90b97e0e288ec16391d1e0b0abf..744fb5ff29506b10ba218931f0d9454a5fc19159 100644 (file)
@@ -1409,10 +1409,10 @@ trait Trait {}
         fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) {}
         "#,
         expect![[r#"
-            23..24 'a': impl Trait + {error}
-            50..51 'b': impl {error}
+            23..24 'a': impl Trait
+            50..51 'b': impl 
             69..70 'c': impl Trait
-            86..87 'd': impl {error}
+            86..87 'd': impl 
             107..108 'e': impl {error}
             123..124 'f': impl Trait + {error}
             147..149 '{}': ()
index 69b828f477fda1bf7a3efd5db90987569c4a71f8..9a605b09d08a1d46f4dd4edc45c4d1b455ae29f1 100644 (file)
@@ -3417,7 +3417,7 @@ impl<T> Foo<T$0> {}
                 ```
                 "#]],
         );
-        // lifetimes aren't being substituted yet
+        // lifetimes bounds arent being tracked yet
         check(
             r#"
 struct Foo<T>(T);
@@ -3427,7 +3427,7 @@ impl<T: 'static> Foo<T$0> {}
                 *T*
 
                 ```rust
-                T: {error}
+                T
                 ```
                 "#]],
         );