Skip to content

Commit 56426db

Browse files
committed
Add test for format_args!("{}", 0) in const.
1 parent cc791eb commit 56426db

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/ui/consts/const-eval/format.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ const fn print() {
99
//~| ERROR cannot call non-const function `_print` in constant functions
1010
}
1111

12+
const fn format_args() {
13+
format_args!("{}", 0);
14+
//~^ ERROR cannot call non-const formatting macro in constant functions
15+
}
16+
1217
fn main() {}

tests/ui/consts/const-eval/format.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ LL | println!("{:?}", 0);
2424
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
2525
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
2626

27-
error: aborting due to 3 previous errors
27+
error[E0015]: cannot call non-const formatting macro in constant functions
28+
--> $DIR/format.rs:13:5
29+
|
30+
LL | format_args!("{}", 0);
31+
| ^^^^^^^^^^^^^^^^^^^^^
32+
|
33+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
34+
35+
error: aborting due to 4 previous errors
2836

2937
For more information about this error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)