Don't lower TypeBound::Lifetime as GenericPredicate::Error

This commit is contained in:
Lukas Wirth 2021-02-20 18:51:42 +01:00
parent ba3a5c518a
commit 9e5192d917
4 changed files with 23 additions and 25 deletions

View file

@ -655,17 +655,6 @@ impl TraitRef {
) -> Substs { ) -> Substs {
substs_from_path_segment(ctx, segment, Some(resolved.into()), false) 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 { impl GenericPredicate {
@ -705,10 +694,19 @@ impl GenericPredicate {
bound: &'a TypeBound, bound: &'a TypeBound,
self_ty: Ty, self_ty: Ty,
) -> impl Iterator<Item = GenericPredicate> + 'a { ) -> impl Iterator<Item = GenericPredicate> + 'a {
let trait_ref = TraitRef::from_type_bound(ctx, bound, self_ty); let mut bindings = None;
iter::once(trait_ref.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented)) let trait_ref = match bound {
.chain( TypeBound::Path(path) => {
trait_ref 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() .into_iter()
.flat_map(move |tr| assoc_type_bindings_from_type_bound(ctx, bound, tr)), .flat_map(move |tr| assoc_type_bindings_from_type_bound(ctx, bound, tr)),
) )

View file

@ -1114,14 +1114,14 @@ fn method_on_dyn_impl() {
trait Foo {} trait Foo {}
impl Foo for u32 {} impl Foo for u32 {}
impl dyn Foo { impl dyn Foo + '_ {
pub fn dyn_foo(&self) -> u32 { pub fn dyn_foo(&self) -> u32 {
0 0
} }
} }
fn main() { fn main() {
let f = &42u32 as &dyn Foo<u32>; let f = &42u32 as &dyn Foo;
f.dyn_foo(); f.dyn_foo();
// ^u32 // ^u32
} }

View file

@ -1409,10 +1409,10 @@ fn weird_bounds() {
fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) {} fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) {}
"#, "#,
expect![[r#" expect![[r#"
23..24 'a': impl Trait + {error} 23..24 'a': impl Trait
50..51 'b': impl {error} 50..51 'b': impl
69..70 'c': impl Trait 69..70 'c': impl Trait
86..87 'd': impl {error} 86..87 'd': impl
107..108 'e': impl {error} 107..108 'e': impl {error}
123..124 'f': impl Trait + {error} 123..124 'f': impl Trait + {error}
147..149 '{}': () 147..149 '{}': ()

View file

@ -3417,7 +3417,7 @@ impl<T> Foo<T$0> {}
``` ```
"#]], "#]],
); );
// lifetimes aren't being substituted yet // lifetimes bounds arent being tracked yet
check( check(
r#" r#"
struct Foo<T>(T); struct Foo<T>(T);
@ -3427,7 +3427,7 @@ impl<T: 'static> Foo<T$0> {}
*T* *T*
```rust ```rust
T: {error} T
``` ```
"#]], "#]],
); );