-
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 error explanation for E0070 #25552
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
e533190
to
c0da2bd
Compare
SOME_NOT_CONST = 14; // that's good ! | ||
let mut i : i32 = 1; | ||
|
||
i = 3; // that's good ! |
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.
This line seems redundant. Seems like the let mut i : i32 = 1;
line would suffice for demonstrating a good assignment.
Edit: Now that I think about it, do we need more than one example of an assignment? I'd imagine the idea of assignment should be pretty familiar to even the newest of Rust programmers. The following code may be enough:
static mut SOME_NOT_CONST : i32 = 12;
fn main() {
SOME_NOT_CONST = 14;
}
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 just wanted to give multiple example cases, I think it's always better. People could think that only const variables could be concerned by this error, I want to avoid that.
f1e36ff
to
26bb333
Compare
☔ The latest upstream changes (presumably #25501) made this pull request unmergeable. Please resolve the merge conflicts. |
26bb333
to
d7749da
Compare
@nham is as much leading the charge as me now 😄 (I've been a bit sick, and busy doing other things) |
enum variant, one of the fields was not provided. Each field should be specified | ||
exactly once. | ||
enum variant, one of the fields was not provided. Each field should be | ||
specified exactly once. |
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 suspect your text editor has done the wrapping here, but these lines of 80 chars are actually fine.
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 didn't even see that. I must have failed my wrapping somewhere... Well, if it is needed, I can undo this. ^^
d7749da
to
7c7e42a
Compare
@michaelsproul @nham @pnkfelix: Do you see anything else which would need to be improved/changed ? |
I cannot tell from reading the diff how E0070 differs from E0067. That to me may be a hint that either we have redundant error codes or that something is missing from their explanatory text. |
E0067 is about "+=" while E0070 is about "=". That's the only difference. @nham told me to take a look at it to help me writing this one, which I did. |
@GuillaumeGomez ah, I see now. In that case, the main changes I would suggest are:
|
@pnkfelix: Wo thanks a lot ! I didn't write E0067 so I'll create a second commit (not PR) to add the changes you proposed. (x, y) = (1, 2); // you cannot do this (at least not today; there may be a postponed RFC asking for it)
// -> it seems logical since you have to declare it before
let (x, y) = (1, 2); // but you can do this
// -> which is done here
let x.foo = 3; // you cannot do this (and almost certainly never will be able to)
// -> you can't allocate just a sub element of a struct without allocating the struct
x.foo = 3; // but you can do this
// -> it's just assigning a value to a sub element of an allocated struct So that's where I don't follow you. |
FYI: When I wrote: (x, y) = (1, 2); it was meant to be in the context of either
or
Anyway, we worked this out over IRC, but the summary is:
|
I'll remove the concerned examples and replace them by others. |
If you feel like including the "fix" to E0067 in this PR, i'll probably approve it (i.e. no need to file an entirely separate PR). The improvements are sort of coupled, after all (since it is clarifying that one message is about assignments and the other is about compound assignments). |
Yes, since it's nearly the same error, it wouldn't make sense to create another PR just for a fix. Thanks for your help ! :-) |
7c7e42a
to
d644f68
Compare
@pnkfelix: I updated the examples. Does that seem good to you ? |
The left-hand side of an assignment operator must be an lvalue expression. An | ||
lvalue expression represents a memory location and includes item paths (ie, | ||
namespaced variables), dereferences, indexing expressions, and field references. | ||
The left-hand side of a compound assignment expression (or compound assignment |
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 didn't mean for you to write "expression (or operator)". Just pick one, please.
(Because I think its confusing in this text to have it be open ended...)
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 couldn't decide... Well, I'll go for the first one then !
the examples look good to me. I'll be happy with the above nit addressed. |
d644f68
to
db9b435
Compare
@pnkfelix: Fixed ! |
Part of #24407.