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 #109664 - m-ou-se:format-args-placeholder-span, r=oli-obk
Use span of placeholders in format_args!() expansion.
`format_args!("{}", x)` expands to something that contains `Argument::new_display(&x)`. That entire expression was generated with the span of `x`.
After this PR, `&x` uses the span of `x`, but the `new_display` call uses the span of the `{}` placeholder within the format string. If an implicitly captured argument was used like in `format_args!("{x}")`, both use the span of the `{x}` placeholder.
This fixes#109576, and also allows for more improvements to similar diagnostics in the future, since the usage of `x` can now be traced to the exact `{}` placeholder that required it to be `Display` (or `Debug` etc.)
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,8 +1,8 @@
1
1
error[E0015]: cannot call non-const formatting macro in constant functions
2
-
--> $DIR/format.rs:2:20
2
+
--> $DIR/format.rs:2:13
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
= note: this error originates in the macro `$crate::const_format_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -17,10 +17,10 @@ LL | panic!("{:?}", 0);
17
17
= note: this error originates in the macro `$crate::const_format_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
18
18
19
19
error[E0015]: cannot call non-const formatting macro in constant functions
20
-
--> $DIR/format.rs:8:22
20
+
--> $DIR/format.rs:8:15
21
21
|
22
22
LL | println!("{:?}", 0);
23
-
| ^
23
+
| ^^^^
24
24
|
25
25
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
26
26
= 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)
| ^^^ `Option<{integer}>` cannot be formatted with the default formatter
6
+
|
7
+
= help: the trait `std::fmt::Display` is not implemented for `Option<{integer}>`
8
+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9
+
= 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)
| ^^^^^^^ `Option<{integer}>` cannot be formatted with the default formatter
16
+
|
17
+
= help: the trait `std::fmt::Display` is not implemented for `Option<{integer}>`
18
+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
19
+
= 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)
| ^^^^^ `DisplayOnly` cannot be formatted using `{:?}`
26
+
|
27
+
= help: the trait `Debug` is not implemented for `DisplayOnly`
28
+
= note: add `#[derive(Debug)]` to `DisplayOnly` or manually `impl Debug for DisplayOnly`
29
+
= 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)
30
+
help: consider annotating `DisplayOnly` with `#[derive(Debug)]`
| ^^^^^^^^^^^ `DisplayOnly` cannot be formatted using `{:?}`
40
+
|
41
+
= help: the trait `Debug` is not implemented for `DisplayOnly`
42
+
= note: add `#[derive(Debug)]` to `DisplayOnly` or manually `impl Debug for DisplayOnly`
43
+
= 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)
44
+
help: consider annotating `DisplayOnly` with `#[derive(Debug)]`
45
+
|
46
+
LL | #[derive(Debug)]
47
+
|
48
+
49
+
error: aborting due to 4 previous errors
50
+
51
+
For more information about this error, try `rustc --explain E0277`.
0 commit comments