Skip to content

Commit 6cd164f

Browse files
committed
Update UB test to fail during build with contant errors
1 parent c45e9c8 commit 6cd164f

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/test/ui/consts/const_unsafe_unreachable_ub.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// build-fail
2+
13
#![feature(const_fn)]
24
#![feature(const_unreachable_unchecked)]
35

@@ -8,8 +10,11 @@ const unsafe fn foo(x: bool) -> bool {
810
}
911
}
1012

13+
#[warn(const_err)]
1114
const BAR: bool = unsafe { foo(false) };
1215

1316
fn main() {
1417
assert_eq!(BAR, true);
18+
//~^ ERROR E0080
19+
//~| ERROR erroneous constant
1520
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
1-
error: any use of this value will cause an error
1+
warning: any use of this value will cause an error
22
--> $SRC_DIR/libcore/hint.rs:LL:COL
33
|
44
LL | unsafe { intrinsics::unreachable() }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
| |
77
| entering unreachable code
88
| inside `std::hint::unreachable_unchecked` at $SRC_DIR/libcore/hint.rs:LL:COL
9-
| inside `foo` at $DIR/const_unsafe_unreachable_ub.rs:7:18
10-
| inside `BAR` at $DIR/const_unsafe_unreachable_ub.rs:11:28
9+
| inside `foo` at $DIR/const_unsafe_unreachable_ub.rs:9:18
10+
| inside `BAR` at $DIR/const_unsafe_unreachable_ub.rs:14:28
1111
|
12-
::: $DIR/const_unsafe_unreachable_ub.rs:11:1
12+
::: $DIR/const_unsafe_unreachable_ub.rs:14:1
1313
|
1414
LL | const BAR: bool = unsafe { foo(false) };
1515
| ----------------------------------------
1616
|
17+
note: the lint level is defined here
18+
--> $DIR/const_unsafe_unreachable_ub.rs:13:8
19+
|
20+
LL | #[warn(const_err)]
21+
| ^^^^^^^^^
22+
23+
error[E0080]: evaluation of constant expression failed
24+
--> $DIR/const_unsafe_unreachable_ub.rs:17:3
25+
|
26+
LL | assert_eq!(BAR, true);
27+
| ^^^^^^^^^^^---^^^^^^^^
28+
| |
29+
| referenced constant has errors
30+
|
31+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
32+
33+
error: erroneous constant used
34+
--> $DIR/const_unsafe_unreachable_ub.rs:17:3
35+
|
36+
LL | assert_eq!(BAR, true);
37+
| ^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
38+
|
1739
= note: `#[deny(const_err)]` on by default
40+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1841

19-
error: aborting due to previous error
42+
error: aborting due to 2 previous errors; 1 warning emitted
2043

44+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)