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

Impl has "stricter" requirement that is implied by existing requirement #134890

Open
LHolten opened this issue Dec 29, 2024 · 0 comments
Open

Impl has "stricter" requirement that is implied by existing requirement #134890

LHolten opened this issue Dec 29, 2024 · 0 comments
Assignees
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-trait-system Area: Trait system C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@LHolten
Copy link

LHolten commented Dec 29, 2024

I tried this code:

trait Foo {
    type Assoc;

    fn bar<'x>()
    where
        Self::Assoc: 'x;
}

impl<A: Foo> Foo for Option<A> {
    type Assoc = Option<A::Assoc>;

    fn bar<'x>()
    where
        Self::Assoc: 'x,
    {
        todo!()
    }
}

I expect this to compile, but it gives the following error

error[E0276]: impl has stricter requirements than trait
  --> src/lib.rs:14:22
   |
4  | /     fn bar<'x>()
5  | |     where
6  | |         Self::Assoc: 'x;
   | |________________________- definition of `bar` from trait
...
14 |           Self::Assoc: 'x,
   |                        ^^ impl has extra requirement `<A as Foo>::Assoc: 'x`

The extra requirement <A as Foo>::Assoc: 'x that it mentions is actually implied by the real requirement Self::Assoc: 'x.
I think rust should always accept trait impls that have the exact same bounds as the trait defintion, that is why I labeled this as a bug.

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (426d17342 2024-12-21)
binary: rustc
commit-hash: 426d1734238e3c5f52e935ba4f617f3a9f43b59d
commit-date: 2024-12-21
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6

Same result on stable

@LHolten LHolten added the C-bug Category: This is a bug. label Dec 29, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 29, 2024
@fmease fmease added A-trait-system Area: Trait system 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 Dec 29, 2024
@compiler-errors compiler-errors self-assigned this Dec 31, 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 A-trait-system Area: Trait system C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants