-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Point spans to inner elements of format strings #52649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
38abca8
4230659
6bcf877
c55a698
bde2be0
f487e39
f9e3762
4d8aa59
3298b9f
7bd94e0
9a893cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
error: 1 positional argument in format string, but no arguments were given | ||
--> $DIR/ifmt-bad-arg.rs:16:14 | ||
| | ||
LL | format!("{}"); | ||
| ^^ | ||
|
||
error: invalid reference to positional argument 1 (there is 1 argument) | ||
--> $DIR/ifmt-bad-arg.rs:19:14 | ||
| | ||
LL | format!("{1}", 1); | ||
| ^^^ | ||
| | ||
= note: positional arguments are zero-based | ||
|
||
error: argument never used | ||
--> $DIR/ifmt-bad-arg.rs:19:20 | ||
| | ||
LL | format!("{1}", 1); | ||
| ^ | ||
|
||
error: 2 positional arguments in format string, but no arguments were given | ||
--> $DIR/ifmt-bad-arg.rs:23:14 | ||
| | ||
LL | format!("{} {}"); | ||
| ^^ ^^ | ||
|
||
error: invalid reference to positional argument 1 (there is 1 argument) | ||
--> $DIR/ifmt-bad-arg.rs:26:14 | ||
| | ||
LL | format!("{0} {1}", 1); | ||
| ^^^ ^^^ | ||
| | ||
= note: positional arguments are zero-based | ||
|
||
error: invalid reference to positional argument 2 (there are 2 arguments) | ||
--> $DIR/ifmt-bad-arg.rs:29:14 | ||
| | ||
LL | format!("{0} {1} {2}", 1, 2); | ||
| ^^^ ^^^ ^^^ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point only to positional argument 2. |
||
| | ||
= note: positional arguments are zero-based | ||
|
||
error: invalid reference to positional argument 2 (there are 2 arguments) | ||
--> $DIR/ifmt-bad-arg.rs:32:14 | ||
| | ||
LL | format!("{} {value} {} {}", 1, value=2); | ||
| ^^ ^^^^^^^ ^^ ^^ | ||
| | ||
= note: positional arguments are zero-based | ||
|
||
error: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments) | ||
--> $DIR/ifmt-bad-arg.rs:34:14 | ||
| | ||
LL | format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2); | ||
| ^^^^^^ ^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point only to positional arguments 3, 4 and 5. |
||
| | ||
= note: positional arguments are zero-based | ||
|
||
error: there is no argument named `foo` | ||
--> $DIR/ifmt-bad-arg.rs:37:17 | ||
| | ||
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); | ||
| ^^^^^ | ||
|
||
error: there is no argument named `bar` | ||
--> $DIR/ifmt-bad-arg.rs:37:26 | ||
| | ||
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); | ||
| ^^^^^ | ||
|
||
error: there is no argument named `foo` | ||
--> $DIR/ifmt-bad-arg.rs:41:14 | ||
| | ||
LL | format!("{foo}"); //~ ERROR: no argument named `foo` | ||
| ^^^^^ | ||
|
||
error: multiple unused formatting arguments | ||
--> $DIR/ifmt-bad-arg.rs:42:17 | ||
| | ||
LL | format!("", 1, 2); //~ ERROR: multiple unused formatting arguments | ||
| -- ^ ^ | ||
| | | ||
| multiple missing formatting arguments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not missing formatting arguments, it's missing formatting specifiers, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
|
||
error: argument never used | ||
--> $DIR/ifmt-bad-arg.rs:43:22 | ||
| | ||
LL | format!("{}", 1, 2); //~ ERROR: argument never used | ||
| ^ | ||
|
||
error: argument never used | ||
--> $DIR/ifmt-bad-arg.rs:44:20 | ||
| | ||
LL | format!("{1}", 1, 2); //~ ERROR: argument never used | ||
| ^ | ||
|
||
error: named argument never used | ||
--> $DIR/ifmt-bad-arg.rs:45:26 | ||
| | ||
LL | format!("{}", 1, foo=2); //~ ERROR: named argument never used | ||
| ^ | ||
|
||
error: argument never used | ||
--> $DIR/ifmt-bad-arg.rs:46:22 | ||
| | ||
LL | format!("{foo}", 1, foo=2); //~ ERROR: argument never used | ||
| ^ | ||
|
||
error: named argument never used | ||
--> $DIR/ifmt-bad-arg.rs:47:21 | ||
| | ||
LL | format!("", foo=2); //~ ERROR: named argument never used | ||
| ^ | ||
|
||
error: multiple unused formatting arguments | ||
--> $DIR/ifmt-bad-arg.rs:48:32 | ||
| | ||
LL | format!("{} {}", 1, 2, foo=1, bar=2); //~ ERROR: multiple unused formatting arguments | ||
| ------- ^ ^ | ||
| | | ||
| multiple missing formatting arguments | ||
|
||
error: duplicate argument named `foo` | ||
--> $DIR/ifmt-bad-arg.rs:50:33 | ||
| | ||
LL | format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument | ||
| ^ | ||
| | ||
note: previously here | ||
--> $DIR/ifmt-bad-arg.rs:50:26 | ||
| | ||
LL | format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument | ||
| ^ | ||
|
||
error: expected ident, positional arguments cannot follow named arguments | ||
--> $DIR/ifmt-bad-arg.rs:51:24 | ||
| | ||
LL | format!("", foo=1, 2); //~ ERROR: positional arguments cannot follow | ||
| ^ | ||
|
||
error: there is no argument named `valueb` | ||
--> $DIR/ifmt-bad-arg.rs:55:23 | ||
| | ||
LL | format!("{valuea} {valueb}", valuea=5, valuec=7); | ||
| ^^^^^^^^ | ||
|
||
error: named argument never used | ||
--> $DIR/ifmt-bad-arg.rs:55:51 | ||
| | ||
LL | format!("{valuea} {valueb}", valuea=5, valuec=7); | ||
| ^ | ||
|
||
error: invalid format string: expected `'}'` but string was terminated | ||
--> $DIR/ifmt-bad-arg.rs:61:15 | ||
| | ||
LL | format!("{"); //~ ERROR: expected `'}'` but string was terminated | ||
| ^ expected `'}'` in format string | ||
| | ||
= note: if you intended to print `{`, you can escape it using `{{` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make this a structured suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll look into this as a follow up, because the output would look a bit bad (it'd have to suggest |
||
|
||
error: invalid format string: unmatched `}` found | ||
--> $DIR/ifmt-bad-arg.rs:63:18 | ||
| | ||
LL | format!("foo } bar"); //~ ERROR: unmatched `}` found | ||
| ^ unmatched `}` in format string | ||
| | ||
= note: if you intended to print `}`, you can escape it using `}}` | ||
|
||
error: invalid format string: unmatched `}` found | ||
--> $DIR/ifmt-bad-arg.rs:64:18 | ||
| | ||
LL | format!("foo }"); //~ ERROR: unmatched `}` found | ||
| ^ unmatched `}` in format string | ||
| | ||
= note: if you intended to print `}`, you can escape it using `}}` | ||
|
||
error: argument never used | ||
--> $DIR/ifmt-bad-arg.rs:66:27 | ||
| | ||
LL | format!("foo %s baz", "bar"); //~ ERROR: argument never used | ||
| ^^^^^ | ||
| | ||
= help: `%s` should be written as `{}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has no span associated with it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
= note: printf formatting not supported; see the documentation for `std::fmt` | ||
|
||
error: aborting due to 26 previous errors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so these are offsets into the format string? A comment would be nice (I'm using this struct in clippy ^^)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added docs.