-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Invalid "variable does not need to be mutable" warning in 2018 edition with partially initialized structs #54499
Comments
I think the error (that partial initialization requires |
So, we decided to echo existing borrowck behavior here, which does require a The simplest thing would be to update the "mut checker" to understand this limitation, I suppose. The more complex thing would be to try and fix #21232 — this feels like something we might consider, as NLL is reaching a decent point. |
In terms of how to suppress the false warning, here are a few tips: The rust/src/librustc_mir/borrow_check/mod.rs Lines 436 to 438 in c9865b1
So we probably need to add something to that set when we see rust/src/librustc_mir/borrow_check/mod.rs Lines 493 to 499 in c9865b1
Here we special case out assignments to immutable local variables (not this case): rust/src/librustc_mir/borrow_check/mod.rs Lines 1094 to 1108 in c9865b1
and then fall through to rust/src/librustc_mir/borrow_check/mod.rs Lines 1110 to 1117 in c9865b1
Something in there must be failing to update |
@xfix out of curiosity, how did you notice this bug? Are you relying on the current behavior of being able to assign to (but not read from) a field of an uninitialized variable? |
@nikomatsakis I just like abusing compiler edge cases hoping to find bugs, this isn't from an actual program. |
…#54986. Treat attempt to partially intialize local `l` as uses of a `mut` in `let mut l;`, to fix rust-lang#54499.
This commit makes two changes: First, it updates the dataflow builder to add an init for the place containing a union if there is an assignment into the field of that union. Second, it stops a "use of uninitialized" error occuring when there is an assignment into the field of an uninitialized union that was previously initialized. Making this assignment would re-initialize the union, as tested in `src/test/ui/borrowck/borrowck-union-move-assign.nll.stderr`. The check for previous initialization ensures that we do not start supporting partial initialization yet (cc rust-lang#21232, rust-lang#54499, rust-lang#54986).
NLL Diagnostic Review 3: Unions not reinitialized after assignment into field Fixes #55651, #55652. This PR makes two changes: First, it updates the dataflow builder to add an init for the place containing a union if there is an assignment into the field of that union. Second, it stops a "use of uninitialized" error occuring when there is an assignment into the field of an uninitialized union that was previously initialized. Making this assignment would re-initialize the union, as tested in `src/test/ui/borrowck/borrowck-union-move-assign.nll.stderr`. The check for previous initialization ensures that we do not start supporting partial initialization yet (cc #21232, #54499, #54986). This PR also fixes #55652 which was marked as requiring investigation as the changes in this PR add an error that was previously missing (and mentioned in the review comments) and confirms that the error that was present is correct and a result of earlier partial initialization changes in NLL. r? @pnkfelix (due to earlier work with partial initialization) cc @nikomatsakis
Causes the following warning:
Removing
mut
causes an error:Tested on nightly on the playground. This code is stupid, but I don't think it should report "unused mut" warnings.
The text was updated successfully, but these errors were encountered: