-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Style changes to compiler messages #29989
Conversation
(and, some style changes to how the messages are displayed)
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (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. |
@Manishearth A lot of things need to be clarified! Feel free to burn it down :) |
@@ -799,7 +799,7 @@ impl CodeMap { | |||
|
|||
let lo = self.lookup_char_pos_adj(sp.lo); | |||
let hi = self.lookup_char_pos_adj(sp.hi); | |||
return (format!("{}:{}:{}: {}:{}", | |||
return (format!("{}: {}:{} -> {}:{}", |
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.
The space is added only to separate the span from the file name (for visibility).
The colon has been replaced with an arrow, because we already use it to separate the line number from the character number.
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 think the first space shouldn't be there. Many editors let you say open foo.rs:1:2
on the command line and will open focused on that line. It's easier to copy-paste if there is no space.
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 would not use ->
since we use it for function types/signatures. I'd use to
or ...
or keep the :
Now, a single-line error message looks like, (yeah, it's funny)
... and a multi-line warning looks like,
Thoughts? |
Oh no. Look at the travis log! |
That's compiletest not being able to handle the new formatting. We can either add a flag to preserve the old formatting (which we need to do anyway, simple fix) and have compiletest use that, or we can fix up compiletest to handle the new formatting. |
bikeshed:
|
@Manishearth not sure how this relates to @wafflespeanut's example above, so I may be misunderstanding, but...
What does an error message with a macro expansion trace look like? |
The reason I think it should be indented is to visually separate code from error. We already do that with colors, but I think this would be clearer -- easier to see errors when scanning the log |
If the error is indented, then being not indented would give visual separation (in theory, you'd have to have a big example to check). |
@nrc Here's macro expansion
|
Um, we only have a few lines of code. Others are replaced with the ellipsis anyway, right?
The first line in any compiler message shows the entire span where something bad has occurred. Only the other few lines don't have the line numbers. Should we really need the line numbers for all the lines? |
For what it’s worth, there is a GNU standard for source locations in diagnostic messages, which some tools (Emacs?) support out of the box for jumping to and highlighting locations:
It extends easily:
Also, re. relative vs. absolute paths, errors could follow the behaviour of Make’s |
Tagging with T-Tools as I figure it's worth having the Tools team meet to discuss this. |
Personally I feel like rather than have a switch for "legacy error message mode", we should just move forward with nicely-formatted and deliberately-unstable human-readable error messages, with an optional switch to produce machine-readable error messages. That way we can support tools nicely (nicer than the current error messages) while also allowing us to evolve the typical error messages without feeling like everything has to be perfect immediately. For example, I like Elm's use of color in error message to direct the reader's eye (https://www.reddit.com/r/rust/comments/3ti20g/not_rust_specific_compilers_as_assistants_elm_016/), but that's not something that we need to bikeshed immediately. For now just removing the redundant filename to fix #3533 would be a win on its own. |
@evincarofautumn: GNU paths are very handy. One of the small things that annoys me about Elm's errors is the lack of those paths. They don't need to be repeated constantly like rustc currently does, but it would be a shame to lose them in the interests of going too far towards hiding complexity. I guess with machine-readable errors in the future, it might become easier to make 'beginner' and 'advanced' front-ends for error formatting (that may not be desirable though). |
Ugh - your right @bstrie, this is not really the place for bikeshedding this stuff. Sorry! |
@wafflespeanut, I tend to agree with those advocating the GNU style for formatting the file/line/column readout, if only because it's a widely-used precedent and we could spend forever bikeshedding alternatives. For now I think it's still a huge win to just remove the redundant info on every single line and at last put #3533 to bed. |
👍 for anything that makes the messages consume less horizontal space |
I'd like to see an example of serious spew after this change. It's hard to judge the true effect of this from tiny snippets. Adding another line to every error with a span will decrease the overall number of errors per screen. |
I think this is more a @rust-lang/compiler bug than @rust-lang/tools |
The error message already splits to multiple lines because the pathname is so long. |
Yeah, the addition of new lines, whilst a valid concern, is offset by the fact that many of us have to make our terminals super wide to accommodate the long paths. |
triage: I-nominated Nominating for discussion at compiler team meeting. (Basically, even if I reviewed this patch and were 100% happy with its effects, I would not feel comfortable introducing these changes without first discussing with the rest of the compiler team.) |
@pnkfelix Agreed. Also, (for reference), there were a lot of suggestions at /r/rust. |
@wafflespeanut could you provide an example with lots of errors please? (as requested by @brson above). |
I definitely think we should try to follow a standard of some kind for indicating the file/line-number etc :) I was under the impression that we already did, or at least I've seen similar formatting from a number of tools and emacs seems to recognize it "out of the box". I also think we should not be afraid to change the precise formatting of our messages. I consider it unstable and targeting humans, not tools. But I guess no reason to change willy nilly either. |
@wafflespeanut just so this does not get lost in the shuffle: we need a legacy output flag; it was previously described as "a flag to preserve the old formatting", but it might be easier to think of as an output format that is:
|
Yeah, the standard is
Agreed. Though for tools in the long run I think we should provide structured (JSON) output or something. /me idly proposes "spanhandler plugins" |
☔ The latest upstream changes (presumably #30457) made this pull request unmergeable. Please resolve the merge conflicts. |
Well, there are probably many fixed standards. The one that was cited earlier by @evincarofautumn is this GNU page, which proposes:
Interestingly, we don't seem to do any of those today, and yet emacs correctly highlights regions for me, so it must understand some superset of those formats. Also, that web page is a bit weird, since it seems to indicate that |
@brson @nrc "spew of errors" ...
(Note that there are some off-by-one errors while displaying the span, which can be fixed. Also, this applies only to errors - I haven't added newline to the help & note) And, I agree that we need the legacy output flag. I'll update this soon :) |
@wafflespeanut AFAICT this just breaks error listing completely in at least the editors I use. Already type errors are almost useless since the actual type mismatch isn't part of the error message. Maybe the "nicer" multi-line output forms should be restricted to terminal stdout? |
Most editors can be fed a per-language regex for how to decode more complex data from error messages. |
@Manishearth how many of those work with multiple lines per error message? |
No idea. I don't use shortform error listings much. I think here you should just configure your editor to use the legacy output. Editor-friendly output is more often than not human-unfriendly; and one of the core issues this PR was trying to address was that having everything on one line is incredibly ugly and hard for humans to read on split terminals. We should still ensure that things like jump-to-line on a full error listing work on the new system, though. (Since that's easy to get right without impacting readability) |
ISTR that I implemented the range output, and specifically did not follow the standards because the thing that we currently implement worked correctly with emacs whereas others I tried did not. |
I think I am r+ on the intention here but r- on the specific details of this PR. I think we should evolve it more before we land. What I think I would really like to see (some of which is in this PR):
That said, I find the exact output here to have some shortcomings and be not quite ready to land. For example, it seems somewhat inconsistent to have error messages begin on a new line and TL;DR we should iterate on this more, but it's going in a good direction -- and we should take care to ensure that editors continue to work well. :) |
We discussed this at the compiler meeting, conclusions:
|
Awesome! Thanks :) |
fixes #3533