forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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#106805 - madsravn:master, r=compiler-errors
Suggest `{var:?}` when finding `{?:var}` in inline format strings Link to issue: rust-lang#106572 This is my first PR to this project, so hopefully I can get some good pointers with me from the first PR. Currently my idea was to test out whether or not this is the correct solution to this issue and then hopefully expand upon the idea to not only work for Debug formatting but for all of them. If this is a valid solution, I will create a new issue to give a better error message to a broader range of wrong-order formatting.
- Loading branch information
Showing
3 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
fn main() { | ||
let bar = 3; | ||
format!("{?:}", bar); | ||
//~^ ERROR invalid format string: expected format parameter to occur after `:` | ||
format!("{?:bar}"); | ||
//~^ ERROR invalid format string: expected format parameter to occur after `:` | ||
format!("{?:?}", bar); | ||
//~^ ERROR invalid format string: expected format parameter to occur after `:` | ||
format!("{??}", bar); | ||
//~^ ERROR invalid format string: expected `'}'`, found `'?'` | ||
format!("{?;bar}"); | ||
//~^ ERROR invalid format string: expected `'}'`, found `'?'` | ||
format!("{?:#?}", bar); | ||
//~^ ERROR invalid format string: expected format parameter to occur after `:` | ||
} |
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,54 @@ | ||
error: invalid format string: expected format parameter to occur after `:` | ||
--> $DIR/format-string-wrong-order.rs:3:15 | ||
| | ||
LL | format!("{?:}", bar); | ||
| ^ expected `?` to occur after `:` in format string | ||
| | ||
= note: `?` comes after `:`, try `:?` instead | ||
|
||
error: invalid format string: expected format parameter to occur after `:` | ||
--> $DIR/format-string-wrong-order.rs:5:15 | ||
| | ||
LL | format!("{?:bar}"); | ||
| ^ expected `?` to occur after `:` in format string | ||
| | ||
= note: `?` comes after `:`, try `bar:?` instead | ||
|
||
error: invalid format string: expected format parameter to occur after `:` | ||
--> $DIR/format-string-wrong-order.rs:7:15 | ||
| | ||
LL | format!("{?:?}", bar); | ||
| ^ expected `?` to occur after `:` in format string | ||
| | ||
= note: `?` comes after `:`, try `:?` instead | ||
|
||
error: invalid format string: expected `'}'`, found `'?'` | ||
--> $DIR/format-string-wrong-order.rs:9:15 | ||
| | ||
LL | format!("{??}", bar); | ||
| -^ 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 `'?'` | ||
--> $DIR/format-string-wrong-order.rs:11:15 | ||
| | ||
LL | format!("{?;bar}"); | ||
| -^ 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 format parameter to occur after `:` | ||
--> $DIR/format-string-wrong-order.rs:13:15 | ||
| | ||
LL | format!("{?:#?}", bar); | ||
| ^ expected `?` to occur after `:` in format string | ||
| | ||
= note: `?` comes after `:`, try `:?` instead | ||
|
||
error: aborting due to 6 previous errors | ||
|