-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
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 has picked a reviewer for you, use r? to override) |
The original example from rust-lang/rust#86854 now looks like this:
|
e1404ae
to
0e7af00
Compare
There was a problem hiding this 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.
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 ```
Thanks! @bors r+ |
📌 Commit 9c7cc54 has been approved by |
☀️ Test successful - checks-actions |
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)
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)
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)
Fixes rust-lang/rust#86854.
Don't print "run the command again with --verbose"
Here is a typical error seen by users of Cargo:
The
--verbose
output is not particularly helpful in this case. Theerror is unrelated to what cargo is doing, and passing
--verbose
willnot give useful information about how to proceed. Additionally, it's
unclear that
--verbose
is referring to the cargo command and notrustc; 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 aboveall 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:
After: