-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add detailed error explanation for E0389 #33412
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Aatch (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -286,6 +286,54 @@ You can read more about cell types in the API documentation: | |||
https://doc.rust-lang.org/std/cell/ | |||
"##, | |||
|
|||
E0389: r##" | |||
An attempt was made to assign to data in a non-mutable reference. Example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very clear. Also, you have to write "Example of erroneous code" and not just "Example" as stated by the RFC. It's to keep error explanations homogeneous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. The RFC doesn't seem particularly consistent-- it uses "Example of erroneous code:", "Erroneous code example:", and other errors currently in the same file as E0389 & co. use "For example:", and "Example:". It makes sense to have a standard, though, so perhaps there should be a PR changing the old ones. I can take a look at that after this one if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but before I'd prefer this RFC to be definitely accepted. Once done, you can do it if you want (it'd be very appreciated actually!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. In that case, do you want to modify the RFC to change line 86 to say "Example of erroneous code:"?
Thanks for your work! Please fix the errors and then it should be good to get merged. |
@GuillaumeGomez Done. Squash? |
@@ -286,6 +286,66 @@ You can read more about cell types in the API documentation: | |||
https://doc.rust-lang.org/std/cell/ | |||
"##, | |||
|
|||
E0389: r##" | |||
An attempt was made to mutate data using a non-mutable reference. This | |||
commonly occurs when attempting to assign to a reference of type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your second sentence is a bit unwieldly. What do you think of: "This commonly occurs when attempting to assign to a non-mutable reference of a mutable reference"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha that sounds crazy to me-- that's why I just wrote the type out directly ("a non-mutable reference of a mutable reference" vs. &(&mut T)
). But if you prefer, I'm happy to change it as I don't think it's going to greatly confuse anyone either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typecit out and keep the code in a parenthetical 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it when we can get the best of both worlds 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're demons! 😨
Yes please. |
868dfe7
to
04b45ad
Compare
} | ||
``` | ||
|
||
Here, `&mut fancy` is mutable, but `&(&mut fancy)` is not. To fix this, either |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide a more in-depth explanation as to why &&mut is immutable? This can trip up newcomers who come across it, since it looks like the inner value should be mutable.
(It isn't because &&mut can be aliased, which means that &T transitively makes all mutable references inside it immutable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about, "Creating an immutable reference to a value borrows that value immutably, so neither it nor its contents can be modified." (Should I mention interior mutability?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Creating an immutable reference to a value borrows it immutably, so neither it nor its contents can be modified." (a little better from my point of view 😉 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
@Manishearth: Seems good for me now. |
@GuillaumeGomez where's the in-depth explanation? |
The point here is that The reason that it's not allowed is a bit nuanced. |
@Manishearth: I thought "Here, |
@Manishearth I don't think the "alias" explanation is particularly transparent. I personally prefer the explanation that I provided (the one @GuillaumeGomez referenced). If anything, I think a further clarification might include that there can be multiple references of type |
Yes, that further clarification is what I was looking for. I used alias whilst explaining the concept I felt should be included to you, not intending it to be included in the text 😄rust-lang/rust wrote:@Manishearth I don't think the "alias" explanation is particularly transparent. I personally prefer the explanation that I provided (the one @GuillaumeGomez referenced). If anything, I think a further clarification might include that there can be multiple references of type &(&mut T), so it must be immutable to prevent multiple mutable references to the same value (equivalent to aliasing, but less confusing terminology IMO). —You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub |
Ah, okay. I'll add that then. |
@GuillaumeGomez that doesn't explain why |
Cleanup of E0389 Added type-d out version of type in E0389 description
Change made. |
@bors r+ rollup |
📌 Commit f25cbe6 has been approved by |
Add detailed error explanation for E0389 Part of rust-lang#32777
Add detailed error explanation for E0389 Part of rust-lang#32777
Add detailed error explanation for E0389 Part of rust-lang#32777
Part of #32777