-
Notifications
You must be signed in to change notification settings - Fork 13k
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 #122556 - jieyouxu:non-identifier-format-arg, r=petro…
…chenkov Extend format arg help for simple tuple index access expression The help is only applicable for simple field access `a.b` and (with this PR) simple tuple index access expressions `a.0`. Closes #122535.
- Loading branch information
Showing
4 changed files
with
70 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Checks that there is a suggestion for simple tuple index access expression (used where an | ||
// identifier is expected in a format arg) to use positional arg instead. | ||
// Issue: <https://github.com/rust-lang/rust/issues/122535>. | ||
//@ run-rustfix | ||
|
||
fn main() { | ||
let x = (1,); | ||
println!("{0}", x.0); | ||
//~^ ERROR invalid format string | ||
} |
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,10 @@ | ||
// Checks that there is a suggestion for simple tuple index access expression (used where an | ||
// identifier is expected in a format arg) to use positional arg instead. | ||
// Issue: <https://github.com/rust-lang/rust/issues/122535>. | ||
//@ run-rustfix | ||
|
||
fn main() { | ||
let x = (1,); | ||
println!("{x.0}"); | ||
//~^ ERROR invalid format string | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/ui/fmt/format-args-non-identifier-diagnostics.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,13 @@ | ||
error: invalid format string: tuple index access isn't supported | ||
--> $DIR/format-args-non-identifier-diagnostics.rs:8:16 | ||
| | ||
LL | println!("{x.0}"); | ||
| ^^^ not supported in format string | ||
| | ||
help: consider using a positional formatting argument instead | ||
| | ||
LL | println!("{0}", x.0); | ||
| ~ +++++ | ||
|
||
error: aborting due to 1 previous error | ||
|