Skip to content

Commit

Permalink
Rollup merge of rust-lang#131710 - ShE3py:parse_format_apostrophes, r…
Browse files Browse the repository at this point in the history
…=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
  • Loading branch information
matthiaskrgr authored Oct 15, 2024
2 parents d82a49d + dda3066 commit c99c4d4
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 83 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_index_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
proc-macro = true

[dependencies]
syn = { version = "2.0.9", features = ["full"] }
syn = { version = "2.0.9", features = ["full", "extra-traits"] }
proc-macro2 = "1"
quote = "1"

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,19 +473,19 @@ impl<'a> Parser<'a> {
}

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

let pos = self.to_span_index(pos);

let label = "expected `'}'`".to_owned();
let label = "expected `}`".to_owned();
let (note, secondary_label) = if arg.format.fill == Some('}') {
(
Some("the character `'}'` is interpreted as a fill character because of the `:` that precedes it".to_owned()),
Some("the character `}` is interpreted as a fill character because of the `:` that precedes it".to_owned()),
arg.format.fill_span.map(|sp| ("this is not interpreted as a formatting closing brace".to_owned(), sp)),
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct ErrorWithNonexistentField {
}

#[derive(Diagnostic)]
//~^ ERROR invalid format string: expected `'}'`
//~^ ERROR invalid format string: expected `}`
#[diag(no_crate_example, code = E0123)]
struct ErrorMissingClosingBrace {
#[suggestion(no_crate_suggestion, code = "{name")]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ error: `name` doesn't refer to a field on this type
LL | #[suggestion(no_crate_suggestion, code = "{name}")]
| ^^^^^^^^

error: invalid format string: expected `'}'` but string was terminated
error: invalid format string: expected `}` but string was terminated
--> $DIR/diagnostic-derive.rs:180:10
|
LL | #[derive(Diagnostic)]
| ^^^^^^^^^^ expected `'}'` in format string
| ^^^^^^^^^^ expected `}` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
= note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ trait ImportantTrait3 {}
trait ImportantTrait4 {}

#[diagnostic::on_unimplemented(message = "Test {Self:!}")]
//~^WARN expected `'}'`, found `'!'`
//~|WARN expected `'}'`, found `'!'`
//~^WARN expected `}`, found `!`
//~|WARN expected `}`, found `!`
//~|WARN unmatched `}` found
//~|WARN unmatched `}` found
trait ImportantTrait5 {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LL | #[diagnostic::on_unimplemented(message = "Test {Self:123}")]
|
= help: no format specifier are supported in this position

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

warning: expected `'}'`, found `'!'`
warning: expected `}`, found `!`
--> $DIR/broken_format.rs:21:32
|
LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fmt/closing-brace-as-fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

fn main() {
println!("Hello, world! {0:}<3", 2);
//~^ ERROR invalid format string: expected `'}'` but string was terminated
//~^ ERROR invalid format string: expected `}` but string was terminated
}
6 changes: 3 additions & 3 deletions tests/ui/fmt/closing-brace-as-fill.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: invalid format string: expected `'}'` but string was terminated
error: invalid format string: expected `}` but string was terminated
--> $DIR/closing-brace-as-fill.rs:6:35
|
LL | println!("Hello, world! {0:}<3", 2);
| - ^ expected `'}'` in format string
| - ^ expected `}` in format string
| |
| this is not interpreted as a formatting closing brace
|
= note: the character `'}'` is interpreted as a fill character because of the `:` that precedes it
= note: the character `}` is interpreted as a fill character because of the `:` that precedes it

error: aborting due to 1 previous error

2 changes: 1 addition & 1 deletion tests/ui/fmt/format-string-error-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ raw { \n

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

println!("\x7B}\u8 {", 1);
//~^ ERROR incorrect unicode escape sequence
Expand Down
56 changes: 28 additions & 28 deletions tests/ui/fmt/format-string-error-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,138 +9,138 @@ help: format of unicode escape sequences uses braces
LL | println!("\x7B}\u{8} {", 1);
| ~~~~~

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

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

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

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

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

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

error: invalid format string: expected `'}'`, found `'a'`
error: invalid format string: expected `}`, found `a`
--> $DIR/format-string-error-2.rs:29:5
|
LL | {
| - because of this opening brace
LL | a
| ^ expected `'}'` in format string
| ^ expected `}` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`

error: invalid format string: expected `'}'`, found `'b'`
error: invalid format string: expected `}`, found `b`
--> $DIR/format-string-error-2.rs:35:5
|
LL | { \
| - because of this opening brace
LL | \
LL | b");
| ^ expected `'}'` in format string
| ^ expected `}` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`

error: invalid format string: expected `'}'`, found `'b'`
error: invalid format string: expected `}`, found `b`
--> $DIR/format-string-error-2.rs:40:5
|
LL | { \
| - because of this opening brace
LL | \
LL | b \
| ^ expected `'}'` in format string
| ^ expected `}` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`

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

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

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

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

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

error: invalid format string: expected `'}'` but string was terminated
error: invalid format string: expected `}` but string was terminated
--> $DIR/format-string-error-2.rs:74:27
|
LL | println!("\x7B}\u{8} {", 1);
| -^ expected `'}'` in format string
| -^ expected `}` in format string
| |
| because of this opening brace
|
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/fmt/format-string-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

fn main() {
println!("{");
//~^ ERROR invalid format string: expected `'}'` but string was terminated
//~^ ERROR invalid format string: expected `}` but string was terminated
println!("{{}}");
println!("}");
//~^ ERROR invalid format string: unmatched `}` found
Expand All @@ -13,11 +13,11 @@ fn main() {
let _ = format!("{a:._$}", a = "", _ = 0);
//~^ ERROR invalid format string: invalid argument name `_`
let _ = format!("{");
//~^ ERROR invalid format string: expected `'}'` but string was terminated
//~^ ERROR invalid format string: expected `}` but string was terminated
let _ = format!("}");
//~^ ERROR invalid format string: unmatched `}` found
let _ = format!("{\\}");
//~^ ERROR invalid format string: expected `'}'`, found `'\'`
//~^ ERROR invalid format string: expected `}`, found `\`
let _ = format!("\n\n\n{\n\n\n");
//~^ ERROR invalid format string
let _ = format!(r###"
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/fmt/format-string-error.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: invalid format string: expected `'}'` but string was terminated
error: invalid format string: expected `}` but string was terminated
--> $DIR/format-string-error.rs:4:16
|
LL | println!("{");
| -^ expected `'}'` in format string
| -^ expected `}` in format string
| |
| because of this opening brace
|
Expand Down Expand Up @@ -40,11 +40,11 @@ LL | let _ = format!("{a:._$}", a = "", _ = 0);
|
= note: argument name cannot be a single underscore

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

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

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

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

error: invalid format string: expected `'}'` but string was terminated
error: invalid format string: expected `}` but string was terminated
--> $DIR/format-string-error.rs:35:1
|
LL | {
| - because of this opening brace
LL |
LL | "###);
| ^ expected `'}'` in format string
| ^ expected `}` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`

Expand Down
Loading

0 comments on commit c99c4d4

Please sign in to comment.