Skip to content

Commit 9b5b9b9

Browse files
authored
Rollup merge of #65593 - RalfJung:non-const-fn, r=oli-obk
add test for calling non-const fn The good news is that there is an error. But I expected to see [this error](https://github.com/rust-lang/rust/blob/9578272d681c8691ca2ff3f5c4230b491bc1c694/src/librustc_mir/const_eval.rs#L346) surface. @oli-obk any idea why that message is not shown anywhere? r? @oli-obk
2 parents c8fb27d + 38fd74f commit 9b5b9b9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
#![warn(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+
//~^ WARN any use of this value will cause an error
10+
11+
fn main() {
12+
println!("{:?}", C); //~ ERROR: evaluation of constant expression failed
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: skipping const checks
2+
--> $DIR/non_const_fn.rs:8:15
3+
|
4+
LL | const C: () = foo();
5+
| ^^^^^
6+
7+
warning: any use of this value will cause an error
8+
--> $DIR/non_const_fn.rs:8:15
9+
|
10+
LL | const C: () = foo();
11+
| --------------^^^^^-
12+
| |
13+
| calling non-const function `foo`
14+
|
15+
note: lint level defined here
16+
--> $DIR/non_const_fn.rs:2:9
17+
|
18+
LL | #![warn(const_err)]
19+
| ^^^^^^^^^
20+
21+
error[E0080]: evaluation of constant expression failed
22+
--> $DIR/non_const_fn.rs:12:22
23+
|
24+
LL | println!("{:?}", C);
25+
| ^ referenced constant has errors
26+
27+
error: aborting due to previous error
28+
29+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)