-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Compound assignment (+=
) on uninitialized variables is allowed
#12527
Comments
cc @flaper87 |
cc me |
If this were to be fixed as fn f3() {
let mut x = 3;
//~^ ERROR variable `x` is assigned to, but never used
x += 4;
//~^ ERROR value assigned to `x` is never read
}
fn f3b() {
let mut z = 3;
//~^ ERROR variable `z` is assigned to, but never used
loop {
z += 4;
}
} But it makes sense, doesn't it? |
@edwardw actually, that analysis (that gives those warnings) is completely separate, and I remember it drew some subtle distinctions regarding assignment vs use etc |
Very subtle indeed. I think I find the right compromise. |
No, this is the wrong approach. |
Well, let me review the code, but I think liveness should just have the job of warnings (in general I'd like to be able to |
Whoops, the patch has been half way through bors. |
@edwardw just to be clear, the patch you made is pretty reasonable, it's just that I've been moving responsibility for these sorts of checks to the borrow checker, which is probably not clear from the code. I think I didn't do a good job of finishing the job of simplifying liveness. Anyway the problem there is that the borrow checker classifies all expressions into assignees or uses, but this is both, so we need to change the move data to have a 3-way classification. It'd also be nice to remove all span_err's from liveness and make sure that my assertion that liveness is purely about warnings is actually true. Maybe there are other oversights in the borrow checker! |
I see. Let's see what I can do about that. |
r? |
Yeah, this looks good. I made a few minor suggestions. |
All comments addressed. r? |
- Repurposes `MoveData.assignee_ids` to mean only `=` but not `+=`, so that borrowck effectively classifies all expressions into assignees, uses or both. - Removes two `span_err` in liveness analysis, which are now borrowck's responsibilities. Closes #12527.
- Repurposes `MoveData.assignee_ids` to mean only `=` but not `+=`, so that borrowck effectively classifies all expressions into assignees, uses or both. - Removes two `span_err` in liveness analysis, which are now borrowck's responsibilities. Closes #12527.
Rustup r? `@ghost` changelog: none
This compiles:
Now, I can't seem to get that anything reads the value again to compile, but it seems like bad times anyway.
Thought to try this because of #12452.
The text was updated successfully, but these errors were encountered: