2023-05-01 06:18:41 -05:00
|
|
|
// unit-test: ConstProp
|
|
|
|
// compile-flags: -Zmir-enable-passes=+RemoveZsts
|
2022-02-16 18:00:00 -06:00
|
|
|
// Verify that we can pretty print invalid constants.
|
|
|
|
|
2022-02-18 18:00:00 -06:00
|
|
|
#![feature(adt_const_params)]
|
2022-02-16 18:00:00 -06:00
|
|
|
#![feature(inline_const)]
|
2022-02-18 18:00:00 -06:00
|
|
|
#![allow(incomplete_features)]
|
2022-02-16 18:00:00 -06:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
#[repr(u32)]
|
|
|
|
enum E { A, B, C }
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
enum Empty {}
|
2022-02-15 06:58:34 -06:00
|
|
|
|
2023-01-23 16:17:36 -06:00
|
|
|
// EMIT_MIR invalid_constant.main.RemoveZsts.diff
|
2022-02-15 06:58:34 -06:00
|
|
|
// EMIT_MIR invalid_constant.main.ConstProp.diff
|
|
|
|
fn main() {
|
2022-02-16 18:00:00 -06:00
|
|
|
// An invalid char.
|
|
|
|
union InvalidChar {
|
2022-02-16 18:00:00 -06:00
|
|
|
int: u32,
|
|
|
|
chr: char,
|
|
|
|
}
|
2022-03-03 06:02:52 -06:00
|
|
|
let _invalid_char = unsafe { InvalidChar { int: 0x110001 }.chr };
|
2022-02-16 18:00:00 -06:00
|
|
|
|
|
|
|
// An enum with an invalid tag. Regression test for #93688.
|
|
|
|
union InvalidTag {
|
|
|
|
int: u32,
|
|
|
|
e: E,
|
|
|
|
}
|
2022-03-03 06:02:52 -06:00
|
|
|
let _invalid_tag = [unsafe { InvalidTag { int: 4 }.e }];
|
2022-02-16 18:00:00 -06:00
|
|
|
|
|
|
|
// An enum without variants. Regression test for #94073.
|
|
|
|
union NoVariants {
|
|
|
|
int: u32,
|
|
|
|
empty: Empty,
|
|
|
|
}
|
2022-03-03 06:02:52 -06:00
|
|
|
let _enum_without_variants = [unsafe { NoVariants { int: 0 }.empty }];
|
2022-02-18 18:00:00 -06:00
|
|
|
|
|
|
|
// A non-UTF-8 string slice. Regression test for #75763 and #78520.
|
|
|
|
struct Str<const S: &'static str>;
|
|
|
|
let _non_utf8_str: Str::<{
|
|
|
|
unsafe { std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) }
|
|
|
|
}>;
|
2022-02-15 06:58:34 -06:00
|
|
|
}
|