-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Reorder span_suggestions to appear below main labels #40851 #41698
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
Comments
cc @oli-obk |
This is somewhat related to #41695 Here we are already duplicating the error in the main message and again in the note. (See https://github.com/rust-lang/rust/blob/master/src/librustc_borrowck/borrowck/gather_loans/move_error.rs#L138-L144 for the creation of the error and note) In this case I'd just remove the duplication of the message and only show the suggestion inline. But I don't know the rules around this duplication stuff, although I personally dislike it if the message is duplicated. Back to the topic: I think the issue is that https://github.com/rust-lang/rust/blob/master/src/librustc_errors/emitter.rs#L322-L344 sorts the labels according to their start/end column position. So if we have three labels AA, AB, BB where AA and AB have the same span, we might get AA, AB, BB after sorting, then reverse it to BB, AB, AA, but we wanted to get BB, AA, AB (everything with the same span should keep its original order) Right now emitter does: sort notes, reverse notes. |
@oli-obk yes, I agree that this is strongly related to #41695, though I guess that we can have the problem even if the messages aren't the same. It seems like suggestions ought to come last -- I wonder if the general rule should be that you add labels in order of precedence anyhow (i.e., given two labels with same span, we'd prefer the one added first?). |
This can be tagged E-mentor and E-easy. Instructions are given in my previous comment. Feel free to ask me any questions about this here or on irc. |
I'd like to take this one if it's not yet assigned. |
@imanti go ahead! It's all yours |
@oli-obk the problem with the first example is how the list of annotations is being sorted: since both annotation have the exact same values in all fields except the message string, it will always find the suggestion to be bigger. As you pointed out, in these lines https://github.com/rust-lang/rust/blob/master/src/librustc_errors/emitter.rs#L322-L344 the list is being sorted and then reversed. So no matter how's the order of the list before those two lines, it'll always end up with the suggestion first. Consider this snippet (it has the real values for the annotations):
I'm not an expert at all in rust code, but I can't think in a way of generically order these messages without knowing which one is a suggestion and which one not. So let me know your ideas. |
The sorting could be done with sort_by_key to not sort by the message string, which is a useless criterion for sorting anyway |
nice!! I'll try it tonigth at home and let you know. |
@oli-obk sorting by key works as expected:
I created branch here with the changes (just two lines). |
We'll find those examples when the tests fail 😉 could you run the ui tests and fix them with the command line the test failure gives you? Then we can see the changes in the PR. |
Is someone still working on this? |
hmm... I haven't seen that one, But I've noticed that If it still doesn't work, try starting out from a clean checkout of the rust repository |
Suggestions on the output? |
Here are the test fixes |
Yes. Please do so. The tests look much more readable after the changes |
@oli-obk I had a look at this earlier and was wondering if there was any reason to not do a reverse sort instead of the reverse, sort, reverse steps. Like so:
|
That's a great idea. It just never crossed my mind. |
Reorder span suggestions to appear below main labels A fix to #41698 r? @nikomatsakis
This was fixed in #43251. |
Uh oh!
There was an error while loading. Please reload this page.
In #40851, owing to the the fact that suggestions have been moved inline, no doubt is a good idea. But in the case where the span of the suggestion and the span of the main comment coincide, it currently causes the suggestion to appear before the main comment, which seems suboptimal. We should reorder suggestions so they appear below other labels.
Here is the example,
In the move_error.rs
cc @nikomatsakis @estebank
The text was updated successfully, but these errors were encountered: