mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
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
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||
#![warn(const_err)]
|
||||
|
||||
// A test demonstrating that we prevent calling non-const fn during CTFE.
|
||||
|
||||
fn foo() {}
|
||||
|
||||
const C: () = foo(); //~ WARN: skipping const checks
|
||||
//~^ WARN any use of this value will cause an error
|
||||
|
||||
fn main() {
|
||||
println!("{:?}", C); //~ ERROR: evaluation of constant expression failed
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
warning: skipping const checks
|
||||
--> $DIR/non_const_fn.rs:8:15
|
||||
|
|
||||
LL | const C: () = foo();
|
||||
| ^^^^^
|
||||
|
||||
warning: any use of this value will cause an error
|
||||
--> $DIR/non_const_fn.rs:8:15
|
||||
|
|
||||
LL | const C: () = foo();
|
||||
| --------------^^^^^-
|
||||
| |
|
||||
| calling non-const function `foo`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/non_const_fn.rs:2:9
|
||||
|
|
||||
LL | #![warn(const_err)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error[E0080]: evaluation of constant expression failed
|
||||
--> $DIR/non_const_fn.rs:12:22
|
||||
|
|
||||
LL | println!("{:?}", C);
|
||||
| ^ referenced constant has errors
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
Reference in New Issue
Block a user