forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#85263 - Smittyvb:thir-unsafeck-union-field, r…
…=oli-obk Check for union field accesses in THIR unsafeck see also rust-lang#85259, rust-lang#83129, rust-lang/project-thir-unsafeck#7 r? `@LeSeulArtichaut`
- Loading branch information
Showing
72 changed files
with
1,095 additions
and
76 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 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 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 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 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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/issue-47412.rs:14:11 | ||
| | ||
LL | match u.void {} | ||
| ^^^^^^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block | ||
--> $DIR/issue-47412.rs:21:11 | ||
--> $DIR/issue-47412.rs:20:11 | ||
| | ||
LL | match *ptr {} | ||
| ^^^^ dereference of raw pointer | ||
| | ||
= note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 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
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 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 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 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
60 changes: 60 additions & 0 deletions
60
src/test/ui/union/union-borrow-move-parent-sibling.thirunsafeck.stderr
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,60 @@ | ||
error[E0502]: cannot borrow `u` (via `u.y`) as immutable because it is also borrowed as mutable (via `u.x.0`) | ||
--> $DIR/union-borrow-move-parent-sibling.rs:56:13 | ||
| | ||
LL | let a = &mut u.x.0; | ||
| ---------- mutable borrow occurs here (via `u.x.0`) | ||
LL | let b = &u.y; | ||
| ^^^^ immutable borrow of `u.y` -- which overlaps with `u.x.0` -- occurs here | ||
LL | use_borrow(a); | ||
| - mutable borrow later used here | ||
| | ||
= note: `u.y` is a field of the union `U`, so it overlaps the field `u.x.0` | ||
|
||
error[E0382]: use of moved value: `u` | ||
--> $DIR/union-borrow-move-parent-sibling.rs:63:13 | ||
| | ||
LL | let u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) }; | ||
| - move occurs because `u` has type `U`, which does not implement the `Copy` trait | ||
LL | let a = u.x.0; | ||
| ----- value moved here | ||
LL | let b = u.y; | ||
| ^^^ value used here after move | ||
|
||
error[E0502]: cannot borrow `u` (via `u.y`) as immutable because it is also borrowed as mutable (via `u.x.0.0`) | ||
--> $DIR/union-borrow-move-parent-sibling.rs:69:13 | ||
| | ||
LL | let a = &mut (u.x.0).0; | ||
| -------------- mutable borrow occurs here (via `u.x.0.0`) | ||
LL | let b = &u.y; | ||
| ^^^^ immutable borrow of `u.y` -- which overlaps with `u.x.0.0` -- occurs here | ||
LL | use_borrow(a); | ||
| - mutable borrow later used here | ||
| | ||
= note: `u.y` is a field of the union `U`, so it overlaps the field `u.x.0.0` | ||
|
||
error[E0382]: use of moved value: `u` | ||
--> $DIR/union-borrow-move-parent-sibling.rs:76:13 | ||
| | ||
LL | let u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) }; | ||
| - move occurs because `u` has type `U`, which does not implement the `Copy` trait | ||
LL | let a = (u.x.0).0; | ||
| --------- value moved here | ||
LL | let b = u.y; | ||
| ^^^ value used here after move | ||
|
||
error[E0502]: cannot borrow `u` (via `u.x`) as immutable because it is also borrowed as mutable (via `u.y`) | ||
--> $DIR/union-borrow-move-parent-sibling.rs:82:13 | ||
| | ||
LL | let a = &mut *u.y; | ||
| --- mutable borrow occurs here (via `u.y`) | ||
LL | let b = &u.x; | ||
| ^^^^ immutable borrow of `u.x` -- which overlaps with `u.y` -- occurs here | ||
LL | use_borrow(a); | ||
| - mutable borrow later used here | ||
| | ||
= note: `u.x` is a field of the union `U`, so it overlaps the field `u.y` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0382, E0502. | ||
For more information about an error, try `rustc --explain E0382`. |
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 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 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
Oops, something went wrong.