forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#134877 - DavisRayM:129966-format-string-hel…
…p-message, r=estebank add suggestion for wrongly ordered format parameters Add suggestion for wrongly ordered format parameters like `?#`. Supersedes rust-lang#131004 Fix rust-lang#129966
- Loading branch information
Showing
7 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! Regression test for https://github.com/rust-lang/rust/issues/129966 | ||
//! | ||
//! Ensure we provide suggestion for wrongly ordered format parameters. | ||
//@ run-rustfix | ||
#![allow(dead_code)] | ||
|
||
#[derive(Debug)] | ||
struct Foo(u8, u8); | ||
|
||
fn main() { | ||
let f = Foo(1, 2); | ||
|
||
println!("{f:#?}"); | ||
//~^ ERROR invalid format string: expected `}`, found `#` | ||
//~| HELP did you mean `#?`? | ||
|
||
println!("{f:x?}"); | ||
//~^ ERROR invalid format string: expected `}`, found `x` | ||
//~| HELP did you mean `x?`? | ||
|
||
println!("{f:X?}"); | ||
//~^ ERROR invalid format string: expected `}`, found `X` | ||
//~| HELP did you mean `X?`? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! Regression test for https://github.com/rust-lang/rust/issues/129966 | ||
//! | ||
//! Ensure we provide suggestion for wrongly ordered format parameters. | ||
//@ run-rustfix | ||
#![allow(dead_code)] | ||
|
||
#[derive(Debug)] | ||
struct Foo(u8, u8); | ||
|
||
fn main() { | ||
let f = Foo(1, 2); | ||
|
||
println!("{f:?#}"); | ||
//~^ ERROR invalid format string: expected `}`, found `#` | ||
//~| HELP did you mean `#?`? | ||
|
||
println!("{f:?x}"); | ||
//~^ ERROR invalid format string: expected `}`, found `x` | ||
//~| HELP did you mean `x?`? | ||
|
||
println!("{f:?X}"); | ||
//~^ ERROR invalid format string: expected `}`, found `X` | ||
//~| HELP did you mean `X?`? | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/ui/fmt/suggest-wrongly-order-format-parameter.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error: invalid format string: expected `}`, found `#` | ||
--> $DIR/suggest-wrongly-order-format-parameter.rs:14:19 | ||
| | ||
LL | println!("{f:?#}"); | ||
| ^ expected `'}'` in format string | ||
| | ||
help: did you mean `#?`? | ||
| | ||
LL | println!("{f:#?}"); | ||
| ~~ | ||
|
||
error: invalid format string: expected `}`, found `x` | ||
--> $DIR/suggest-wrongly-order-format-parameter.rs:18:19 | ||
| | ||
LL | println!("{f:?x}"); | ||
| ^ expected `'}'` in format string | ||
| | ||
help: did you mean `x?`? | ||
| | ||
LL | println!("{f:x?}"); | ||
| ~~ | ||
|
||
error: invalid format string: expected `}`, found `X` | ||
--> $DIR/suggest-wrongly-order-format-parameter.rs:22:19 | ||
| | ||
LL | println!("{f:?X}"); | ||
| ^ expected `'}'` in format string | ||
| | ||
help: did you mean `X?`? | ||
| | ||
LL | println!("{f:X?}"); | ||
| ~~ | ||
|
||
error: aborting due to 3 previous errors | ||
|