Skip to content

Commit 6c72a00

Browse files
committed
Add test for span of implicit format args captures.
1 parent 769886c commit 6c72a00

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-compile
2+
3+
struct DisplayOnly;
4+
5+
impl std::fmt::Display for DisplayOnly {
6+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7+
unimplemented!()
8+
}
9+
}
10+
11+
fn main() {
12+
let x = Some(1);
13+
println!("{x:?} {x} {x:?}");
14+
//~^ ERROR: `Option<{integer}>` doesn't implement `std::fmt::Display`
15+
println!("{x:?} {x} {x:?}", x = Some(1));
16+
//~^ ERROR: `Option<{integer}>` doesn't implement `std::fmt::Display`
17+
let x = DisplayOnly;
18+
println!("{x} {x:?} {x}");
19+
//~^ ERROR: `DisplayOnly` doesn't implement `Debug`
20+
println!("{x} {x:?} {x}", x = DisplayOnly);
21+
//~^ ERROR: `DisplayOnly` doesn't implement `Debug`
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error[E0277]: `Option<{integer}>` doesn't implement `std::fmt::Display`
2+
--> $DIR/format-args-argument-span.rs:13:21
3+
|
4+
LL | println!("{x:?} {x} {x:?}");
5+
| ^^^ `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)
10+
11+
error[E0277]: `Option<{integer}>` doesn't implement `std::fmt::Display`
12+
--> $DIR/format-args-argument-span.rs:15:37
13+
|
14+
LL | println!("{x:?} {x} {x:?}", x = Some(1));
15+
| ^^^^^^^ `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)
20+
21+
error[E0277]: `DisplayOnly` doesn't implement `Debug`
22+
--> $DIR/format-args-argument-span.rs:18:19
23+
|
24+
LL | println!("{x} {x:?} {x}");
25+
| ^^^^^ `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)]`
31+
|
32+
LL | #[derive(Debug)]
33+
|
34+
35+
error[E0277]: `DisplayOnly` doesn't implement `Debug`
36+
--> $DIR/format-args-argument-span.rs:20:35
37+
|
38+
LL | println!("{x} {x:?} {x}", x = DisplayOnly);
39+
| ^^^^^^^^^^^ `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

Comments
 (0)