forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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 rust-lang#124504 - gurry:123710-union-ICE, r=oli-obk Mark unions non-const-propagatable in `KnownPanicsLint` without calling layout Fixes rust-lang#123710 The ICE occurs during the layout calculation of the union `InvalidTag` in rust-lang#123710 because the following assert fails:https://github.com/rust-lang/rust/blob/5fe8b697e729b6eb64841a3905e57da1b47f4ca3/compiler/rustc_abi/src/layout.rs#L289-L292 The layout calculation is invoked by `KnownPanicsLint` when it is trying to figure out which locals it can const prop. Since `KnownPanicsLint` is never actually going to const props unions thanks to PR rust-lang#121628 there's no point calling layout to check if it can. So in this fix I skip the call to layout and just mark the local non-const propagatable if it is a union.
- Loading branch information
Showing
4 changed files
with
64 additions
and
24 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.
22 changes: 22 additions & 0 deletions
22
tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs
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,22 @@ | ||
// Regression test for issue 123710. | ||
// Tests that the we do not ICE in KnownPanicsLint | ||
// when a union contains an enum with an repr(packed), | ||
// which is a repr not supported for enums | ||
|
||
#[repr(packed)] | ||
//~^ ERROR attribute should be applied to a struct or union | ||
#[repr(u32)] | ||
enum E { | ||
A, | ||
B, | ||
C, | ||
} | ||
|
||
fn main() { | ||
union InvalidTag { | ||
int: u32, | ||
e: E, | ||
//~^ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union | ||
} | ||
let _invalid_tag = InvalidTag { int: 4 }; | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.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,29 @@ | ||
error[E0517]: attribute should be applied to a struct or union | ||
--> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:6:8 | ||
| | ||
LL | #[repr(packed)] | ||
| ^^^^^^ | ||
... | ||
LL | / enum E { | ||
LL | | A, | ||
LL | | B, | ||
LL | | C, | ||
LL | | } | ||
| |_- not a struct or union | ||
|
||
error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union | ||
--> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:18:9 | ||
| | ||
LL | e: E, | ||
| ^^^^ | ||
| | ||
= note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` | ||
help: wrap the field type in `ManuallyDrop<...>` | ||
| | ||
LL | e: std::mem::ManuallyDrop<E>, | ||
| +++++++++++++++++++++++ + | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0517, E0740. | ||
For more information about an error, try `rustc --explain E0517`. |