The following fails to compile:
pub trait Iter {
type Item;
}
impl<'x, I> Iter for I
where
I: IntoIterator<Item = &'x str>,
{
type Item = &'x str;
}
pub struct Map<I>(I)
where
I: Iter,
I::Item: 'static;
fn test(_: Map<Vec<&str>>) {}
//~^ ERROR needs to satisfy a `'static` lifetime requirement
while changing the Iter impl to use a paramter type X instead of the lifetime 'x makes it compile:
// ...
impl<X, I> Iter for I
where
I: IntoIterator<Item = X>,
{
type Item = X;
}
// ...
This is because we are ignoring projection predicates that constrain region variables while using those that constrain type variables:
|
if obligation.predicate.has_non_region_infer() { |
|
match obligation.predicate.kind().skip_binder() { |
|
ty::PredicateKind::Clause(ty::Clause::Projection(..)) |
|
| ty::PredicateKind::AliasRelate(..) => { |
|
ocx.register_obligation(obligation.clone()); |
|
} |
|
_ => {} |
|
} |
|
} |
Should be fixed by #109482.
The following fails to compile:
while changing the
Iterimpl to use a paramter typeXinstead of the lifetime'xmakes it compile:This is because we are ignoring projection predicates that constrain region variables while using those that constrain type variables:
rust/compiler/rustc_traits/src/implied_outlives_bounds.rs
Lines 86 to 94 in 8a7ca93
Should be fixed by #109482.