rust-lang / rust-lang/rust

Implementing generic trait for dyn T is not allowed when a supertrait with different type parameter is present

Open
#149,364 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-dyn-trait A-trait-system C-bug needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

mod supertrait {
    trait V<T> {}
    trait A : V<u32> {}
    struct T {}
    impl A for T {}
    impl V<u32> for T {}
    impl V<i32> for dyn A {} // `(dyn A + 'static)` automatically implements trait `V`
}

mod nosupertrait {
    trait V<T> {}
    trait A {}
    struct T {}
    impl A for T {}
    impl V<u32> for T {}
    impl V<i32> for dyn A {} // ok
}

I expected to see this happen: No error in either case.

Instead, this happened: Using a supertrait causes the compiler to complain about auto implemented trait as if type parameters are not being taken into account.

Meta

rustc --version --verbose:

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-pc-windows-msvc
release: 1.88.0
LLVM version: 20.1.5
Backtrace

<backtrace>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the minimized Rust example from the issue with rustc 1.88.0 and confirm that the supertrait case fails while the nosupertrait case succeeds. Trace the compiler's handling of the generic trait implementation for dyn A and its supertrait obligations; done means both examples compile without incorrectly treating V as V.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.