-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve E0389 "cannot borrow data mutably in a &
reference" error message
#38147
Comments
&
reference" error message&
reference" error message
How would you improve it? It seems pretty clear for me. :-/ |
I think not will be helpful
and for sample from tests
I'm not sure it's easy to do, but I'll try. |
Oh, I actually proposed such a change here. Still some little things to debate. |
@GuillaumeGomez I don't understand how its related, are you already work on it? |
It's the first step. It suggests references and stuff. However, if the variable isn't mutable, it won't say "make your variable mutable and then use &mut". This step will need to be added. |
Point to immutable arg/fields when trying to use as &mut Present the following output when trying to access an immutable borrow's field as mutable: ``` error[E0389]: cannot borrow data mutably in a `&` reference --> $DIR/issue-38147-1.rs:27:9 | 26 | fn f(&self) { | ----- use `&mut self` here to make mutable 27 | f.s.push('x'); | ^^^ assignment into an immutable reference ``` And the following when trying to access an immutable struct field as mutable: ``` error: cannot borrow immutable borrowed content `*self.s` as mutable --> $DIR/issue-38147-3.rs:17:9 | 12 | s: &'a String | ------------- use `&'a mut String` here to make mutable ...| 16 | fn f(&self) { | ----- use `&mut self` here to make mutable 17 | self.s.push('x'); | ^^^^^^ cannot borrow as mutable ``` Fixes #38147.
Error in next case could be more helpful
error:
cc @jonathandturner
The text was updated successfully, but these errors were encountered: