Incorrect "conflicting implementations" error between two non-overlapping blanket impls
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
pub trait Pod: Copy + 'static {}
pub trait Marshal {}
impl<T> Marshal for T where T: Pod {}
impl<T> Marshal for &mut T where T: Pod {}
I expected to see this happen: Compiles.
Instead, this happened:
error[E0119]: conflicting implementations of trait `Marshal` for type `&mut _`
--> src/lib.rs:6:1
|
5 | impl<T> Marshal for T where T: Pod {}
| ---------------------------------- first implementation here
6 | impl<T> Marshal for &mut T where T: Pod {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&mut _`
|
= note: downstream crates may implement trait `std::clone::Clone` for type `&mut _`
= note: downstream crates may implement trait `std::marker::Copy` for type `&mut _`
= note: downstream crates may implement trait `Pod` for type `&mut _`
Notably, the notes are simply wrong: while it is possible to implement some upstream traits for &mut T as long as T is local (since &mut T is fundamental), a Clone or Copy impl cannot be written for any mutable reference type, since libcore has a negative impl !Clone for &mut T.
Attempting to do so anyways will yield "error[E0751]: found both positive and negative implementation of trait Clone for type &mut S".
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
Start by running the reproducer in src/lib.rs and examining the E0119 diagnostic for the two blanket implementations. Trace how the compiler reasons about downstream Clone, Copy, and Pod implementations for &mut T. Done means the non-overlapping implementations compile or the diagnostic no longer makes the incorrect claims described here.
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
- 38/100