Rollup merge of #87403 - LeSeulArtichaut:assign-dropping-union, r=oli-obk

Implement `AssignToDroppingUnionField` in THIR unsafeck

r? ``@oli-obk`` cc rust-lang/project-thir-unsafeck#7
This commit is contained in:
Manish Goregaokar 2021-07-24 09:52:01 -07:00 committed by GitHub
commit 075d3a15b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 20 deletions

View file

@ -36,8 +36,8 @@ fn deref_union_field(mut u: URef) {
fn assign_noncopy_union_field(mut u: URefCell) {
// FIXME(thir-unsafeck)
u.a = (RefCell::new(0), 1); //[mir]~ ERROR assignment to union field that might need dropping
u.a.0 = RefCell::new(0); //[mir]~ ERROR assignment to union field that might need dropping
u.a = (RefCell::new(0), 1); //~ ERROR assignment to union field that might need dropping
u.a.0 = RefCell::new(0); //~ ERROR assignment to union field that might need dropping
u.a.1 = 1; // OK
}

View file

@ -6,6 +6,22 @@ LL | *(u.p) = 13;
|
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
error[E0133]: assignment to union field that might need dropping is unsafe and requires unsafe function or block
--> $DIR/union-unsafe.rs:39:5
|
LL | u.a = (RefCell::new(0), 1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to union field that might need dropping
|
= note: the previous content of the field will be dropped, which causes undefined behavior if the field was not properly initialized
error[E0133]: assignment to union field that might need dropping is unsafe and requires unsafe function or block
--> $DIR/union-unsafe.rs:40:5
|
LL | u.a.0 = RefCell::new(0);
| ^^^^^^^^^^^^^^^^^^^^^^^ assignment to union field that might need dropping
|
= note: the previous content of the field will be dropped, which causes undefined behavior if the field was not properly initialized
error[E0133]: access to union field is unsafe and requires unsafe function or block
--> $DIR/union-unsafe.rs:47:6
|
@ -70,6 +86,6 @@ LL | *u3.a = String::from("new");
|
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
error: aborting due to 9 previous errors
error: aborting due to 11 previous errors
For more information about this error, try `rustc --explain E0133`.