-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Stop prepending the path and line number to every line in error messages #3533
Comments
We could also print the relative path instead of absolute. Whatever the solution it needs to be compatible with emacs's compilation buffers. |
Brian Anderson wrote:
I wanted to say the same thing. The current situation is nice (for me) |
Does compatibility with emacs' compilation buffers require prepending paths and line numbers to each line? |
Emacs supports a variety of error reporting formats, so I imagine we have some flexibility. Finding out exactly what it accepts may require reading the code. We will need to make sure it's ok with vim users to. |
I think the answer is no though. If emacs decides a line is an error message it will try to interpret it, otherwise it will just print it. Some lines must be crafted to look special to emacs, other lines must be careful to not look special. |
Building on @bstrie's example, I think it would be even better if it was made explicit which
(I also changed the span in question to just cover the trait name, rather than the whole trait block). |
Bumping to 0.7 |
Not critical for 0.7, de-milestoning. |
Nominating for production ready. B-Clarifying to work out the exact output desired. |
not accepted for production ready |
Traige: still a problem. My preference is for relative paths in the error/warnings/notes and no paths/spans on the code itself. Some examples of other compilers (all invoked Haskellmain = putStrLn 1 GHC
Works with Hugs
Doesn't work. Cint main() { main + main; } GCC
Works. Clang
Works. Dmodule main;
void main() { return 1; } LDC2
Doesn't work. GDC
Mostly works (the Gopackage main
func main() { "foo" + 1 } play.golang.org
(My package manager isn't letting me install straight golang atm.) GCCGO
Works. |
The answer to this question was indeed "no." (I've become much more intimate with compilation mode since tackling #6887.) |
Triage: Still valid. The path is now relative but it's still printed for every line. I also prefer file and line numbers in errors/warnings/notes messages and nothing on the code trait test {}
fn main() {}
|
It's also annoying for readers that errors usually print very long lines that wrap and are very hard to read rather than splitting them up intelligently so that they look good even on trim terminals. |
No. #11715 just fixes the line numbers to line up properly when we go from 9 to 10, or 99 to 100, as the formatting broke by one space. If we removed the line numbers and column numbers, it would be moot. |
Relevant code: rust/src/libsyntax/diagnostic.rs Line 464 in ca4b967
We should split that to handle one-line and multi-line errors, keeping one-line errors as is and indenting multi-line errors by a fixed amount instead of appending the line number. |
Should there be a CLI flag for turning this off? |
@wafflespeanut is working on this Note: We should preserve the old behavior with a rust flag like --machine-readable-errors or something for IDEs |
I'm fine with having a flag to re-enable verbose error output for the purpose of IDEs, but the other comments in this thread seem to imply that's not actually necessary. What IDEs need output like this? |
VisualRust is parsing rustc output, but that's actually not very robust at the moment, so we need to change something there anyway. I'm also looking forward to having a structured machine-readable output format as proposed in https://github.com/nrc/rfcs/blob/ide/text/0000-ide.md#error-format. I'd say that the way forward is to have separate output formats for humans (focusing on readability) and IDEs, but the latter should not be what we have right now. |
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: #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
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
fix Comma in comment causes no formatting
…eferences, r=RalfJung Make file descriptors into refcount references fixes rust-lang#3525 Remove `fn dup` in `trait FileDescription`, define `struct FileDescriptor(Rc<RefCell<dyn FileDescription>>)`, and use `BTreeMap<i32, FileDescriptor>` in `FdTable`. --- There are some refactors similar to the following form: ```rust { // origin: if let Some(file_descriptor) = this.machine.fds.get_mut(fd) { // write file_descriptor this.try_unwrap_io_result(result) } else { this.fd_not_found() } } { // now: let Some(mut file_descriptor) = this.machine.fds.get_mut(fd) else { return this.fd_not_found(); }; // write file_descriptor drop(file_descriptor); this.try_unwrap_io_result(result) } ``` The origin form can't compile because as using `RefCell` to get interior mutability, `fn get_mut` return `Option<std::cell::RefMut<'_, dyn FileDescription>>` instead of `Option<&mut dyn FileDescription>` now, and the `deref_mut` on `file_descriptor: RefMut` will cause borrow `this` as mutable more than once at a time. So this form of refactors and manual drops are are implemented to avoid borrowing `this` at the same time.
…eferences, r=RalfJung Make file descriptors into refcount references fixes rust-lang#3525 Remove `fn dup` in `trait FileDescription`, define `struct FileDescriptor(Rc<RefCell<dyn FileDescription>>)`, and use `BTreeMap<i32, FileDescriptor>` in `FdTable`. --- There are some refactors similar to the following form: ```rust { // origin: if let Some(file_descriptor) = this.machine.fds.get_mut(fd) { // write file_descriptor this.try_unwrap_io_result(result) } else { this.fd_not_found() } } { // now: let Some(mut file_descriptor) = this.machine.fds.get_mut(fd) else { return this.fd_not_found(); }; // write file_descriptor drop(file_descriptor); this.try_unwrap_io_result(result) } ``` The origin form can't compile because as using `RefCell` to get interior mutability, `fn get_mut` return `Option<std::cell::RefMut<'_, dyn FileDescription>>` instead of `Option<&mut dyn FileDescription>` now, and the `deref_mut` on `file_descriptor: RefMut` will cause borrow `this` as mutable more than once at a time. So this form of refactors and manual drops are are implemented to avoid borrowing `this` at the same time.
For the sake of people with 80-character terminals, Rust code is limited to 78 characters in width. So why do error messages on 80-character terminals look like this:
This is a pathological case, but I still manage to hit this frequently even though my term is often well wider than 80 characters.
Here's how Java formats its error messages:
Taking inspiration from this, Rust error messages could instead look like:
The text was updated successfully, but these errors were encountered: