You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Confusing error message suggestion when invoking mutable trait method implemented by a mutable reference #83241
error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
--> src/lib.rs:11:5
|
11 | f.bar();
| ^
| |
| cannot borrow as mutable
| try removing `&mut` here
error: aborting due to previous error
The suggestion to remove &mut is quite confusing and does not appear actionable unless it means removing &mut from the declaration of fn bar(&mut self);. I believe the correct fix is to add a mut before the argument in baz:
pubfnbaz(mutf:&mutString){
f.bar();}
Ideally the output should be similar to the case where the trait is implemented by something that is not a mutable reference:
error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
--> src/lib.rs:11:5
|
10 | pub fn baz(f: String) {
| - help: consider changing this to be mutable: `mut f`
11 | f.bar();
| ^ cannot borrow as mutable
error: aborting due to previous error
Activity
Suggestion for call on immutable binding of mutable type
Rollup merge of rust-lang#83251 - estebank:issue-83241, r=oli-obk