Skip to content

Commit 7f1ce45

Browse files
committed
add test for calling non-const fn
1 parent e5b8c11 commit 7f1ce45

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
#![allow(const_err)]
3+
4+
// A test demonstrating that we prevent calling non-const fn during CTFE.
5+
6+
fn foo() {}
7+
8+
const C: () = foo(); //~ WARN: skipping const checks
9+
10+
fn main() {
11+
println!("{:?}", C); //~ ERROR: evaluation of constant expression failed
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
warning: skipping const checks
2+
--> $DIR/non_const_fn.rs:8:15
3+
|
4+
LL | const C: () = foo();
5+
| ^^^^^
6+
7+
error[E0080]: evaluation of constant expression failed
8+
--> $DIR/non_const_fn.rs:11:22
9+
|
10+
LL | println!("{:?}", C);
11+
| ^ referenced constant has errors
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)