Add a test for const unsafe_unreachable that triggers UB
This commit is contained in:
parent
2f28d5945d
commit
c45e9c86ca
2 changed files with 35 additions and 0 deletions
15
src/test/ui/consts/const_unsafe_unreachable_ub.rs
Normal file
15
src/test/ui/consts/const_unsafe_unreachable_ub.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
20
src/test/ui/consts/const_unsafe_unreachable_ub.stderr
Normal file
20
src/test/ui/consts/const_unsafe_unreachable_ub.stderr
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue