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

Make sure -Dunused-crate-dependencies --json unused-externs makes rustc exit with error status #96085

Merged
merged 5 commits into from
Apr 28, 2022

Conversation

jsgf
Copy link
Contributor

@jsgf jsgf commented Apr 15, 2022

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: #96068

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 15, 2022
@rust-highfive
Copy link
Collaborator

r? @compiler-errors

(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 Apr 15, 2022
@jsgf jsgf force-pushed the deny-unused-deps branch from 2d9ab89 to a5d3f41 Compare April 15, 2022 18:05
@est31
Copy link
Member

est31 commented Apr 15, 2022

I don't like this PR, see my comment here: #96068 (comment)

@compiler-errors
Copy link
Member

Just took a look at this. These changes look good to me, but I don't have context around why the behavior this PR adjusts is the way it currently is (except for reading #96068 (comment)).

More concretely, is this blocked on #96067 landing and cargo being adjusted to use --extern nounused:, so we don't introduce new failures in cargo projects with deny(unused_crate_dependencies)? if so, not sure what the best coordination strategy of this PR would be w/ the corresponding cargo changes.

@jsgf jsgf force-pushed the deny-unused-deps branch from abd0c56 to b570d5c Compare April 17, 2022 00:38
// aux-crate:bar=bar.rs

fn main() {}
//~^ ERROR external crate `bar` unused in
Copy link
Member

Choose a reason for hiding this comment

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

This line can be removed now, right? stderr should not contain it.

let mut inner = self.inner.borrow_mut();

if loud && lint_level.is_error() {
inner.bump_err_count();
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? bumping the error count should happen automatically if the lint is an error, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's needed because if we're going via the json event path, the normal diagnostics are not emitted, so error count isn't bumped. This is the core of the change to make get errors to be reported in the exit status.

Copy link
Member

Choose a reason for hiding this comment

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

I see, makes sense 👍 .

Copy link
Member

@est31 est31 left a comment

Choose a reason for hiding this comment

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

With the --json unused-externs-silent flag my general concerns are resolved. I still wonder about two of the code changes, see inline comments.

@jsgf jsgf force-pushed the deny-unused-deps branch 2 times, most recently from 03a2965 to bb91830 Compare April 17, 2022 01:24
@jsgf
Copy link
Contributor Author

jsgf commented Apr 22, 2022

ping?

@compiler-errors
Copy link
Member

@jsgf, you never answered my question 😛

More concretely, is this blocked on #96067 landing and cargo being adjusted to use --extern nounused:, so we don't introduce new failures in cargo projects with deny(unused_crate_dependencies)?

@est31
Copy link
Member

est31 commented Apr 22, 2022

@compiler-errors the cargo implementation was never merged. #96067. It won't break any users, but I would still prefer for the feature to be compatible with the design my PR proposed.

@jsgf
Copy link
Contributor Author

jsgf commented Apr 24, 2022

@compiler-errors Yeah, I think nounused is really orthogonal to this.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 26, 2022

📌 Commit bb91830f7a1545ec38a2736819a1931c4b259c98 has been approved by compiler-errors

@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 Apr 26, 2022
@bors
Copy link
Contributor

bors commented Apr 26, 2022

⌛ Testing commit bb91830f7a1545ec38a2736819a1931c4b259c98 with merge 299f80b2776088e087a626daf2c3e455d5044c1b...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 26, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 26, 2022
jsgf and others added 3 commits April 27, 2022 09:37
As generated by --json unused-externs.
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.
jsgf added 2 commits April 27, 2022 10:04
Since Cargo wants to do its own fatal error handling for unused
dependencies, add the option `--json unused-externs-silent` which
has the original behaviour of not indicating non-zero exit status for
`deny`/`forbid`-level unused dependencies.
@jsgf jsgf force-pushed the deny-unused-deps branch from bb91830 to c6bafa7 Compare April 27, 2022 17:04
@jsgf
Copy link
Contributor Author

jsgf commented Apr 27, 2022

Update with reblessed tests.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 27, 2022

📌 Commit c6bafa7 has been approved by compiler-errors

@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 Apr 27, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 27, 2022
…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
@bors
Copy link
Contributor

bors commented Apr 28, 2022

⌛ Testing commit c6bafa7 with merge 0e7915d...

@bors
Copy link
Contributor

bors commented Apr 28, 2022

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 0e7915d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 28, 2022
@bors bors merged commit 0e7915d into rust-lang:master Apr 28, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 28, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0e7915d): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@jsgf jsgf deleted the deny-unused-deps branch April 28, 2022 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-Dunused-crate-dependency --json unused-externs doesn't cause rustc to exit with error status
8 participants