-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tweak format string error to point at arguments always #65746
Conversation
Add secondary span labels with no text to make it clear when there's a mismatch bewteen the positional arguments in a format string and the arguments to the macro. This shouldn't affect experienced users, but it should make it easier for newcomers to more clearly understand how `format!()` and `println!()` are supposed to be used. ``` error: 2 positional arguments in format string, but there is 1 argument --> file8.rs:2:14 | 2 | format!("{} {}", 1); | ^^ ^^ - ``` instead of ``` error: 2 positional arguments in format string, but there is 1 argument --> file8.rs:2:14 | 2 | format!("{} {}", 1); | ^^ ^^ ```
@@ -304,6 +304,9 @@ impl<'a, 'b> Context<'a, 'b> { | |||
self.describe_num_args(), | |||
), | |||
); | |||
for arg in &self.args { // Point at the arguments that will be formatted. | |||
e.span_label(arg.span, ""); |
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.
This use of ""
is fairly weird but it works I suppose. :)
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.
I know, but DiagnosticBuilder<'_>
already handles ""
conceptually as an Option::None
so we might as well (ab)use it 🤷♂
@bors r+ |
📌 Commit 8467cef has been approved by |
Tweak format string error to point at arguments always Add secondary span labels with no text to make it clear when there's a mismatch bewteen the positional arguments in a format string and the arguments to the macro. This shouldn't affect experienced users, but it should make it easier for newcomers to more clearly understand how `format!()` and `println!()` are supposed to be used. ``` error: 2 positional arguments in format string, but there is 1 argument --> file8.rs:2:14 | 2 | format!("{} {}", 1); | ^^ ^^ - ``` instead of ``` error: 2 positional arguments in format string, but there is 1 argument --> file8.rs:2:14 | 2 | format!("{} {}", 1); | ^^ ^^ ``` r? @Centril
Tweak format string error to point at arguments always Add secondary span labels with no text to make it clear when there's a mismatch bewteen the positional arguments in a format string and the arguments to the macro. This shouldn't affect experienced users, but it should make it easier for newcomers to more clearly understand how `format!()` and `println!()` are supposed to be used. ``` error: 2 positional arguments in format string, but there is 1 argument --> file8.rs:2:14 | 2 | format!("{} {}", 1); | ^^ ^^ - ``` instead of ``` error: 2 positional arguments in format string, but there is 1 argument --> file8.rs:2:14 | 2 | format!("{} {}", 1); | ^^ ^^ ``` r? @Centril
Rollup of 8 pull requests Successful merges: - #65625 (Turn crate store into a resolver output) - #65627 (Forbid non-`structural_match` types in const generics) - #65710 (Update cargo) - #65729 (Update test cases for vxWorks) - #65746 (Tweak format string error to point at arguments always) - #65753 (Don't assert for different instance on impl trait alias) - #65755 (Avoid ICE when adjusting bad self ty) - #65766 (Update hashbrown to 0.6.2) Failed merges: r? @ghost
☔ The latest upstream changes (presumably #65771) made this pull request unmergeable. Please resolve the merge conflicts. |
Add secondary span labels with no text to make it clear when there's a
mismatch bewteen the positional arguments in a format string and the
arguments to the macro. This shouldn't affect experienced users, but it
should make it easier for newcomers to more clearly understand how
format!()
andprintln!()
are supposed to be used.instead of
r? @Centril