Confusing error message when a trait bound is unsatisfied due to lack of mutability #63619
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-trait-system
Area: Trait system
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
In this code,
fp
should have been declared as a mutable reference, and the compiler gives you a nice clear error message saying so:⟶
But you have a BufWriter in between
writeln!
and the match, you get a different and very confusing error message:⟶
How can it possibly be that "the trait
std::io::Write
is not implemented for&dyn std::io::Write
" ?! Well, in fact, it's the exact same problem as the first sample code, and the error message is literally true.&dyn std::io::Write
doesn't implementstd::io::Write
, but&mut dyn std::io::Write
does.Could the compiler perhaps print an additional note when
&T
doesn't satisfy a trait bound, but&mut T
would have, explaining that this might be the problem? Or vice versa, of course.The text was updated successfully, but these errors were encountered: