-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Overhaul borrowck error messages and compiler error formatting generally #32756
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
cc @rust-lang/compiler @rust-lang/tools @mitaa |
I'm super excited about this! Those snippets are really looking great to me. One point is that in the past we've had mixed experience with lots of words colored differently than the default. In Cargo we recently switched from errors as all-red to just the word "error" in red. In the snippets you've pasted, this just applies to:
Altogether I guess I'm just saying we probably shouldn't go too crazy in terms of colorizing words. I might revert back to today's behavior for the filename + error indicator, but the help messages I'd probably leave pretty similar to the way they are in your snippets. |
Oh, cc @brson, with whom I've talked about this a plenty. |
Looks better to me. A big change but it'll probably just take time to adapt.
|
I noticed the carrots |
Very nice.
|
This is very cool. It will essentially make dybuk outdated. |
On a seperate note, it should be possible to configure the style of the error messages. |
I was wondering about this. Do we have one-line errors? Most errors include at least a span, and usually more text. |
I'm torn about the colors on the filename. I agree that coloring the filename red doesn't look as good as it does in emacs, and I also agree it is less necessary if we remove the redundant filenames. For reference, here is an image comparing what I see in emacs (which applies its own colors) vs what the compiler does today http://imgur.com/GZKJ4Pg. Somehow the emacs one looks nice to me, but the imitation thereof in this PR looks a little plodding. It might be that the column numbers are highlighted differently. At the same time, the emacs column numbers have quite a lot of colors, maybe a bit more than is needed. In any case, @brson's observions, combined with @alexcrichton's suggestion that we minimize color, are making think that perhaps we can find a new balance. That said, the current colors arose out of a lot of experimentation -- it's surprisingly hard to find a combination that looks good and achieves a wide variety of goals:
Of course, you might not agree that the current colors achieve that balance. In any case, I don't consider the current choices optimal, and I definitely think there is room to play around more here. (Does anyone know a good "ANSI editor", btw? It'd be helpful to be able to do mock-ups. I guess I can do it in emacs, maybe. Or maybe just write some custom program using |
Also, can we rely on unicode being available? Or auto-detect it? I don't want to have too many modes...but using unicode box-drawing characters would be cool. I remember @kmcallister (I think) had a PR on this that never quite landed. |
For comparison This PR: |
I would be surprised if you could detect unicode support, @nikomatsakis, as it depends on the font being used (or available fallbacks, I guess.) |
Why not just have a variable, |
That's awesome! However, like others already said, why not replacing "~" by "^"? Also, why not setting a different color for error lines? I think that having the filename with its own and unique color would improve the display and help to understand what we're reading more quickly. |
I'd much rather make it opt-out. I think the real question is what scheme we want to use for controlling rustc's "skin". We have some compile flags for using colors, which is an obvious precedent, but also doesn't seem that great; this is something that a user would want to decide, and probably uniformly. Maybe we should look for |
@ticki yeah, I was thinking that maybe the thing to do is to put the error underneath the filename/line-number. In general I think it's probably a win to use more vertical space when formatting errors. As long as emacs can still take me to the next error, I'm happy with that. =) |
For reference, here's the pull request: #21406. EDIT: And the follow-up issue: #24387. EDITEDIT: Another relevant issue: #28902. |
I like the general appearance, here’s some notes:
The box drawing symbols exist since Unicode 1.1. Rust does not support systems with non-utf-8 locales anyway… the only problem is the Windows’ The cmd doesn’t use ANSI and thus must be reliably detected and worked around anyway, so…
Axe-actly! In my experience barely any default and non-trivial colouring works well with solarized, so we should probably either restrict ourselves to the most barebones escape codes and colours like colours 1-to-6 and inverse or allow configuration of them. looks hard to figure out which spans relate to which messages. What happens when these spans overlap?
Using |
You're looking at it. The two labels there are attached to the same span. |
One more inevitable thing is that a lot of docs are going to be showing old errors. Not a showstopper for this PR, mind you, but something that needs to be considered to some degree. |
To me it looks like that’s two notes attached to two adjacent spans of length 1. One span on
|
I wonder if there's any way to automate the inclusion of errors. |
Yeah, that's actually true in this particular case, I didn't look closely enough. In any case, what the PR currently does is to union all |
So what do people think about using unicode except for when running on windows, since apparently cmd doesn't support unicode? |
Overhaul borrowck error messages and compiler error formatting generally This is a major overhaul of how the compiler reports errors. The primary goal is to be able to give many spans within the same overall context, such as this: ``` ./borrow-errors.rs:73:17: 73:20: error: cannot borrow `*vec` as immutable because previous closure requires unique access [E0501] 70 let append = |e| { ~~~ closure construction occurs here 71 vec.push(e) ~~~ previous borrow occurs due to use of `vec` in closure 72 }; 73 let data = &vec[3]; ~~~ borrow occurs here 74 } ~ borrow from closure ends here ``` However, in the process we made a number of other changes: - Removed the repetitive filenames from snippets and just give the line number. - Color the line numbers blue so they "fade away" - Remove the file name and line number from the error code suggestions since they don't seem to fit anymore. (This should probably happen in more places, like existing notes.) - Newlines in between errors to help group them better. This PR is not quite ready to land, but we thought it made sense to stop here and get some feedback from people at large. It'd be great if people can check out the branch and play with it. We'd be especially interested in hearing about cases that don't look good with the new formatting (I suspect they exist). Here is a checklist of some pending work items for this PR. Some of them may be best left for follow-up PRs: - [x] Accommodate multiple files in a `MultiSpan` (this should be easy) - In this case, we want to print filenames though. - [x] Remove duplicate E0500 code. - [x] Make the header message bold, rather than current hack that makes all errors/warnings bold - [x] Update warning text color (yellow is hard to read w/ a white background) Moved numerous follow-ups to: rust-lang#33240 Joint work with @jonathandturner. Fixes rust-lang#3533
⛄ The build was interrupted to prioritize another pull request. |
⌛ Testing commit 9355a91 with merge 44b3cd8... |
Overhaul borrowck error messages and compiler error formatting generally This is a major overhaul of how the compiler reports errors. The primary goal is to be able to give many spans within the same overall context, such as this: ``` ./borrow-errors.rs:73:17: 73:20: error: cannot borrow `*vec` as immutable because previous closure requires unique access [E0501] 70 let append = |e| { ~~~ closure construction occurs here 71 vec.push(e) ~~~ previous borrow occurs due to use of `vec` in closure 72 }; 73 let data = &vec[3]; ~~~ borrow occurs here 74 } ~ borrow from closure ends here ``` However, in the process we made a number of other changes: - Removed the repetitive filenames from snippets and just give the line number. - Color the line numbers blue so they "fade away" - Remove the file name and line number from the error code suggestions since they don't seem to fit anymore. (This should probably happen in more places, like existing notes.) - Newlines in between errors to help group them better. This PR is not quite ready to land, but we thought it made sense to stop here and get some feedback from people at large. It'd be great if people can check out the branch and play with it. We'd be especially interested in hearing about cases that don't look good with the new formatting (I suspect they exist). Here is a checklist of some pending work items for this PR. Some of them may be best left for follow-up PRs: - [x] Accommodate multiple files in a `MultiSpan` (this should be easy) - In this case, we want to print filenames though. - [x] Remove duplicate E0500 code. - [x] Make the header message bold, rather than current hack that makes all errors/warnings bold - [x] Update warning text color (yellow is hard to read w/ a white background) Moved numerous follow-ups to: #33240 Joint work with @jonathandturner. Fixes #3533
Overhaul borrowck error messages and compiler error formatting generally This is a major overhaul of how the compiler reports errors. The primary goal is to be able to give many spans within the same overall context, such as this: ``` ./borrow-errors.rs:73:17: 73:20: error: cannot borrow `*vec` as immutable because previous closure requires unique access [E0501] 70 let append = |e| { ~~~ closure construction occurs here 71 vec.push(e) ~~~ previous borrow occurs due to use of `vec` in closure 72 }; 73 let data = &vec[3]; ~~~ borrow occurs here 74 } ~ borrow from closure ends here ``` However, in the process we made a number of other changes: - Removed the repetitive filenames from snippets and just give the line number. - Color the line numbers blue so they "fade away" - Remove the file name and line number from the error code suggestions since they don't seem to fit anymore. (This should probably happen in more places, like existing notes.) - Newlines in between errors to help group them better. This PR is not quite ready to land, but we thought it made sense to stop here and get some feedback from people at large. It'd be great if people can check out the branch and play with it. We'd be especially interested in hearing about cases that don't look good with the new formatting (I suspect they exist). Here is a checklist of some pending work items for this PR. Some of them may be best left for follow-up PRs: - [x] Accommodate multiple files in a `MultiSpan` (this should be easy) - In this case, we want to print filenames though. - [x] Remove duplicate E0500 code. - [x] Make the header message bold, rather than current hack that makes all errors/warnings bold - [x] Update warning text color (yellow is hard to read w/ a white background) Moved numerous follow-ups to: rust-lang#33240 Joint work with @jonathandturner. Fixes rust-lang#3533
🎉 |
I really like the new approach posted by @jonathandturner in #32756 (comment) , particularly the method of highlighting the primary error. Two remaining issues with it, one minor, one major:
|
This is really a sticking point. I'm not really sure what's the best fix here. I think that the current format with the
OTOH, I really want to enable "low-tech" editor integration. One thing we've debated about is having a "third mode". For example, perhaps we DO use an environment variable (
in front of the error. This is intended for your editor to match on, basically. (The downside of this is that the message would appear twice, which is a shame.) The reason I've come to favor an env var for this purpose is that one can easily set it in the editor's setup and have it "propagate down" to compilations executed by the editor, but not affect compilations done by hand on the console. But I guess the other question is how easy it will be to adjust editor modes to the new format as it exists today. For example, I opened this PR on the emacs mode rust-lang/rust-mode#154. If we can just get editors to either use JSON or else use the default format, that might be best. |
I think that this form of integration is hacky. IDEs should prefer JSON. |
@nikomatsakis I absolutely agree that this format is more usable by humans, just not by existing editors. I don't think it's reasonable to require an environment variable for this; error message parsing and handling should work out of the box. Right now, I have no Rust support in vim (because the Vim mode for Rust isn't packaged in Debian), and I regularly use Having an environment variable and command-line option for explicit handling, or for IDEs/editors that want to implement special support for Rust, seems like a good idea. However, I would suggest that the default should be "auto", which would imply "normal" if stderr is a TTY, or "header" if it isn't. @ticki Current generation IDEs with specifically designed support for Rust might, but we can't write off decades of programmer's editors and the conventions they expect. The standard error message format is |
It is only a de facto convention, not standard. There’s a bunch of things that do not honour the convention as well. |
Yeah, most compilers use that, so it wouldn't make sense to drop it. I simply think that for Rust-specific IDEs, there should be more emphasis on JSON, since it is strictly less ambigious and spec-able |
@ticki Absolutely agreed; anything doing more than the most basic parsing should use the JSON format. @nagisa Half the world runs smoothly because of de-facto conventions. The default configuration shouldn't break people's preferred editors. Again, we're not talking about changing the default format for terminal use; we're talking about automatically detecting when output goes to a log and adding a line to simplify parsing. @nikomatsakis One other aspect of the "header" format: it needs to not include the |
Rather than discussing this "header format" on this closed PR, I propose we move the conversation here: http://internals.rust-lang.org/t/editor-compatibility-and-the-new-error-format/3435 I tried to summarize the salient points. |
…=jntrnr degrade gracefully with empty spans In rust-lang#32756, we solved the final test failure, but digging more into it the handling of that scenario could be better. The error was caused by an empty span supplied by the parser representing EOF. This patch checks that we cope more gracefully with such spans: r? @jonathandturner
…=jntrnr degrade gracefully with empty spans In rust-lang#32756, we solved the final test failure, but digging more into it the handling of that scenario could be better. The error was caused by an empty span supplied by the parser representing EOF. This patch checks that we cope more gracefully with such spans: r? @jonathandturner
This is a major overhaul of how the compiler reports errors. The primary goal is to be able to give many spans within the same overall context, such as this:
However, in the process we made a number of other changes:
This PR is not quite ready to land, but we thought it made sense to stop here and get some feedback from people at large. It'd be great if people can check out the branch and play with it. We'd be especially interested in hearing about cases that don't look good with the new formatting (I suspect they exist).
Here is a checklist of some pending work items for this PR. Some of them may be best left for follow-up PRs:
MultiSpan
(this should be easy)Moved numerous follow-ups to: #33240
Joint work with @jonathandturner.
Fixes #3533