rust-lang / rust-lang/rust

Can't `impl Trait<i32> for dyn Trait<i64>`

Open
#152,154 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-coherence A-dyn-trait A-trait-system C-bug T-lang T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

trait Trait<T> {}

impl Trait<i32> for dyn Trait<i64> {}

I expected the code to compile, but I got this error instead:

error[E0371]: the object type `(dyn Trait<i64> + 'static)` automatically implements the trait `Trait`
 --> src/lib.rs:3:1
  |
3 | impl Trait<i32> for dyn Trait<i64> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Trait<i64> + 'static)` automatically implements trait `Trait`

For more information about this error, try `rustc --explain E0371`.

I'm not sure if this is useful to allow, but I do find it strange that it's prohibited.

Even though we're implementing the trait on a trait object of that "same" trait, the generic parameter is different, so there should be no overlap.

Meta

Reproducible on the playground with version 1.95.0-nightly (2026-02-04 db3e99bbab28c6ca778b)

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

Reproduce the Rust snippet in the linked playground and read the rustc --explain E0371 output first. Investigate how trait objects and generic trait implementations are handled, then determine whether this impl should be accepted; done requires a decided language behavior with corresponding compiler coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.