Trait implementations error message confusing when taking a reference of a reference
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
trait GenericImage {}
trait Canvas {}
impl<I> Canvas for I
where
I: GenericImage,
{}
pub fn draw<C>(canvas: &mut C)
where
C: Canvas,
{
draw_filled_rect_mut(&mut canvas);
}
pub fn draw_filled_rect_mut<C>(_canvas: &mut C)
where
C: Canvas,
{
todo!()
}
Current output
error[E0277]: the trait bound `&mut C: Canvas` is not satisfied
--> src/lib.rs:14:26
|
14 | draw_filled_rect_mut(&mut canvas);
| -------------------- ^^^^^^^^^^^ the trait `GenericImage` is not implemented for `&mut C`
| |
| required by a bound introduced by this call
|
help: this trait has no implementations, consider adding one
--> src/lib.rs:1:1
|
1 | trait GenericImage {}
| ^^^^^^^^^^^^^^^^^^
note: required for `&mut C` to implement `Canvas`
--> src/lib.rs:4:9
|
4 | impl<I> Canvas for I
| ^^^^^^ ^
5 | where
6 | I: GenericImage,
| ------------ unsatisfied trait bound introduced here
note: required by a bound in `draw_filled_rect_mut`
--> src/lib.rs:19:8
|
17 | pub fn draw_filled_rect_mut<C>(_canvas: &mut C)
| -------------------- required by a bound in this function
18 | where
19 | C: Canvas,
| ^^^^^^ required by this bound in `draw_filled_rect_mut`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 1 previous error
Desired output
error[E0277]: the trait bound `&mut C: Canvas` is not satisfied
--> src/lib.rs:14:26
|
14 | draw_filled_rect_mut(&mut canvas);
| -------------------- ^^^^^^^^^^^ the trait `GenericImage` is not implemented for `&mut C`
| |
| required by a bound introduced by this call
|
help: The trait-bound is satisfied for `canvas`, but not `&mut canvas`.
Rationale and extra context
No response
Other cases
Rust Version
Tested in playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=beb18623866b4914d0da0fce16a2e4f0
Build using the Nightly version: 1.91.0-nightly
(2025-08-29 fe55364329579d361b1a)
Anything else?
No response
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 diagnostic with the provided src/lib.rs example in the Rust Playground, starting at draw and draw_filled_rect_mut. Compare the current E0277 output with the requested concise help message and trace the compiler diagnostic path responsible for the trait-bound explanation. Done means the reference-of-a-reference case emits the requested guidance without the current verbose suggestions.
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
- 45/100