Skip to content

Unify cargo and rustc's error reporting #86854

Closed
rust-lang/cargo
#9655
@jyn514

Description

@jyn514

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-cargoRelevant to the cargo team, which will review and decide on the PR/issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions