Skip to content

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

Open
epage wants to merge 10 commits intorust-lang:masterfrom
epage:refactor
Open

fix(compile): Where possible, hint about misplaced deps #16940
epage wants to merge 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

r#"
#[test]
fn foo {
fn foo() {
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.

Nice catch 😆.

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.

}
if used_in_dev {
let help = Group::with_title(Level::HELP.secondary_title(format!(
"to still use for development builds, move to `dev-dependencies`"
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.

nit: format! is not necessary.

Comment on lines +336 to +344
/// Expected [`Self::seen_units`] entries to know we've received them all
///
/// To avoid warning in cases where we didn't,
/// e.g. if a [`Unit`] errored and didn't report unused externs.
needed_units: Option<usize>,
needed_units: usize,
/// As reported by rustc
seen_units: Vec<Unit>,
/// As reported by rustc
unused_externs: IndexMap<Unit, Vec<InternedString>>,
unused_externs: Option<BTreeSet<InternedString>>,
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.

I understand it's implementation detail, though is still confusing to see two fields saying as reported by rustc whereas they are actually not the same and unused_externs is not directly reported by rustc.

Probably something like:

/// Units that have reported their unused externs
seen_units: Vec<Unit>,
/// Intersection of unused externs across all [`Self::seen_units`]
unused_externs: Option<BTreeSet<InternedString>>,

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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants