Skip to content

fix(compile): Where possible, hint about misplaced deps #16940

Merged
weihanglo merged 10 commits intorust-lang:masterfrom
epage:refactor
Apr 28, 2026
Merged

fix(compile): Where possible, hint about misplaced deps #16940
weihanglo merged 10 commits intorust-lang:masterfrom
epage:refactor

Conversation

@epage
Copy link
Copy Markdown
Contributor

@epage epage commented Apr 24, 2026

What does this PR try to resolve?

Sometimes a normal dependency is actually a dev-dependency.
For any of the dev-dependencies we build, we can let users know that an
unused dep might be a misplaced dep. This check came from #8437 but I originally punted on it due to the complexity of having the right information. Through the refactors done in this, I found it became easy to report this. The help could be improved to show the insertion of the dev-dependency with a removal of the normal dependency but that is being left to a future exercise to limit the scope of this.

This also improves the quality of the logged messages for people who are ok with the false positives that we can't report.

How to test and review this PR?

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 24, 2026

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, weihanglo

@epage
Copy link
Copy Markdown
Contributor Author

epage commented Apr 24, 2026

The bump check is a non-blocking job currently broken by GitoxideLabs/gitoxide#2541 because cargo-semver-checks isn't able to respect lockfiles fully.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 25, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Copy Markdown
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Nice refactor! Just some nits on commit messages and comments :)

View changes since this review

Comment thread tests/testsuite/lints/unused_dependencies.rs
Comment on lines +134 to +139
state.seen_units.push(unit.clone());
if let Some(existing) = state.unused_externs.as_mut() {
existing.retain(|ext| unused_externs.contains(ext));
} else {
state.unused_externs = Some(unused_externs);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is a bit weird that the actual core part of this PR is this commit not the fix commit, which people may easily overlook.

The commit message around also doesn't say anything more obvious than "track as we go". It is indeed a refactor commit, though I think it might be worthy adding more context about why this is needed and how this data model unblock the later behavior change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I focus PR titles and descriptions on the user-facing impact.

Originally, the intersection was my end-goal. Everything else was "oh, here is another thing I can do". I did not predict at all where it was going to go. I can edit it in hindsight but that also feels weird (wouldn't have been there if I had split the PR like I considered).

I've at least gone into more detail on the commit itself about my intent with it.

Comment thread src/cargo/core/compiler/unused_deps.rs Outdated
Comment thread src/cargo/core/compiler/unused_deps.rs
epage added 8 commits April 28, 2026 08:36
Instead of saving off all unused externs and checking the externs
against them,
let's take the intersection of the unused externs.

This makes the logging messages much better for unreported unused
externs.
The one side effect is we won't list used export in traces.
Through the re-ordering of things,
the check has become redundant and can be removed.
Sometimes a normal dependency is actually a dev-dependency.
For any of the dev-dependencies we build, we can let users know that an
unused dep might be a misplaced dep.
Copy link
Copy Markdown
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks for the commit message updates!

View changes since this review

@weihanglo weihanglo enabled auto-merge April 28, 2026 13:47
@weihanglo weihanglo added this pull request to the merge queue Apr 28, 2026
Merged via the queue into rust-lang:master with commit 00c3cce Apr 28, 2026
28 of 29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2026
@epage epage deleted the refactor branch April 28, 2026 15:13
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request May 2, 2026
Update cargo submodule

10 commits in eb9b60f1f6604b5e022c56be31692c215b8ba11d..4f9b52075316e9ced380c8fa492858048d5758b6
2026-04-24 20:52:07 +0000 to 2026-05-01 22:36:41 +0000
- chore(deps): update compatible (rust-lang/cargo#16952)
- feat(lints): Add deny-by-default text_direction_codepoint lints (rust-lang/cargo#16950)
- chore(deps): update embarkstudios/cargo-deny-action action to v2.0.17 (rust-lang/cargo#16953)
- docs(guide): Switch from third-party to first-party unused deps detection (rust-lang/cargo#16946)
- Remove curl dependency from crates-io crate (rust-lang/cargo#16936)
- chore(deps): update gix to 0.83 (rust-lang/cargo#16945)
- fix(compile): Where possible, hint about misplaced deps  (rust-lang/cargo#16940)
- Remove `windows-sys` from `home` (rust-lang/cargo#16918)
- docs(resolver): `--precise <yanked>` is on stable (rust-lang/cargo#16944)
- Update `gix` to 0.82 (with security fixes and hardened parsers) (rust-lang/cargo#16941)
@rustbot rustbot added this to the 1.97.0 milestone May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants