-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #87734 - Smittyvb:more-union-tests, r=LeSeulArtichaut
Test dropping union fields more Now that #87403 is merged, a few more tests can be added for reads/writes to dropping union fields. r? `@LeSeulArtichaut`
- Loading branch information
Showing
5 changed files
with
151 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-assignop.rs:20:5 | ||
| | ||
LL | foo.a += 5; | ||
| ^^^^^^^^^^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-assignop.rs:21:5 | ||
| | ||
LL | foo.b += Dropping; | ||
| ^^^^^ access to union field | ||
| | ||
= 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-assignop.rs:22:5 | ||
| | ||
LL | foo.b = Dropping; | ||
| ^^^^^^^^^^^^^^^^ 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-assignop.rs:23:5 | ||
| | ||
LL | foo.a; | ||
| ^^^^^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-assignop.rs:25:5 | ||
| | ||
LL | foo.b; | ||
| ^^^^^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-assignop.rs:27:13 | ||
| | ||
LL | foo.b = foo.b; | ||
| ^^^^^ access to union field | ||
| | ||
= 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-assignop.rs:27:5 | ||
| | ||
LL | foo.b = foo.b; | ||
| ^^^^^^^^^^^^^ 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: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// revisions: mirunsafeck thirunsafeck | ||
// [thirunsafeck]compile-flags: -Z thir-unsafeck | ||
|
||
#![feature(untagged_unions)] | ||
|
||
use std::ops::AddAssign; | ||
|
||
struct Dropping; | ||
impl AddAssign for Dropping { | ||
fn add_assign(&mut self, _: Self) {} | ||
} | ||
|
||
union Foo { | ||
a: u8, // non-dropping | ||
b: Dropping, // treated as dropping | ||
} | ||
|
||
fn main() { | ||
let mut foo = Foo { a: 42 }; | ||
foo.a += 5; //~ ERROR access to union field is unsafe | ||
foo.b += Dropping; //~ ERROR access to union field is unsafe | ||
foo.b = Dropping; //~ ERROR assignment to union field that might need dropping is unsafe | ||
foo.a; //~ ERROR access to union field is unsafe | ||
let foo = Foo { a: 42 }; | ||
foo.b; //~ ERROR access to union field is unsafe | ||
let mut foo = Foo { a: 42 }; | ||
foo.b = foo.b; | ||
//~^ ERROR access to union field is unsafe | ||
//~| ERROR assignment to union field that might need dropping | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-assignop.rs:20:5 | ||
| | ||
LL | foo.a += 5; | ||
| ^^^^^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-assignop.rs:21:5 | ||
| | ||
LL | foo.b += Dropping; | ||
| ^^^^^ access to union field | ||
| | ||
= 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-assignop.rs:22:5 | ||
| | ||
LL | foo.b = Dropping; | ||
| ^^^^^^^^^^^^^^^^ 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-assignop.rs:23:5 | ||
| | ||
LL | foo.a; | ||
| ^^^^^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-assignop.rs:25:5 | ||
| | ||
LL | foo.b; | ||
| ^^^^^ access to union field | ||
| | ||
= 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-assignop.rs:27:5 | ||
| | ||
LL | foo.b = foo.b; | ||
| ^^^^^^^^^^^^^ 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-assignop.rs:27:13 | ||
| | ||
LL | foo.b = foo.b; | ||
| ^^^^^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |