-
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
-Dunused-crate-dependency --json unused-externs
doesn't cause rustc to exit with error status
#96068
Comments
-Dunused-crate-dependency --json unused-externs
doesn't cause rustc to exit with error stats-Dunused-crate-dependency --json unused-externs
doesn't cause rustc to exit with error status
I've made it this way on purpose so that if you use it with cargo, you can put |
@est31 Hm, I think I see, but it seems like a strange way of doing it. Right now, if you put This seems surprising to me. In effect, Also, perhaps related, I put up PR #96067 to implement |
Yes, that's what my (non-upstreamed) implementation of the
If anything then the lint is allowed, because the warning is entirely suppressed. I agree that it is not an optimal solution, and I would like cleaner alternatives. I'm not sure a cap-lints flag as suggested by you is good because it would bloat the rustc command line even further. That's why I went with this "surprising" approach, to save on command line bloat. (Edited to add: also I'm not sure about how lint levels are handled internally by rustc, that is if the reported lint level in the json would be able to become deny if it's capped to warn, one needs to figure out if the "raw" uncapped lint level can be reported...). The reason this entire thing is done is so that
Not much, as the number of non unused units is not known. |
Yep.
That doesn't seem like a great tradeoff. While I agree generally about command-line bloat, we're taking about a single option with a fixed size - it's not like an option per dependency or something. (In general I wouldn't worry about command-line length at all if it weren't for Windows and its ridiculous limits, but we do have @file as an escape hatch.) By contrast this behaviour is surprising because it has this non-orthogonal side effect. It makes the mechanism essentially Cargo-specific, as a workaround for Cargo's imprecise dependency specifications.
I'm not quite sure how to parse this, but the lint level in the json does behave as expected - it is capped by Actually I just noticed there's a discrepancy between the json and regular diagnostics. The json uses strings from rust/compiler/rustc_lint_defs/src/lib.rs Lines 151 to 176 in 1e6fe58
and so are "allow", "warn", "deny", etc. But regular diagnostics use rust/compiler/rustc_errors/src/lib.rs Lines 1435 to 1451 in 1e6fe58
and so are "warning", "error", "note", "help", internal errors and so on.
Sure, I agree that the presentation of the diagnostic belongs at the level which has some knowledge of how the dependencies are specified. But the logic of whether the error should be considered fatal seems to me like it should be handled like any other diagnostic, with that being entirely As I understand it, the problem is:
As a result anything using One could imagine solving this in a generic way by having something like:
Or the other alternative this, but with a per-lint --cap-lints capability which Cargo could use to control unused-crate-dependencies specifically. Either way, this would allow Buck or other build systems with precise dependency information to use |
Your understanding is correct. Note that it's not upstreamed atm, but that's my intent.
It uses the same notation as lints do, which as you correctly point out is a different notation from the one that warnings do. The level has to be "combined" from the output of multiple compilation units. As for build tools knowing about the concept of lint levels, it already passes arguments to cap lints at warn. Furthermore, there are discussions to allow users to put lint level information into
Actually good that you bring this up. As we've talked about cargo's use cases of the flag, what are buck's use cases, if not reporting on unused crates on its own? I have another alternative: a |
Yeah, I'm fine with that. I can update my PR. Edit: Done. |
Summary: For Reasons, `rustc` does not exit with an error status for unused dependency errors (rust-lang/rust#96068). We can promote them to proper errors in the rustc_action script. Also improve how the diagnostics are rendered to make them a bit more readable. Reviewed By: dtolnay Differential Revision: D35690034 fbshipit-source-id: a2571f9d6682a83527bfca9ce73dc474162a6f9c
There were none at all. These test for original functionality, but this also adds a test that `-Dunused-crate-dependencies` causes a compilation failure, which currently fails (rust-lang#96068). This is fixed in subsequent changes.
…rrors Make sure `-Dunused-crate-dependencies --json unused-externs` makes rustc exit with error status This PR: - fixes compiletest to understand unused extern notifications - adds tests for `--json unused-externs` - makes sure that deny-level unused externs notifications are treated as compile errors - refactors the `emit_unused_externs` callstack to plumb through the level as an enum as a string, and adds `Level::is_error` Update: adds `--json unused-externs-silent` with the original behaviour since Cargo needs it. Should address `@est31's` concerns. Fixes: rust-lang#96068
Make sure `-Dunused-crate-dependencies --json unused-externs` makes rustc exit with error status This PR: - fixes compiletest to understand unused extern notifications - adds tests for `--json unused-externs` - makes sure that deny-level unused externs notifications are treated as compile errors - refactors the `emit_unused_externs` callstack to plumb through the level as an enum as a string, and adds `Level::is_error` Update: adds `--json unused-externs-silent` with the original behaviour since Cargo needs it. Should address `@est31's` concerns. Fixes: rust-lang#96068
Given the following code:
t.rs:
unused.rs:
// empty
The current output is:
It reports a "deny" level event as expected, but it does not cause
rustc
to exit with a non-zero status.I think it should since this is a fatal compiler diagnostic, I think it should exit with an error code. Of course a process monitoring the json stream could treat the
"deny"
level as a fatal error, but it seems odd to have a special case just for this.The text was updated successfully, but these errors were encountered: