Skip to content

incomplete normalization in implied bounds #109799

Closed

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.

Activity

  1. added
    C-bugCategory: This is a bug.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    A-implied-boundsArea: Implied bounds / inferred outlives-bounds
    on Mar 31, 2023
  2. added a commit that references this issue on Apr 1, 2023
  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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