-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
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:
rust/compiler/rustc_traits/src/implied_outlives_bounds.rs
Lines 86 to 94 in 8a7ca93
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.
Metadata
Metadata
Assignees
Labels
A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.