Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/test/ui/consts/miri_unleashed/non_const_fn.rs
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions src/test/ui/consts/miri_unleashed/non_const_fn.stderr
Original file line number Diff line number Diff line change
@@ -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`.