Skip to content

incomplete normalization in implied bounds #109799

Closed
@aliemjay

Description

@aliemjay

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-implied-boundsArea: Implied bounds / inferred outlives-boundsC-bugCategory: This is a bug.T-compilerRelevant 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions