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

bounds on trait impls are used in implied bounds #109628

Open
aliemjay opened this issue Mar 26, 2023 · 2 comments · Fixed by #118553
Open

bounds on trait impls are used in implied bounds #109628

aliemjay opened this issue Mar 26, 2023 · 2 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 compiles although it shouldn't:

trait Trait {
    type Assoc;
}

impl<T: 'static> Trait for Box<T> {
    type Assoc = ();
}

struct MyTy<U>(U)
where
    U: Trait,
    U::Assoc: Sized, // any predicate naming U::Assoc
;

fn fn_test<T>(_: MyTy<Box<T>>) {}

fn_test should fail with an error requiring an explicit T: 'static bound.

This is a compiler bug for the following reasons:

  • It certainly does not follow from the rules of RFC 1214 and RFC 2089. The implied bounds from a trait reference (Box<T>: Trait) includes only the where-clauses of the trait itself, not the trait impl.
  • It breaks stability guarantees in the sense that relaxing region constraints on trait impls is now a breaking change. Removing the useless bound U::Assoc: Sized is also a breaking change.
  • It requires remote reasoning when dealing with implied bounds.
  • It is a surprising behavior: why does the trivial bound U::Assoc: Sized make any meaningful difference?
@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 26, 2023
aliemjay added a commit to aliemjay/rust that referenced this issue Mar 26, 2023
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 17, 2023
…, r=lcnr

ignore implied bounds with placeholders

given the following code:
```rust
trait Trait {
    type Ty<'a> where Self: 'a;
}

impl<T> Trait for T {
    type Ty<'a> = () where Self: 'a;
}

struct Foo<T: Trait>(T)
where
    for<'x> T::Ty<'x>: Sized;
```

when computing the implied bounds from `Foo<X>` we incorrectly get the bound `X: !x` from the normalization of ` for<'x> <X as Trait>::Ty::<'x>: Sized`. This is a a known bug! we shouldn't use the constraints that arise from normalization as implied bounds. See rust-lang#109628.

Ignore these bounds for now. This should prevent later ICEs.

Fixes rust-lang#112250
Fixes rust-lang#107409
@jackh726
Copy link
Member

jackh726 commented Nov 29, 2023

Just for reference: This is a stable-to-stable regression, first passing in 1.29.0.

🤷‍♀️ on adding the label

@lcnr
Copy link
Contributor

lcnr commented Jan 19, 2024

this still applies to bevy and during MIR typeck due to #119956, reopening.

@lcnr lcnr reopened this Jan 19, 2024
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
4 participants