Add const eval tests ensuring padding gets correctly marked as deinit on deaggregation
This commit is contained in:
parent
2a040284a5
commit
f7ca97a209
17
src/test/ui/consts/const-eval/ub-enum-overwrite.rs
Normal file
17
src/test/ui/consts/const-eval/ub-enum-overwrite.rs
Normal file
@ -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() {}
|
20
src/test/ui/consts/const-eval/ub-enum-overwrite.stderr
Normal file
20
src/test/ui/consts/const-eval/ub-enum-overwrite.stderr
Normal file
@ -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`.
|
Loading…
x
Reference in New Issue
Block a user