rust/src/test/ui/consts/const_unsafe_unreachable_ub.rs

21 lines
426 B
Rust
Raw Normal View History

// build-fail
#![feature(const_unreachable_unchecked)]
const unsafe fn foo(x: bool) -> bool {
match x {
true => true,
false => std::hint::unreachable_unchecked(),
}
}
#[warn(const_err)]
const BAR: bool = unsafe { foo(false) };
fn main() {
assert_eq!(BAR, true);
//~^ ERROR E0080
//~| ERROR erroneous constant
2021-01-30 07:49:22 -06:00
//~| WARN this was previously accepted by the compiler but is being phased out
}