You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #140544 - m-ou-se:format-args-const-cleanup, r=fee1-dead
Clean up "const" situation in format_args!().
This cleans up the "const" situation in the format_args!() expansion/lowering.
Rather than marking the Argument::new_display etc. functions as non-const, this marks the Arguments::new_v1 functions as non-const.
Example expansion/lowering of format_args!() in const:
```rust
// Error: cannot call non-const formatting macro in constant functions
const {
fmt::Arguments::new_v1( // Now the error is produced here.
&["Hello, ", "!\n"],
&[
fmt::Argument::new_display(&world) // The error used to be produced here.
],
)
}
```
Copy file name to clipboardExpand all lines: tests/ui/consts/const-eval/format.stderr
+4-4
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
error[E0015]: cannot call non-const formatting macro in constant functions
2
-
--> $DIR/format.rs:2:13
2
+
--> $DIR/format.rs:2:5
3
3
|
4
4
LL | panic!("{:?}", 0);
5
-
| ^^^^
5
+
| ^^^^^^^^^^^^^^^^^
6
6
|
7
7
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
8
8
9
9
error[E0015]: cannot call non-const formatting macro in constant functions
10
-
--> $DIR/format.rs:7:15
10
+
--> $DIR/format.rs:7:5
11
11
|
12
12
LL | println!("{:?}", 0);
13
-
| ^^^^
13
+
| ^^^^^^^^^^^^^^^^^^^
14
14
|
15
15
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
16
16
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
0 commit comments