diff --git a/src/test/ui/consts/const_unsafe_unreachable_ub.rs b/src/test/ui/consts/const_unsafe_unreachable_ub.rs new file mode 100644 index 000000000000..2e4dfd1522b9 --- /dev/null +++ b/src/test/ui/consts/const_unsafe_unreachable_ub.rs @@ -0,0 +1,15 @@ +#![feature(const_fn)] +#![feature(const_unreachable_unchecked)] + +const unsafe fn foo(x: bool) -> bool { + match x { + true => true, + false => std::hint::unreachable_unchecked(), + } +} + +const BAR: bool = unsafe { foo(false) }; + +fn main() { + assert_eq!(BAR, true); +} diff --git a/src/test/ui/consts/const_unsafe_unreachable_ub.stderr b/src/test/ui/consts/const_unsafe_unreachable_ub.stderr new file mode 100644 index 000000000000..0a7aa4e00214 --- /dev/null +++ b/src/test/ui/consts/const_unsafe_unreachable_ub.stderr @@ -0,0 +1,20 @@ +error: any use of this value will cause an error + --> $SRC_DIR/libcore/hint.rs:LL:COL + | +LL | unsafe { intrinsics::unreachable() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | entering unreachable code + | inside `std::hint::unreachable_unchecked` at $SRC_DIR/libcore/hint.rs:LL:COL + | inside `foo` at $DIR/const_unsafe_unreachable_ub.rs:7:18 + | inside `BAR` at $DIR/const_unsafe_unreachable_ub.rs:11:28 + | + ::: $DIR/const_unsafe_unreachable_ub.rs:11:1 + | +LL | const BAR: bool = unsafe { foo(false) }; + | ---------------------------------------- + | + = note: `#[deny(const_err)]` on by default + +error: aborting due to previous error +