Description
Given the following code:
fn f() -> usize {}
The current output is:
error[E0308]: mismatched types
--> src/lib.rs:1:11
|
1 | fn f() -> usize {}
| - ^^^^^ expected `usize`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Ideally the output should look like:
error[E0308]: mismatched types
--> src/lib.rs:1:11
|
1 | fn f() -> usize {}
| - ^^^^^ expected `usize`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error
Right now, cargo and rustc operate basically independently of each other. The summary ("aborting ..." and "could not compile ...") is repeated twice, and both have different, incompatible ways to get more info about what went wrong. There's no reason to repeat these twice; we could include all the same information in half the space if we can get cargo and rustc to cooperate.
I suggest the way this be implemented is by keeping rustc's output the same when run standalone, but omitting "aborting due to ..." and "for more information ..." when run with --error-format=json
. Then cargo can aggregate the info it used to print into its own errors by using the JSON output.
cc @rust-lang/cargo @rust-lang/wg-diagnostics
(meta note: I thought of this while working on #86022, which has fully 12 lines of "metadata" after the 5 line error. Most builds are not that bad in comparison, but I do think it shows that it needs support from all the tools in the stack to keep the verbosity down.)