Unions reinitialized after assignment into field.
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 #21232, #54499, #54986).
This commit is contained in:
parent
87a3c1ee70
commit
a4e0945621
4 changed files with 50 additions and 31 deletions
|
|
@ -8,28 +8,6 @@ LL | let a = u.a; //~ ERROR use of moved value: `u.a`
|
|||
|
|
||||
= note: move occurs because `u` has type `U`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `u`
|
||||
--> $DIR/borrowck-union-move-assign.rs:33:21
|
||||
|
|
||||
LL | let a = u.a;
|
||||
| --- value moved here
|
||||
LL | u.a = A;
|
||||
LL | let a = u.a; // OK
|
||||
| ^^^ value used here after move
|
||||
|
|
||||
= note: move occurs because `u` has type `U`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `u`
|
||||
--> $DIR/borrowck-union-move-assign.rs:39:21
|
||||
|
|
||||
LL | let a = u.a;
|
||||
| --- value moved here
|
||||
LL | u.b = B;
|
||||
LL | let a = u.a; // OK
|
||||
| ^^^ value used here after move
|
||||
|
|
||||
= note: move occurs because `u` has type `U`, which does not implement the `Copy` trait
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0382`.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,16 @@ error[E0381]: assign to part of possibly uninitialized variable: `x`
|
|||
LL | x.a = 1; //~ ERROR
|
||||
| ^^^^^^^ use of possibly uninitialized `x`
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0594]: cannot assign to `x.b`, as `x` is not declared as mutable
|
||||
--> $DIR/reassignment_immutable_fields_overlapping.rs:23:5
|
||||
|
|
||||
LL | let x: Foo;
|
||||
| - help: consider changing this to be mutable: `mut x`
|
||||
LL | x.a = 1; //~ ERROR
|
||||
LL | x.b = 22; //~ ERROR
|
||||
| ^^^^^^^^ cannot assign
|
||||
|
||||
For more information about this error, try `rustc --explain E0381`.
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors occurred: E0381, E0594.
|
||||
For more information about an error, try `rustc --explain E0381`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue