Skip to content

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

Open
@LHolten

Description

@LHolten
Contributor

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

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Dec 29, 2024
added
T-typesRelevant to the types team, which will review and decide on the PR/issue.
A-implied-boundsArea: Implied bounds / inferred outlives-bounds
on Dec 29, 2024
added
S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-implied-boundsArea: Implied bounds / inferred outlives-boundsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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

      Participants

      @compiler-errors@fmease@LHolten@jieyouxu@rustbot

      Issue actions

        Impl has "stricter" requirement that is implied by existing requirement · Issue #134890 · rust-lang/rust