Skip to content

Conversation

macdonaldo
Copy link

When format specifier is missing from the format string:

  • Found format specifiers are pointed at
  • Suggest format specifier if none is present

Fix #68293

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 7, 2020
@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 8, 2020
@jyn514
Copy link
Member

jyn514 commented Sep 8, 2020

This is really good!

r? @estebank

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

I am slightly concerned by making the used formatting specifiers part of the primary multi span, as it semantically implies that there's something problematic about them. Moving that to a note makes it easier to read and I think should help with clarity.

Comment on lines 96 to 102
error: argument never used
--> $DIR/ifmt-bad-arg.rs:33:22
--> $DIR/ifmt-bad-arg.rs:33:14
|
LL | format!("{}", 1, 2);
| ---- ^ argument never used
| -^^- ^ argument never used
| |
| formatting specifier missing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that ideally this would look like

error: argument never used
  --> $DIR/ifmt-bad-arg.rs:33:22
   |
LL |     format!("{}", 1, 2);
   |             ----     ^ argument never used
   |             |
   |             formatting specifier missing
note: the following existing formatting specifiers are used
   |
LL |     format!("{}", 1, 2);
   |              ^^      - used by positional formatting specifier `0`
   |              |
   |              this is positional formatting specifier `0`

In order to accomplish that we would need to

  • keep track of the spans for each formatting specifier and a way to refer to them ("positional specifier 0", "named specifier foo", etc.)
  • look at the mapping for which formatting specifier is used by which argument
  • we'll need to account for named and positional specifiers that are not used

For the proposed output we would need to do something like (simplified):

let note_span: MultiSpan = cx.arg_spans.into();
for span in cx.arg_spans {
    note_span.push_span_label(span, "used argument");
}
for span in errs.iter().map(|&(sp, _)| sp) {
  note_span.push_span_label(span, "argument used here");
}
err.span_note(note_span, "the following existing formatting specifiers are used");

Would you be ok with taking on trying to accomplish this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I'll work on making these changes. Thanks for the feedback!

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 13, 2020
@JohnCSimon
Copy link
Member

JohnCSimon commented Sep 29, 2020

Ping from triage:
@macdonaldo can you post your status on this PR?

@macdonaldo
Copy link
Author

@JohnCSimon I made some progress on this but I'm a bit stuck at the moment, so I asked for help on zulip
@estebank Could you help me out here ?

When format specifier is missing from the format string:
- Found format specifiers are pointed at
- Suggest format specifier if none is present

Fix #68293
@macdonaldo macdonaldo closed this Oct 12, 2020
@macdonaldo
Copy link
Author

Sorry folks, I don't have much time to commit to this at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest examples of format specifiers in error messages
6 participants