-
Notifications
You must be signed in to change notification settings - Fork 74
Stabilize --json=unused-externs(-silent) #674
Copy link
Copy link
Closed
Labels
T-compilerAdd this label so rfcbot knows to poll the compiler teamAdd this label so rfcbot knows to poll the compiler teamdisposition-mergeThe FCP starter wants to merge thisThe FCP starter wants to merge thismajor-changeA proposal to make a major change to rustcA proposal to make a major change to rustcmajor-change-acceptedA major change proposal that was acceptedA major change proposal that was acceptedproposed-final-comment-periodAn FCP has been started, cast your votes and raise concernsAn FCP has been started, cast your votes and raise concerns
Metadata
Metadata
Assignees
Labels
T-compilerAdd this label so rfcbot knows to poll the compiler teamAdd this label so rfcbot knows to poll the compiler teamdisposition-mergeThe FCP starter wants to merge thisThe FCP starter wants to merge thismajor-changeA proposal to make a major change to rustcA proposal to make a major change to rustcmajor-change-acceptedA major change proposal that was acceptedA major change proposal that was acceptedproposed-final-comment-periodAn FCP has been started, cast your votes and raise concernsAn FCP has been started, cast your votes and raise concerns
Type
Fields
Give feedbackNo fields configured for issues without a type.
Proposal
This would stabilize two related options:
--json=unused-externs--json=unused-externs-silent--json=unused-externswas introduced about 3 years ago in rust-lang/rust#73945.When using json diagnostics, this flag causes rustc to emit extra diagnostics about unused crates. Specifically, it lists all the crates specified by an
--extern cratenameoption which never had any symbols referenced when compiling the current crate.This is distinct from a normal diagnostic message because there's no actual problem with the Rust code per-se - it simply means that the build system provided extra dependencies which were not used. In particular, there's no source file or line number a diagnostic can reference, because that's the whole point - we're reporting an absence.
Typically a user will want to remove those dependencies because they're either the result of cut-and-paste, no longer needed after code changes, and so on. The intended use of this message is that the build system itself will consume it, and turn it into a form which makes sense to the user with respect to the build system. For example, Cargo could consume it, make sure that none the crates in a given Cargo package require the unused crate(s), and then reference specific lines in
Cargo.tomlwhich should be removed or altered. Alternatively one could auto-fix such dependencies.unused-externsandunused-externs-silentare identical except for how they interact with lint levels. Firstly neither does anything unless theunused-crate-dependencieslint is enabled. If it's set to deny or forbid level, thenunused-externswill cause the build to fail as expected.unused-externs-silentsuppresses this, and leaves it to the build system to present a build failure. This is because Cargo needs to determine whether a given dependency is unused over multiple crates, so its only an error if it is unused in all crates.This feature has been used extensively with a non-Cargo build system (buck2) with great success - it is used as part of tooling to automatically remove unused dependencies across a very large codebase. The only change required in functionality since the original introduction was making
unused-externshonor lint levels and introductingunused-externs-silentin order to resolve issue rust-lang/rust#96068.Mentors or Reviewers
@est31 @ehuss
Process
The main points of the Major Change Process are as follows:
@rustbot second.-C flag, then full team check-off is required.@rfcbot fcp mergeon either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.