-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 #100058 - TaKO8Ki:suggest-positional-formatting-argum…
…ent-instead-of-format-args-capture, r=estebank Suggest a positional formatting argument instead of a captured argument This patch fixes a part of #96999. fixes #98241 fixes #97311 r? `@estebank`
- Loading branch information
Showing
5 changed files
with
182 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// run-rustfix | ||
|
||
#[derive(Debug)] | ||
struct Foo { | ||
field: usize, | ||
} | ||
|
||
fn main() { | ||
let foo = Foo { field: 0 }; | ||
let bar = 3; | ||
format!("{0}", foo.field); //~ ERROR invalid format string: field access isn't supported | ||
format!("{1} {} {bar}", "aa", foo.field); //~ ERROR invalid format string: field access isn't supported | ||
format!("{2} {} {1} {bar}", "aa", "bb", foo.field); //~ ERROR invalid format string: field access isn't supported | ||
format!("{1} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported | ||
format!("{1:?} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported | ||
format!("{1:#?} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported | ||
format!("{1:.3} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported | ||
} |
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,18 @@ | ||
// run-rustfix | ||
|
||
#[derive(Debug)] | ||
struct Foo { | ||
field: usize, | ||
} | ||
|
||
fn main() { | ||
let foo = Foo { field: 0 }; | ||
let bar = 3; | ||
format!("{foo.field}"); //~ ERROR invalid format string: field access isn't supported | ||
format!("{foo.field} {} {bar}", "aa"); //~ ERROR invalid format string: field access isn't supported | ||
format!("{foo.field} {} {1} {bar}", "aa", "bb"); //~ ERROR invalid format string: field access isn't supported | ||
format!("{foo.field} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported | ||
format!("{foo.field:?} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported | ||
format!("{foo.field:#?} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported | ||
format!("{foo.field:.3} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported | ||
} |
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,79 @@ | ||
error: invalid format string: field access isn't supported | ||
--> $DIR/struct-field-as-captured-argument.rs:11:15 | ||
| | ||
LL | format!("{foo.field}"); | ||
| ^^^^^^^^^ not supported in format string | ||
| | ||
help: consider using a positional formatting argument instead | ||
| | ||
LL | format!("{0}", foo.field); | ||
| ~ +++++++++++ | ||
|
||
error: invalid format string: field access isn't supported | ||
--> $DIR/struct-field-as-captured-argument.rs:12:15 | ||
| | ||
LL | format!("{foo.field} {} {bar}", "aa"); | ||
| ^^^^^^^^^ not supported in format string | ||
| | ||
help: consider using a positional formatting argument instead | ||
| | ||
LL | format!("{1} {} {bar}", "aa", foo.field); | ||
| ~ +++++++++++ | ||
|
||
error: invalid format string: field access isn't supported | ||
--> $DIR/struct-field-as-captured-argument.rs:13:15 | ||
| | ||
LL | format!("{foo.field} {} {1} {bar}", "aa", "bb"); | ||
| ^^^^^^^^^ not supported in format string | ||
| | ||
help: consider using a positional formatting argument instead | ||
| | ||
LL | format!("{2} {} {1} {bar}", "aa", "bb", foo.field); | ||
| ~ +++++++++++ | ||
|
||
error: invalid format string: field access isn't supported | ||
--> $DIR/struct-field-as-captured-argument.rs:14:15 | ||
| | ||
LL | format!("{foo.field} {} {baz}", "aa", baz = 3); | ||
| ^^^^^^^^^ not supported in format string | ||
| | ||
help: consider using a positional formatting argument instead | ||
| | ||
LL | format!("{1} {} {baz}", "aa", foo.field, baz = 3); | ||
| ~ +++++++++++ | ||
|
||
error: invalid format string: field access isn't supported | ||
--> $DIR/struct-field-as-captured-argument.rs:15:15 | ||
| | ||
LL | format!("{foo.field:?} {} {baz}", "aa", baz = 3); | ||
| ^^^^^^^^^ not supported in format string | ||
| | ||
help: consider using a positional formatting argument instead | ||
| | ||
LL | format!("{1:?} {} {baz}", "aa", foo.field, baz = 3); | ||
| ~ +++++++++++ | ||
|
||
error: invalid format string: field access isn't supported | ||
--> $DIR/struct-field-as-captured-argument.rs:16:15 | ||
| | ||
LL | format!("{foo.field:#?} {} {baz}", "aa", baz = 3); | ||
| ^^^^^^^^^ not supported in format string | ||
| | ||
help: consider using a positional formatting argument instead | ||
| | ||
LL | format!("{1:#?} {} {baz}", "aa", foo.field, baz = 3); | ||
| ~ +++++++++++ | ||
|
||
error: invalid format string: field access isn't supported | ||
--> $DIR/struct-field-as-captured-argument.rs:17:15 | ||
| | ||
LL | format!("{foo.field:.3} {} {baz}", "aa", baz = 3); | ||
| ^^^^^^^^^ not supported in format string | ||
| | ||
help: consider using a positional formatting argument instead | ||
| | ||
LL | format!("{1:.3} {} {baz}", "aa", foo.field, baz = 3); | ||
| ~ +++++++++++ | ||
|
||
error: aborting due to 7 previous errors | ||
|