rust/tests/mir-opt/const_prop/invalid_constant.rs
Nicholas Nethercote c9c80d2c5f rustfmt tests/mir-opt.
The only non-obvious changes:
- `building/storage_live_dead_in_statics.rs` has a `#[rustfmt::skip]`
  attribute to avoid reformating a table of data.
- Two `.mir` files have slight changes involving line numbers.
- In `unusual_item_types.rs` an `EMIT_MIR` annotation is moved to
  outside a function, which is the usual spot, because `tidy` complains
  if such a comment is indented.

The commit also tweaks the comments in `rustfmt.toml`.
2024-06-03 14:17:16 +10:00

48 lines
1.2 KiB
Rust

// skip-filecheck
//@ test-mir-pass: GVN
//@ compile-flags: -Zmir-enable-passes=+RemoveZsts
// Verify that we can pretty print invalid constants.
#![feature(adt_const_params)]
#![allow(incomplete_features)]
#[derive(Copy, Clone)]
#[repr(u32)]
enum E {
A,
B,
C,
}
#[derive(Copy, Clone)]
enum Empty {}
// EMIT_MIR invalid_constant.main.RemoveZsts.diff
// EMIT_MIR invalid_constant.main.GVN.diff
fn main() {
// An invalid char.
union InvalidChar {
int: u32,
chr: char,
}
let _invalid_char = unsafe { InvalidChar { int: 0x110001 }.chr };
// An enum with an invalid tag. Regression test for #93688.
union InvalidTag {
int: u32,
e: E,
}
let _invalid_tag = [unsafe { InvalidTag { int: 4 }.e }];
// An enum without variants. Regression test for #94073.
union NoVariants {
int: u32,
empty: Empty,
}
let _enum_without_variants = [unsafe { NoVariants { int: 0 }.empty }];
// 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]) } }>;
}