Can't `impl Trait<i32> for dyn Trait<i64>`
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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