Skip to content

"conflicting implementations of trait" for two distinct types #142853

Open
@Dzuchun

Description

@Dzuchun

I tried this code:

trait T {}
impl T for <&'static i32 as core::ops::Deref>::Target {}
impl T for () {}

I expected to see this happen: successful compilation, since <&'static i32 as core::ops::Deref>::Target is i32 (clearly not ())

Instead, this happened: compilation failed with

error[E0119]: conflicting implementations of trait `T` for type `<&'static i32 as Deref>::Target`
 --> src/lib.rs:3:1
  |
2 | impl T for <&'static i32 as core::ops::Deref>::Target {}
  | --------------------------------------------- first implementation here
3 | impl T for () {}
  | ^^^^^^^^^^^^^ conflicting implementation for `<&'static i32 as Deref>::Target`

It should be noted, that substituting <&'static i32 as Deref>::Target for i32 removes the error, i.e. the following code compiles:

trait T {}
impl T for i32 {}
impl T for () {}

Meta

rustc --version --verbose:

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

In my testing, all of the following reproduced this behavior:

  • stable 1.87.0
  • beta 1.88.0-beta.5 (2025-06-01)
  • nightly 1.89.0-nightly (2025-06-11)

(no backtrace produced)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.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