Skip to content

refactor(compile): Log all ignored unused externs#16920

Merged
weihanglo merged 10 commits intorust-lang:masterfrom
epage:log
Apr 21, 2026
Merged

refactor(compile): Log all ignored unused externs#16920
weihanglo merged 10 commits intorust-lang:masterfrom
epage:log

Conversation

@epage
Copy link
Copy Markdown
Contributor

@epage epage commented Apr 21, 2026

What does this PR try to resolve?

Shoring up the logging we do for unused dependency lints to help with debugging and profiling.

This could also be useful for users to get more insight on things we can't or won't show, like helping hunt down features to deactivate to reduce unused dependencies (e.g. cli on pulldown-cmark) or removing transitively unused dependencies.

How to test and review this PR?

Running this on cargo itself:

$ CARGO_LOG=cargo::core::compiler::unused_deps=debug nargo check
...
   2.537113285s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg crypto-common v0.1.6 (normal): ignoring unused extern `typenum`, untracked dependent
   2.537569241s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg heapless v0.8.0 (normal): ignoring unused extern `stable_deref_trait`, untracked dependent
   2.537758659s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg faster-hex v0.10.0 (normal): ignoring unused extern `heapless`, untracked dependent
   2.537984665s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-date v0.15.1 (normal): ignoring unused extern `bstr`, untracked dependent
   2.538312867s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-object v0.58.0 (normal): ignoring unused extern `gix_hashtable`, untracked dependent
   2.538704975s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-tempfile v21.0.2 (normal): ignoring unused extern `libc`, untracked dependent
   2.538762374s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-tempfile v21.0.2 (normal): ignoring unused extern `parking_lot`, untracked dependent
   2.539010269s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-commitgraph v0.35.0 (normal): ignoring unused extern `bstr`, untracked dependent
   2.539205527s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg libnghttp2-sys v0.1.13+1.68.1 (normal): ignoring unused extern `libc`, untracked dependent
   2.539597903s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg curl-sys v0.4.87+curl-8.19.0 (normal): ignoring unused extern `libnghttp2_sys`, untracked dependent
   2.539654548s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg curl-sys v0.4.87+curl-8.19.0 (normal): ignoring unused extern `libz_sys`, untracked dependent
   2.539711192s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg curl-sys v0.4.87+curl-8.19.0 (normal): ignoring unused extern `openssl_sys`, untracked dependent
   2.540319246s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg curl v0.4.49 (normal): ignoring unused extern `openssl_probe`, untracked dependent
   2.540373049s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg curl v0.4.49 (normal): ignoring unused extern `openssl_sys`, untracked dependent
   2.540811522s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-index v0.49.0 (normal): ignoring unused extern `gix_fs`, untracked dependent
   2.541504178s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-revision v0.43.0 (normal): ignoring unused extern `gix_commitgraph`, untracked dependent
   2.541560742s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-revision v0.43.0 (normal): ignoring unused extern `nonempty`, untracked dependent
   2.541873702s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg nix v0.30.1 (normal): ignoring unused extern `bitflags`, lint is allowed
   2.542548816s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg nom v7.1.3 (normal): ignoring unused extern `minimal_lexical`, lint is allowed
   2.542935941s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-negotiate v0.29.0 (normal): ignoring unused extern `gix_commitgraph`, untracked dependent
   2.542989018s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix-negotiate v0.29.0 (normal): ignoring unused extern `gix_object`, untracked dependent
   2.543198046s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg tracing-subscriber v0.3.23 (normal): ignoring unused extern `once_cell`, lint is allowed
   2.543249959s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg tracing-subscriber v0.3.23 (normal): ignoring unused extern `regex_automata`, lint is allowed
   2.543640436s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg git2 v0.20.4 (normal): ignoring unused extern `openssl_sys`, untracked dependent
   2.544004330s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg regex v1.12.3 (normal): ignoring unused extern `aho_corasick`, lint is allowed
   2.544419766s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg futures v0.3.32 (normal): ignoring unused extern `futures_task`, lint is allowed
   2.544564859s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix v0.81.0 (normal): ignoring unused extern `gix_revision`, untracked dependent
   2.544617049s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg gix v0.81.0 (normal): ignoring unused extern `prodash`, untracked dependent
   2.544779907s debug emit_unused_warnings: cargo::core::compiler::unused_deps: pkg rustfix v0.9.6 (normal): ignoring unused extern `tracing`, untracked dependent
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.54s

Doesn't work too well for --all-targets because we don't support dev targets at the moment, so we don't track which externs came from dependencies vs dev-dependencies.

Also, of note that I found while doing this that confused me at first is that we don't fingerprint -Zcargo-lints, so users can have stale caches with no unused externs "reported" by rustc to cargo.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 21, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 21, 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

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.

Also, of note that I found while doing this that confused me at first is that we don't fingerprint -Zcargo-lints, so users can have stale caches with no unused externs "reported" by rustc to cargo.

Ah, this sounds not good, though a separate issue.

View changes since this review

@weihanglo weihanglo added this pull request to the merge queue Apr 21, 2026
Merged via the queue into rust-lang:master with commit dede9f5 Apr 21, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 21, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Apr 25, 2026
Update cargo submodule

10 commits in 06ac0e7c05770a8c7bbf67bdd12fa1a1eefdc8ae..eb9b60f1f6604b5e022c56be31692c215b8ba11d
2026-04-21 15:33:56 +0000 to 2026-04-24 20:52:07 +0000
- chore: Remove unused deps (rust-lang/cargo#16938)
- feat(compile): Stabilize `build.warnings` (rust-lang/cargo#16796)
- cargo clean: do not error if explicitly specified target-dir does not exist (rust-lang/cargo#16934)
- Revert "feat(lints): Add unused deps ignore list" (rust-lang/cargo#16937)
- fix(compile): Ignore unused deps if also transitive  (rust-lang/cargo#16935)
- Update rustls (rust-lang/cargo#16932)
- chore(deps): update rust crate openssl to v0.10.78 [security] (rust-lang/cargo#16931)
- chore(build-rs): Ensure we lint the crate (rust-lang/cargo#16930)
- Fix flaky test: proc_macro_in_artifact_dep (rust-lang/cargo#16922)
- refactor(compile): Log all ignored unused externs (rust-lang/cargo#16920)

r? ghost
@rustbot rustbot added this to the 1.97.0 milestone Apr 25, 2026
@epage epage deleted the log branch April 27, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants