Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incomplete normalization in implied bounds #109799

Closed
aliemjay opened this issue Mar 31, 2023 · 0 comments · Fixed by #118553
Closed

incomplete normalization in implied bounds #109799

aliemjay opened this issue Mar 31, 2023 · 0 comments · Fixed by #118553
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@aliemjay
Copy link
Member

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.

@aliemjay aliemjay added C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue. A-implied-bounds Area: Implied bounds / inferred outlives-bounds labels Mar 31, 2023
rust-cloud-vms bot pushed a commit to aliemjay/rust that referenced this issue Mar 31, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 1, 2023
… r=petrochenkov

add test for normalization in implied bounds query

See rust-lang#109799.
oli-obk pushed a commit to oli-obk/miri that referenced this issue Apr 4, 2023
…henkov

add test for normalization in implied bounds query

See rust-lang/rust#109799.
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
2 participants