Skip to content
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

Unify cargo and rustc's error reporting #9655

Merged
merged 2 commits into from
Jul 7, 2021
Merged

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Jul 5, 2021

Fixes rust-lang/rust#86854.

Don't print "run the command again with --verbose"

Here is a typical error seen by users of Cargo:

error[E0601]: `main` function not found in crate `wrong`
  |
  = note: consider adding a `main` function to `src/main.rs`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0601`.
error: could not compile `wrong`

To learn more, run the command again with --verbose.

The --verbose output is not particularly helpful in this case. The
error is unrelated to what cargo is doing, and passing --verbose will
not give useful information about how to proceed. Additionally, it's
unclear that --verbose is referring to the cargo command and not
rustc; this is especially true when cargo is wrapped by another build
system (such as Meson, x.py, or Make).

This omits the "run the command again with --verbose" output. --verbose
is still shown in cargo build --help, but it's not singled out above
all the other options.

Combine rustc and cargo's diagnostic summaries

This works by introspecting rustc's error output, using the JSON format
to determine whether it's a warning or error, then skipping it
altogether if it's a summary of the diagnostics printed.

Before:

$ cargo check --message-format short
src/main.rs:1:10: warning: trait objects without an explicit `dyn` are deprecated
src/main.rs:1:1: error[E0601]: `main` function not found in crate `wrong`
src/main.rs:1:9: error[E0038]: the trait `Clone` cannot be made into an object
error: aborting due to 2 previous errors; 1 warning emitted
error: could not compile `wrong`

After:

$ cargo check --message-format short
src/main.rs:1:10: warning: trait objects without an explicit `dyn` are deprecated
src/main.rs:1:1: error[E0601]: `main` function not found in crate `wrong`
src/main.rs:1:9: error[E0038]: the trait `Clone` cannot be made into an object
error: could not compile `wrong` due to 2 previous errors; 1 warning emitted

Here is a typical error seen by users of Cargo:

```
error[E0601]: `main` function not found in crate `wrong`
  |
  = note: consider adding a `main` function to `src/main.rs`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0601`.
error: could not compile `wrong`

To learn more, run the command again with --verbose.
```

The `--verbose` output is not particularly helpful in this case. The
error is unrelated to what cargo is doing, and passing `--verbose` will
not give useful information about how to proceed. Additionally, it's
unclear that `--verbose` is referring to the cargo command and not
rustc; this is especially true when cargo is wrapped by another build
system (such as Meson, x.py, or Make).

This omits the "run the command again with --verbose" output. --verbose
is still shown in `cargo build --help`, but it's not singled out above
all the other options.
@rust-highfive
Copy link

r? @alexcrichton

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 5, 2021
@jyn514
Copy link
Member Author

jyn514 commented Jul 5, 2021

The original example from rust-lang/rust#86854 now looks like this:

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

@jyn514 jyn514 changed the title [WIP] Unify cargo and rustc's error reporting Unify cargo and rustc's error reporting Jul 6, 2021
@jyn514 jyn514 force-pushed the verbose branch 2 times, most recently from e1404ae to 0e7af00 Compare July 6, 2021 00:31
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I think this is a great improvement.

src/cargo/core/compiler/mod.rs Outdated Show resolved Hide resolved
@ehuss ehuss assigned ehuss and unassigned alexcrichton Jul 6, 2021
This works by introspecting rustc's error output, using the JSON format
to determine whether it's a warning or error, then skipping it
altogether if it's a summary of the diagnostics printed.

Before:

```
src/main.rs:1:10: warning: trait objects without an explicit `dyn` are deprecated
src/main.rs:1:1: error[E0601]: `main` function not found in crate `wrong`
src/main.rs:1:9: error[E0038]: the trait `Clone` cannot be made into an object
error: aborting due to 2 previous errors; 1 warning emitted
error: could not compile `wrong`

```

After:

```
$ cargo check --message-format short
src/main.rs:1:10: warning: trait objects without an explicit `dyn` are deprecated
src/main.rs:1:1: error[E0601]: `main` function not found in crate `wrong`
src/main.rs:1:9: error[E0038]: the trait `Clone` cannot be made into an object
error: could not compile `wrong` due to 2 previous errors; 1 warning emitted
```
@ehuss
Copy link
Contributor

ehuss commented Jul 7, 2021

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Jul 7, 2021

📌 Commit 9c7cc54 has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 7, 2021
@bors
Copy link
Contributor

bors commented Jul 7, 2021

⌛ Testing commit 9c7cc54 with merge cc80b40...

@bors
Copy link
Contributor

bors commented Jul 7, 2021

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing cc80b40 to master...

@bors bors merged commit cc80b40 into rust-lang:master Jul 7, 2021
@jyn514 jyn514 deleted the verbose branch July 7, 2021 17:16
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 15, 2021
Update cargo

13 commits in 3ebb5f15a940810f250b68821149387af583a79e..66a6737a0c9f3a974af2dd032a65d3e409c77aac
2021-07-02 20:35:38 +0000 to 2021-07-14 20:54:28 +0000
- Add format option to `cargo tree` to print the lib_name (rust-lang/cargo#9663)
- Prefer patched versions of dependencies (rust-lang/cargo#9639)
- When a dependency does not have a version, git or path, fails directly (rust-lang/cargo#9686)
- Spot the crate typo easily (rust-lang/cargo#9665)
- remove unnecessary 'collect' (rust-lang/cargo#9616)
- Make it easier to run testsuite with a custom toolchain. (rust-lang/cargo#9679)
- Serialize `cargo fix` (rust-lang/cargo#9677)
- Don't recommend filing issues on rust-lang/cargo for Cargo.toml errors. (rust-lang/cargo#9658)
- Update nightly failure notification. (rust-lang/cargo#9657)
- Update Windows env uppercase key check. (rust-lang/cargo#9654)
- Unignore fix_edition_2021. (rust-lang/cargo#9662)
- Warning when using features in patch (rust-lang/cargo#9666)
- Unify cargo and rustc's error reporting (rust-lang/cargo#9655)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 15, 2021
Update cargo

13 commits in 3ebb5f15a940810f250b68821149387af583a79e..66a6737a0c9f3a974af2dd032a65d3e409c77aac
2021-07-02 20:35:38 +0000 to 2021-07-14 20:54:28 +0000
- Add format option to `cargo tree` to print the lib_name (rust-lang/cargo#9663)
- Prefer patched versions of dependencies (rust-lang/cargo#9639)
- When a dependency does not have a version, git or path, fails directly (rust-lang/cargo#9686)
- Spot the crate typo easily (rust-lang/cargo#9665)
- remove unnecessary 'collect' (rust-lang/cargo#9616)
- Make it easier to run testsuite with a custom toolchain. (rust-lang/cargo#9679)
- Serialize `cargo fix` (rust-lang/cargo#9677)
- Don't recommend filing issues on rust-lang/cargo for Cargo.toml errors. (rust-lang/cargo#9658)
- Update nightly failure notification. (rust-lang/cargo#9657)
- Update Windows env uppercase key check. (rust-lang/cargo#9654)
- Unignore fix_edition_2021. (rust-lang/cargo#9662)
- Warning when using features in patch (rust-lang/cargo#9666)
- Unify cargo and rustc's error reporting (rust-lang/cargo#9655)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 15, 2021
Update cargo

13 commits in 3ebb5f15a940810f250b68821149387af583a79e..66a6737a0c9f3a974af2dd032a65d3e409c77aac
2021-07-02 20:35:38 +0000 to 2021-07-14 20:54:28 +0000
- Add format option to `cargo tree` to print the lib_name (rust-lang/cargo#9663)
- Prefer patched versions of dependencies (rust-lang/cargo#9639)
- When a dependency does not have a version, git or path, fails directly (rust-lang/cargo#9686)
- Spot the crate typo easily (rust-lang/cargo#9665)
- remove unnecessary 'collect' (rust-lang/cargo#9616)
- Make it easier to run testsuite with a custom toolchain. (rust-lang/cargo#9679)
- Serialize `cargo fix` (rust-lang/cargo#9677)
- Don't recommend filing issues on rust-lang/cargo for Cargo.toml errors. (rust-lang/cargo#9658)
- Update nightly failure notification. (rust-lang/cargo#9657)
- Update Windows env uppercase key check. (rust-lang/cargo#9654)
- Unignore fix_edition_2021. (rust-lang/cargo#9662)
- Warning when using features in patch (rust-lang/cargo#9666)
- Unify cargo and rustc's error reporting (rust-lang/cargo#9655)
@ehuss ehuss added this to the 1.55.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify cargo and rustc's error reporting
5 participants