Skip to content

Commit c99c4d4

Browse files
authored
Rollup merge of #131710 - ShE3py:parse_format_apostrophes, r=compiler-errors
Remove `'apostrophes'` from `rustc_parse_format` The rest of the compiler uses \`grave accents\`, while `rustc_parse_format` uses \`'apostrophes.'\` Also makes the crate compile as a stand-alone: ``` ~/rust/compiler/rustc_parse_format $ cargo check Compiling rustc_index_macros v0.0.0 (/home/lieselotte/rust/compiler/rustc_index_macros) error[E0277]: `syn::Lit` doesn't implement `Debug` --> compiler/rustc_index_macros/src/newtype.rs:52:57 | 52 | panic!("Specified multiple max: {old:?}"); | ^^^^^^^ `syn::Lit` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = help: the trait `Debug` is not implemented for `syn::Lit` = 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) error[E0277]: `syn::Lit` doesn't implement `Debug` --> compiler/rustc_index_macros/src/newtype.rs:64:74 | 64 | panic!("Specified multiple debug format options: {old:?}"); | ^^^^^^^ `syn::Lit` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = help: the trait `Debug` is not implemented for `syn::Lit` = 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) For more information about this error, try `rustc --explain E0277`. error: could not compile `rustc_index_macros` (lib) due to 2 previous errors ``` `@rustbot` label +A-diagnostics
2 parents d82a49d + dda3066 commit c99c4d4

21 files changed

+83
-83
lines changed

compiler/rustc_index_macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
proc-macro = true
88

99
[dependencies]
10-
syn = { version = "2.0.9", features = ["full"] }
10+
syn = { version = "2.0.9", features = ["full", "extra-traits"] }
1111
proc-macro2 = "1"
1212
quote = "1"
1313

compiler/rustc_parse_format/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -473,19 +473,19 @@ impl<'a> Parser<'a> {
473473
}
474474

475475
pos = peek_pos;
476-
description = format!("expected `'}}'`, found `{maybe:?}`");
476+
description = format!("expected `}}`, found `{}`", maybe.escape_debug());
477477
} else {
478-
description = "expected `'}'` but string was terminated".to_owned();
478+
description = "expected `}` but string was terminated".to_owned();
479479
// point at closing `"`
480480
pos = self.input.len() - if self.append_newline { 1 } else { 0 };
481481
}
482482

483483
let pos = self.to_span_index(pos);
484484

485-
let label = "expected `'}'`".to_owned();
485+
let label = "expected `}`".to_owned();
486486
let (note, secondary_label) = if arg.format.fill == Some('}') {
487487
(
488-
Some("the character `'}'` is interpreted as a fill character because of the `:` that precedes it".to_owned()),
488+
Some("the character `}` is interpreted as a fill character because of the `:` that precedes it".to_owned()),
489489
arg.format.fill_span.map(|sp| ("this is not interpreted as a formatting closing brace".to_owned(), sp)),
490490
)
491491
} else {

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ struct ErrorWithNonexistentField {
178178
}
179179

180180
#[derive(Diagnostic)]
181-
//~^ ERROR invalid format string: expected `'}'`
181+
//~^ ERROR invalid format string: expected `}`
182182
#[diag(no_crate_example, code = E0123)]
183183
struct ErrorMissingClosingBrace {
184184
#[suggestion(no_crate_suggestion, code = "{name")]

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ error: `name` doesn't refer to a field on this type
184184
LL | #[suggestion(no_crate_suggestion, code = "{name}")]
185185
| ^^^^^^^^
186186

187-
error: invalid format string: expected `'}'` but string was terminated
187+
error: invalid format string: expected `}` but string was terminated
188188
--> $DIR/diagnostic-derive.rs:180:10
189189
|
190190
LL | #[derive(Diagnostic)]
191-
| ^^^^^^^^^^ expected `'}'` in format string
191+
| ^^^^^^^^^^ expected `}` in format string
192192
|
193193
= note: if you intended to print `{`, you can escape it using `{{`
194194
= note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/ui/diagnostic_namespace/on_unimplemented/broken_format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ trait ImportantTrait3 {}
1919
trait ImportantTrait4 {}
2020

2121
#[diagnostic::on_unimplemented(message = "Test {Self:!}")]
22-
//~^WARN expected `'}'`, found `'!'`
23-
//~|WARN expected `'}'`, found `'!'`
22+
//~^WARN expected `}`, found `!`
23+
//~|WARN expected `}`, found `!`
2424
//~|WARN unmatched `}` found
2525
//~|WARN unmatched `}` found
2626
trait ImportantTrait5 {}

tests/ui/diagnostic_namespace/on_unimplemented/broken_format.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | #[diagnostic::on_unimplemented(message = "Test {Self:123}")]
3030
|
3131
= help: no format specifier are supported in this position
3232

33-
warning: expected `'}'`, found `'!'`
33+
warning: expected `}`, found `!`
3434
--> $DIR/broken_format.rs:21:32
3535
|
3636
LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")]
@@ -153,7 +153,7 @@ note: required by a bound in `check_4`
153153
LL | fn check_4(_: impl ImportantTrait4) {}
154154
| ^^^^^^^^^^^^^^^ required by this bound in `check_4`
155155

156-
warning: expected `'}'`, found `'!'`
156+
warning: expected `}`, found `!`
157157
--> $DIR/broken_format.rs:21:32
158158
|
159159
LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")]

tests/ui/fmt/closing-brace-as-fill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
fn main() {
66
println!("Hello, world! {0:}<3", 2);
7-
//~^ ERROR invalid format string: expected `'}'` but string was terminated
7+
//~^ ERROR invalid format string: expected `}` but string was terminated
88
}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error: invalid format string: expected `'}'` but string was terminated
1+
error: invalid format string: expected `}` but string was terminated
22
--> $DIR/closing-brace-as-fill.rs:6:35
33
|
44
LL | println!("Hello, world! {0:}<3", 2);
5-
| - ^ expected `'}'` in format string
5+
| - ^ expected `}` in format string
66
| |
77
| this is not interpreted as a formatting closing brace
88
|
9-
= note: the character `'}'` is interpreted as a fill character because of the `:` that precedes it
9+
= note: the character `}` is interpreted as a fill character because of the `:` that precedes it
1010

1111
error: aborting due to 1 previous error
1212

tests/ui/fmt/format-string-error-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ raw { \n
7272

7373
// note: `\x7B` is `{`
7474
println!("\x7B}\u{8} {", 1);
75-
//~^ ERROR invalid format string: expected `'}'` but string was terminated
75+
//~^ ERROR invalid format string: expected `}` but string was terminated
7676

7777
println!("\x7B}\u8 {", 1);
7878
//~^ ERROR incorrect unicode escape sequence

tests/ui/fmt/format-string-error-2.stderr

+28-28
Original file line numberDiff line numberDiff line change
@@ -9,138 +9,138 @@ help: format of unicode escape sequences uses braces
99
LL | println!("\x7B}\u{8} {", 1);
1010
| ~~~~~
1111

12-
error: invalid format string: expected `'}'`, found `'a'`
12+
error: invalid format string: expected `}`, found `a`
1313
--> $DIR/format-string-error-2.rs:5:5
1414
|
1515
LL | format!("{
1616
| - because of this opening brace
1717
LL | a");
18-
| ^ expected `'}'` in format string
18+
| ^ expected `}` in format string
1919
|
2020
= note: if you intended to print `{`, you can escape it using `{{`
2121

22-
error: invalid format string: expected `'}'`, found `'b'`
22+
error: invalid format string: expected `}`, found `b`
2323
--> $DIR/format-string-error-2.rs:9:5
2424
|
2525
LL | format!("{ \
2626
| - because of this opening brace
2727
LL | \
2828
LL | b");
29-
| ^ expected `'}'` in format string
29+
| ^ expected `}` in format string
3030
|
3131
= note: if you intended to print `{`, you can escape it using `{{`
3232

33-
error: invalid format string: expected `'}'`, found `'\'`
33+
error: invalid format string: expected `}`, found `\`
3434
--> $DIR/format-string-error-2.rs:11:18
3535
|
3636
LL | format!(r#"{ \
37-
| - ^ expected `'}'` in format string
37+
| - ^ expected `}` in format string
3838
| |
3939
| because of this opening brace
4040
|
4141
= note: if you intended to print `{`, you can escape it using `{{`
4242

43-
error: invalid format string: expected `'}'`, found `'\'`
43+
error: invalid format string: expected `}`, found `\`
4444
--> $DIR/format-string-error-2.rs:15:18
4545
|
4646
LL | format!(r#"{ \n
47-
| - ^ expected `'}'` in format string
47+
| - ^ expected `}` in format string
4848
| |
4949
| because of this opening brace
5050
|
5151
= note: if you intended to print `{`, you can escape it using `{{`
5252

53-
error: invalid format string: expected `'}'`, found `'e'`
53+
error: invalid format string: expected `}`, found `e`
5454
--> $DIR/format-string-error-2.rs:21:5
5555
|
5656
LL | format!("{ \n
5757
| - because of this opening brace
5858
LL | \n
5959
LL | e");
60-
| ^ expected `'}'` in format string
60+
| ^ expected `}` in format string
6161
|
6262
= note: if you intended to print `{`, you can escape it using `{{`
6363

64-
error: invalid format string: expected `'}'`, found `'a'`
64+
error: invalid format string: expected `}`, found `a`
6565
--> $DIR/format-string-error-2.rs:25:5
6666
|
6767
LL | {
6868
| - because of this opening brace
6969
LL | a");
70-
| ^ expected `'}'` in format string
70+
| ^ expected `}` in format string
7171
|
7272
= note: if you intended to print `{`, you can escape it using `{{`
7373

74-
error: invalid format string: expected `'}'`, found `'a'`
74+
error: invalid format string: expected `}`, found `a`
7575
--> $DIR/format-string-error-2.rs:29:5
7676
|
7777
LL | {
7878
| - because of this opening brace
7979
LL | a
80-
| ^ expected `'}'` in format string
80+
| ^ expected `}` in format string
8181
|
8282
= note: if you intended to print `{`, you can escape it using `{{`
8383

84-
error: invalid format string: expected `'}'`, found `'b'`
84+
error: invalid format string: expected `}`, found `b`
8585
--> $DIR/format-string-error-2.rs:35:5
8686
|
8787
LL | { \
8888
| - because of this opening brace
8989
LL | \
9090
LL | b");
91-
| ^ expected `'}'` in format string
91+
| ^ expected `}` in format string
9292
|
9393
= note: if you intended to print `{`, you can escape it using `{{`
9494

95-
error: invalid format string: expected `'}'`, found `'b'`
95+
error: invalid format string: expected `}`, found `b`
9696
--> $DIR/format-string-error-2.rs:40:5
9797
|
9898
LL | { \
9999
| - because of this opening brace
100100
LL | \
101101
LL | b \
102-
| ^ expected `'}'` in format string
102+
| ^ expected `}` in format string
103103
|
104104
= note: if you intended to print `{`, you can escape it using `{{`
105105

106-
error: invalid format string: expected `'}'`, found `'\'`
106+
error: invalid format string: expected `}`, found `\`
107107
--> $DIR/format-string-error-2.rs:45:8
108108
|
109109
LL | raw { \
110-
| - ^ expected `'}'` in format string
110+
| - ^ expected `}` in format string
111111
| |
112112
| because of this opening brace
113113
|
114114
= note: if you intended to print `{`, you can escape it using `{{`
115115

116-
error: invalid format string: expected `'}'`, found `'\'`
116+
error: invalid format string: expected `}`, found `\`
117117
--> $DIR/format-string-error-2.rs:50:8
118118
|
119119
LL | raw { \n
120-
| - ^ expected `'}'` in format string
120+
| - ^ expected `}` in format string
121121
| |
122122
| because of this opening brace
123123
|
124124
= note: if you intended to print `{`, you can escape it using `{{`
125125

126-
error: invalid format string: expected `'}'`, found `'e'`
126+
error: invalid format string: expected `}`, found `e`
127127
--> $DIR/format-string-error-2.rs:57:5
128128
|
129129
LL | { \n
130130
| - because of this opening brace
131131
LL | \n
132132
LL | e");
133-
| ^ expected `'}'` in format string
133+
| ^ expected `}` in format string
134134
|
135135
= note: if you intended to print `{`, you can escape it using `{{`
136136

137-
error: invalid format string: expected `'}'`, found `'a'`
137+
error: invalid format string: expected `}`, found `a`
138138
--> $DIR/format-string-error-2.rs:67:5
139139
|
140140
LL | {
141141
| - because of this opening brace
142142
LL | asdf}
143-
| ^ expected `'}'` in format string
143+
| ^ expected `}` in format string
144144
|
145145
= note: if you intended to print `{`, you can escape it using `{{`
146146

@@ -150,11 +150,11 @@ error: 1 positional argument in format string, but no arguments were given
150150
LL | println!("\t{}");
151151
| ^^
152152

153-
error: invalid format string: expected `'}'` but string was terminated
153+
error: invalid format string: expected `}` but string was terminated
154154
--> $DIR/format-string-error-2.rs:74:27
155155
|
156156
LL | println!("\x7B}\u{8} {", 1);
157-
| -^ expected `'}'` in format string
157+
| -^ expected `}` in format string
158158
| |
159159
| because of this opening brace
160160
|

tests/ui/fmt/format-string-error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
fn main() {
44
println!("{");
5-
//~^ ERROR invalid format string: expected `'}'` but string was terminated
5+
//~^ ERROR invalid format string: expected `}` but string was terminated
66
println!("{{}}");
77
println!("}");
88
//~^ ERROR invalid format string: unmatched `}` found
@@ -13,11 +13,11 @@ fn main() {
1313
let _ = format!("{a:._$}", a = "", _ = 0);
1414
//~^ ERROR invalid format string: invalid argument name `_`
1515
let _ = format!("{");
16-
//~^ ERROR invalid format string: expected `'}'` but string was terminated
16+
//~^ ERROR invalid format string: expected `}` but string was terminated
1717
let _ = format!("}");
1818
//~^ ERROR invalid format string: unmatched `}` found
1919
let _ = format!("{\\}");
20-
//~^ ERROR invalid format string: expected `'}'`, found `'\'`
20+
//~^ ERROR invalid format string: expected `}`, found `\`
2121
let _ = format!("\n\n\n{\n\n\n");
2222
//~^ ERROR invalid format string
2323
let _ = format!(r###"

tests/ui/fmt/format-string-error.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: invalid format string: expected `'}'` but string was terminated
1+
error: invalid format string: expected `}` but string was terminated
22
--> $DIR/format-string-error.rs:4:16
33
|
44
LL | println!("{");
5-
| -^ expected `'}'` in format string
5+
| -^ expected `}` in format string
66
| |
77
| because of this opening brace
88
|
@@ -40,11 +40,11 @@ LL | let _ = format!("{a:._$}", a = "", _ = 0);
4040
|
4141
= note: argument name cannot be a single underscore
4242

43-
error: invalid format string: expected `'}'` but string was terminated
43+
error: invalid format string: expected `}` but string was terminated
4444
--> $DIR/format-string-error.rs:15:23
4545
|
4646
LL | let _ = format!("{");
47-
| -^ expected `'}'` in format string
47+
| -^ expected `}` in format string
4848
| |
4949
| because of this opening brace
5050
|
@@ -58,44 +58,44 @@ LL | let _ = format!("}");
5858
|
5959
= note: if you intended to print `}`, you can escape it using `}}`
6060

61-
error: invalid format string: expected `'}'`, found `'\'`
61+
error: invalid format string: expected `}`, found `\`
6262
--> $DIR/format-string-error.rs:19:23
6363
|
6464
LL | let _ = format!("{\}");
65-
| -^ expected `'}'` in format string
65+
| -^ expected `}` in format string
6666
| |
6767
| because of this opening brace
6868
|
6969
= note: if you intended to print `{`, you can escape it using `{{`
7070

71-
error: invalid format string: expected `'}'` but string was terminated
71+
error: invalid format string: expected `}` but string was terminated
7272
--> $DIR/format-string-error.rs:21:35
7373
|
7474
LL | let _ = format!("\n\n\n{\n\n\n");
75-
| - ^ expected `'}'` in format string
75+
| - ^ expected `}` in format string
7676
| |
7777
| because of this opening brace
7878
|
7979
= note: if you intended to print `{`, you can escape it using `{{`
8080

81-
error: invalid format string: expected `'}'` but string was terminated
81+
error: invalid format string: expected `}` but string was terminated
8282
--> $DIR/format-string-error.rs:27:3
8383
|
8484
LL | {"###);
85-
| -^ expected `'}'` in format string
85+
| -^ expected `}` in format string
8686
| |
8787
| because of this opening brace
8888
|
8989
= note: if you intended to print `{`, you can escape it using `{{`
9090

91-
error: invalid format string: expected `'}'` but string was terminated
91+
error: invalid format string: expected `}` but string was terminated
9292
--> $DIR/format-string-error.rs:35:1
9393
|
9494
LL | {
9595
| - because of this opening brace
9696
LL |
9797
LL | "###);
98-
| ^ expected `'}'` in format string
98+
| ^ expected `}` in format string
9999
|
100100
= note: if you intended to print `{`, you can escape it using `{{`
101101

0 commit comments

Comments
 (0)