Skip to content

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

@alrz

Description

@alrz

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-dyn-traitArea: trait objects, vtable layoutA-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions