Invalid suggestion to change &self
to &mut self
in trait implementation
#68049
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
A-trait-system
Area: Trait system
C-bug
Category: This is a bug.
D-invalid-suggestion
Diagnostics: A structured suggestion resulting in incorrect code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Summary: The compiler suggests changing
&self
to&mut self
when trying to modifyself
in a method. For trait implemantions this does not work because it would require changing the trait definition too (which is often not possible).Example:
I was trying to implement the
GlobalAllocator
trait from the standard library for a custom type:(playground)
This of course doesn't work since you can't modify data behind a
&self
reference:However, I noticed that the help message suggests changing the
&self
to&mut self
, which is incorrect since that would require changing the trait definition in the standard library too.Suggestion: I don't know if this is possible, but maybe this help message should only be shown for "normal" methods and hidden when implementing trait methods?
The text was updated successfully, but these errors were encountered: