Skip to content

Commit 9e5192d

Browse files
committed
Don't lower TypeBound::Lifetime as GenericPredicate::Error
1 parent ba3a5c5 commit 9e5192d

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

crates/hir_ty/src/lower.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -655,17 +655,6 @@ impl TraitRef {
655655
) -> Substs {
656656
substs_from_path_segment(ctx, segment, Some(resolved.into()), false)
657657
}
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-
}
669658
}
670659

671660
impl GenericPredicate {
@@ -705,13 +694,22 @@ impl GenericPredicate {
705694
bound: &'a TypeBound,
706695
self_ty: Ty,
707696
) -> impl Iterator<Item = GenericPredicate> + 'a {
708-
let trait_ref = TraitRef::from_type_bound(ctx, bound, self_ty);
709-
iter::once(trait_ref.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented))
710-
.chain(
711-
trait_ref
712-
.into_iter()
713-
.flat_map(move |tr| assoc_type_bindings_from_type_bound(ctx, bound, tr)),
714-
)
697+
let mut bindings = None;
698+
let trait_ref = match bound {
699+
TypeBound::Path(path) => {
700+
bindings = TraitRef::from_path(ctx, path, Some(self_ty));
701+
Some(
702+
bindings.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented),
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+
)
715713
}
716714
}
717715

crates/hir_ty/src/tests/method_resolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,14 +1114,14 @@ fn method_on_dyn_impl() {
11141114
trait Foo {}
11151115
11161116
impl Foo for u32 {}
1117-
impl dyn Foo {
1117+
impl dyn Foo + '_ {
11181118
pub fn dyn_foo(&self) -> u32 {
11191119
0
11201120
}
11211121
}
11221122
11231123
fn main() {
1124-
let f = &42u32 as &dyn Foo<u32>;
1124+
let f = &42u32 as &dyn Foo;
11251125
f.dyn_foo();
11261126
// ^u32
11271127
}

crates/hir_ty/src/tests/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,10 +1409,10 @@ fn weird_bounds() {
14091409
fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) {}
14101410
"#,
14111411
expect![[r#"
1412-
23..24 'a': impl Trait + {error}
1413-
50..51 'b': impl {error}
1412+
23..24 'a': impl Trait
1413+
50..51 'b': impl
14141414
69..70 'c': impl Trait
1415-
86..87 'd': impl {error}
1415+
86..87 'd': impl
14161416
107..108 'e': impl {error}
14171417
123..124 'f': impl Trait + {error}
14181418
147..149 '{}': ()

crates/ide/src/hover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,7 +3417,7 @@ impl<T> Foo<T$0> {}
34173417
```
34183418
"#]],
34193419
);
3420-
// lifetimes aren't being substituted yet
3420+
// lifetimes bounds arent being tracked yet
34213421
check(
34223422
r#"
34233423
struct Foo<T>(T);
@@ -3427,7 +3427,7 @@ impl<T: 'static> Foo<T$0> {}
34273427
*T*
34283428
34293429
```rust
3430-
T: {error}
3430+
T
34313431
```
34323432
"#]],
34333433
);

0 commit comments

Comments
 (0)