-
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.
Modify const eval to implement the new semantics for
SetDiscriminant
.
- Loading branch information
1 parent
1cdeb7f
commit 27c4f88
Showing
4 changed files
with
56 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![feature(const_mut_refs)] | ||
|
||
enum E { | ||
A(u8), | ||
B, | ||
} | ||
|
||
const _: u8 = { | ||
//~^ ERROR is undefined behavior | ||
let mut e = E::A(1); | ||
let p = if let E::A(x) = &mut e { x as *mut u8 } else { unreachable!() }; | ||
// Make sure overwriting `e` uninitializes other bytes | ||
e = E::B; | ||
unsafe { *p } | ||
}; | ||
|
||
fn main() {} |
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,20 @@ | ||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-enum-overwrite.rs:8:1 | ||
| | ||
LL | / const _: u8 = { | ||
LL | | | ||
LL | | let mut e = E::A(1); | ||
LL | | let p = if let E::A(x) = &mut e { x as *mut u8 } else { unreachable!() }; | ||
... | | ||
LL | | unsafe { *p } | ||
LL | | }; | ||
| |__^ type validation failed: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
= note: the raw bytes of the constant (size: 1, align: 1) { | ||
__ │ ░ | ||
} | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |