Skip to content
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

Multiple unused formatting argument are now labels, less unused argument spam #41256

Closed
wants to merge 1 commit into from
Closed

Multiple unused formatting argument are now labels, less unused argument spam #41256

wants to merge 1 commit into from

Conversation

Nickforall
Copy link

@Nickforall Nickforall commented Apr 12, 2017

As my first contribution to the Rust compiler I took a shot at the issue #37718. Instead of printing a list of notes for every individual unused argument, it now displays what arguments are unused underneath each argument, using the span_label function from the DiagnosticBuilder struct.

Example:

error: multiple unused formatting arguments
  -->  /Users/nickvernij/Programming/rust/src/test/ui/macros/format-foreign.rs:12:5
   |
12 |     println!("%.*3$s %s!/n", "Hello,", "World", 4);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^--------^^-------^^-^^
   |                              |         |        |
   |                              |         |        unused
   |                              |         unused
   |                              unused
   |

I modified the test that was used before this change, and added a test that checks this method with a function whose arguments are written on multiple lines.

I ran the style guideline test as described in the contributing guidelines, and a test on the UI tests. Again, this is my first PR here, so I might've missed something somewhere.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (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.

@alexcrichton
Copy link
Member

r? @jonathandturner

@rust-highfive rust-highfive assigned sophiajt and unassigned brson Apr 13, 2017
@shepmaster
Copy link
Member

Thanks for the hard work! We'll make sure that @jonathandturner (or someone else) reviews this soon!

@arielb1 arielb1 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 15, 2017
@sophiajt
Copy link
Contributor

Thanks for the PR!

Let's see, taking a look I think this is an improvement, though I'm not sure if this:

error: multiple unused formatting arguments
  -->  /Users/nickvernij/Programming/rust/src/test/ui/macros/format-foreign.rs:12:5
   |
12 |     println!("%.*3$s %s!/n", "Hello,", "World", 4);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^--------^^-------^^-^^
   |                              |         |        |
   |                              |         |        unused
   |                              |         unused
   |                              unused
   |

Reads better than what we have now. Generally, we've been trying to avoid having both primary and secondary underlines on the same spans. This makes the line harder for the eye to parse.

In theory, I think we support having multiple lines as the primary error, so using the MultiSpan in this case.

The design I'm wondering if we can get to is something like this:

error: multiple unused formatting arguments
  -->  /Users/nickvernij/Programming/rust/src/test/ui/macros/format-foreign.rs:12:5
   |
12 |     println!("%.*3$s %s!/n", "Hello,", "World", 4);
   |                              ^^^^^^^^  ^^^^^^^  ^  
   |                              |         |        |
   |                              ------------------------- unused

That said, I'm not sure if that's an easy fix. If not, then yeah, I think what you have is probably okay.

@sophiajt sophiajt 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 Apr 17, 2017
@Nickforall
Copy link
Author

Thank you for your response. I think it's definitely easier to parse for the eye than the current output, but I get your point.

I'm not too familiar with the codebase yet, so I'll look around in the code/docs a bit, and see if I can get something that looks more like the output you're proposing here.

@sophiajt
Copy link
Contributor

@Nickforall - yeah, definitely.

Here's the MultiSpan I thought you could use: https://github.com/rust-lang/rust/blob/master/src/librustc_errors/diagnostic.rs#L25

If you put the spans together and created a MultiSpan, and used that... I'm honestly sure what will happen 😅 but perhaps it'll work?

Like I said, if it doesn't we can definitely go in the direction of this PR, but I at least wanted to explore a little first.

@Nickforall
Copy link
Author

I've looked through the documentation for span_labels/multispans and throught other errors, but haven't really found a similar case.

So my guess here is that it requires work in the code that renders the error, I've looked through that code, and it doesn't seem like an easy fix to me.

@shepmaster shepmaster added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 21, 2017
@sophiajt
Copy link
Contributor

I'm fine approving this if you want to file a follow up issue to do the next part of the work to see if someone else wants to do it

@sophiajt sophiajt 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 Apr 25, 2017
@arielb1
Copy link
Contributor

arielb1 commented May 2, 2017

@Nickforall and @jonathandturner - friendly ping to keep this on your radar.

@sophiajt
Copy link
Contributor

sophiajt commented May 3, 2017

I believe we're waiting on author feedback on this one.

@Nickforall
Copy link
Author

@arielb1 @jonathandturner I'm quite busy with school this week, I set a reminder in my agenda for the weekend to finish this one.

@Nickforall
Copy link
Author

Hi @jonathandturner, I created the follow-up issue (#41850)

|
13 | println!("%1$*2$.*3$f", 123.456);
20 | println!("%1$*2$.*3$f", 123.456);
| ^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we put a label here also?

|
17 | println!("{} %f", "one", 2.0);
24 | println!("{} %f", "one", 2.0);
| ^^^
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

|
19 | println!("Hi there, $NAME.", NAME="Tim");
26 | println!("Hi there, $NAME.", NAME="Tim");
| ^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

@sophiajt
Copy link
Contributor

@Nickforall - great, thanks for filing the issue. Looks like we're close. I didn't see this missing label last time, but I think after we add that we should be good to go.

@arielb1
Copy link
Contributor

arielb1 commented May 16, 2017

🕸 Closing due to inactivity to keep our backlog clean 🕸. Feel free to reopen @Nickforall!

@arielb1 arielb1 closed this May 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

7 participants