-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #92744 - lambinoo:I-91161-non-exhaustive-foreign-vari…
…ants, r=scottmcm Check if enum from foreign crate has any non exhaustive variants when attempting a cast Fixes #91161 As stated in the issue, this will require a crater run as it might break other people's stuff.
- Loading branch information
Showing
3 changed files
with
34 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
// aux-build:enums.rs | ||
// run-pass | ||
|
||
extern crate enums; | ||
|
||
use enums::FieldLessWithNonExhaustiveVariant; | ||
|
||
fn main() { | ||
let e = FieldLessWithNonExhaustiveVariant::default(); | ||
// FIXME: https://github.com/rust-lang/rust/issues/91161 | ||
// This `as` cast *should* be an error, since it would fail | ||
// if the non-exhaustive variant got fields. But today it | ||
// doesn't. The fix for that will update this test to | ||
// show an error (and not be run-pass any more). | ||
let d = e as u8; | ||
let d = e as u8; //~ ERROR casting `FieldLessWithNonExhaustiveVariant` as `u8` is invalid [E0606] | ||
assert_eq!(d, 0); | ||
} |
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,11 @@ | ||
error[E0606]: casting `FieldLessWithNonExhaustiveVariant` as `u8` is invalid | ||
--> $DIR/enum-as-cast.rs:9:13 | ||
| | ||
LL | let d = e as u8; | ||
| ^^^^^^^ | ||
| | ||
= note: cannot cast an enum with a non-exhaustive variant when it's defined in another crate | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0606`. |