rust/tests/ui/consts/const-mut-refs/issue-76510.rs
Tomasz Miąsko 67f455afe1 Suppress "erroneous constant used" for constants tainted by errors
When constant evaluation fails because its MIR is tainted by errors,
suppress note indicating that erroneous constant was used, since those
errors have to be fixed regardless of the constant being used or not.
2023-05-15 00:00:00 +00:00

18 lines
489 B
Rust

// stderr-per-bitwidth
use std::mem::{transmute, ManuallyDrop};
const S: &'static mut str = &mut " hello ";
//~^ ERROR: mutable references are not allowed in the final value of constants
//~| ERROR: mutation through a reference is not allowed in constants
//~| ERROR: cannot borrow data in a `&` reference as mutable
const fn trigger() -> [(); unsafe {
let s = transmute::<(*const u8, usize), &ManuallyDrop<str>>((S.as_ptr(), 3));
0
}] {
[(); 0]
}
fn main() {}