Skip to content

chore: remove unused dependencies reported by cargo's unused_dependencies lint - #12165

Merged
basvandijk merged 2 commits into
masterfrom
bas/remove-unused-cargo-deps
Nov 18, 2026
Merged

basvandijk merged 2 commits into
masterfrom
bas/remove-unused-cargo-deps

Conversation

@basvandijk

Copy link
Copy Markdown
Collaborator

Rust 1.100.0 (#12143) brought Cargo's new cargo::unused_dependencies and cargo::unused_workspace_dependencies lints (warn by default). On master,

cargo check --workspace --all-targets --all-features --keep-going

reports 30 unused [dependencies]/[build-dependencies] entries and one unused [workspace.dependencies] entry. A run with default features reports the same 31.

This PR removes the ones that are really unused. Where Bazel listed the same dependency, the PR removes it from the BUILD.bazel file too; the "already absent" rows below needed no Bazel change. It also removes the crate.spec of each removed workspace dependency from bazel/rust.MODULE.bazel.

The lint says nothing about a dependency while another dependency of the same crate still pulls it in, so the removals exposed four more, which this PR also removes:

  • rustc-hash in ic-nns-integration-tests, previously also reachable through its dev-dependency ic-nervous-system-integration-tests;
  • ic-types and icp-ledger in ic-sns-governance-api, previously also reachable through ic-nns-common;
  • the workspace's rustc-hash entry, once no member inherited it.

In total the PR removes 21 [dependencies], 2 [build-dependencies] and 2 [workspace.dependencies] entries, and moves 4 entries to [dev-dependencies]. After it, the command above reports only the six false positives listed at the end, with default features as well.

A [dependencies] entry only counts as used if the library or a binary (including their unit tests) uses it. The lint therefore also reports dependencies that only integration tests (tests/*.rs) use. Deleting those would break the tests, so they move to [dev-dependencies] instead; the lint doesn't check that table.

Removed

Crate Unused dependency Bazel
consensus-vetkd-system-tests ic_consensus_system_test_utils removed
ic-boundary-nodes-performance-test-common ic-boundary-nodes-system-test-utils removed
ic_consensus_system_test_utils ic-http-utils removed
ic-cup-explorer ic-registry-client already absent
ic-nervous-system-integration-tests ic-nns-test-utils-macros already absent
ic-nervous-system-integration-tests ic-test-utilities-load-wasm, rustc-hash removed
ic-nns-integration-tests dfn_json, rustc-hash removed
ic-nns-test-utils ic-node-rewards-canister-api removed
ic-node-rewards-canister-api ic-nervous-system-proto already absent
rewards-calculation ic-cdk, ic-nns-constants already absent
dfn_http_metrics dfn_http already absent
ic-sns-governance-api ic-nns-common, ic-types, icp-ledger, itertools already absent
ic-sns-test-utils ic-nns-governance already absent
ic-validator-ingress-message-test-canister build-info removed
ic-sns-governance build-dependencies ic-base-types and prost-build (build.rs only calls build_info_build) removed from BUILD_DEPENDENCIES
ic-dummy-getrandom-for-wasm getrandom on targets other than wasm32-unknown-unknown, where all of the crate's code is compiled out deps became a select() on wasm32-unknown-unknown
workspace ring (no member has inherited it since #11669) and rustc-hash (no member inherits it after the removals above) crate.specs removed

Moved to [dev-dependencies] (only integration tests use them)

Crate Dependency Bazel
ic-consensus ic-consensus-certification removed from :malicious_consensus; the test targets already list it
ic-crypto-internal-seed hex already only on :seed_integration
ic_stable_memory_integrity canister-test already only on the rust_ic_test
ic-nervous-system-integration-tests ic-sns-cli moved from the shared list to the three rust_tests that use it

ring and rustc-hash

Both stay transitive dependencies in Cargo and in Bazel.

  • ring comes in through rcgen, x509-parser and, on wasm32, quinn-proto, so its crate.annotation stays. The removed crate.spec was the only thing enabling ring's std feature in Bazel. Cargo already builds ring without std (see cargo tree -e features -i ring --target all), so after the repin Bazel matches Cargo. In ring 0.17.14, std only adds std::error::Error impls for error::Unspecified and error::KeyRejected.
  • rustc-hash 1.1.0 comes in through bindgen. Its crate.spec enabled no features and it has no crate.annotation, so the repin only drops it from the direct dependencies.

Kept: false positives

The lint only sees code compiled for the host. These dependencies are only used when compiling for wasm, so they stay:

  • ic0 in canlog (#[cfg(target_family = "wasm")]) and ic-canister-profiler (#[cfg(target_arch = "wasm32")])
  • ic-cdk in ic-nervous-system-time-helpers (#[cfg(target_arch = "wasm32")])
  • ic-dummy-getrandom-for-wasm in cycles-minting-canister, ic-ckbtc-minter and xnet-test. Nothing references it in Rust code. It turns on getrandom 0.2's custom feature, which rand needs to compile for wasm32-unknown-unknown with Cargo.

🤖 Generated with Claude Code

…cies lint

Remove the dependencies that Cargo 1.100's `cargo::unused_dependencies` and
`cargo::unused_workspace_dependencies` lints report and that are really unused,
move the ones only integration tests use to `[dev-dependencies]`, and mirror
the changes in the BUILD.bazel files and bazel/rust.MODULE.bazel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@basvandijk basvandijk added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Nov 18, 2026
@github-actions github-actions Bot added the chore label Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the dependency cleanup.

No open issues 🎉

What changed in this PR

Removes unused Rust dependencies identified by Cargo’s new lints, keeping Cargo and Bazel dependency declarations aligned while preserving integration-test and WebAssembly requirements.

Changes:

  • Removes unused regular, build, and workspace dependencies and updates lockfiles.
  • Moves four integration-test-only dependencies to development dependencies, adjusting Bazel test targets where needed.
  • Restricts the dummy randomness dependency to WebAssembly and removes direct ring and rustc-hash specifications while retaining their transitive dependencies.
File Description
rs/​validator/​ingress_message/​test_canister/​Cargo.toml Removes unused runtime build-info.
rs/​validator/​ingress_message/​test_canister/​BUILD.bazel Removes the matching build-info dependency.
rs/​tests/​consensus/​vetkd/​Cargo.toml Removes unused consensus system-test utilities.
rs/​tests/​consensus/​vetkd/​BUILD.bazel Removes the matching test-utilities dependency.
rs/​tests/​consensus/​utils/​Cargo.toml Removes unused ic-http-utils.
rs/​tests/​consensus/​utils/​BUILD.bazel Removes the matching HTTP utilities dependency.
rs/​tests/​boundary_nodes/​performance_test_common/​Cargo.toml Removes unused boundary-node test utilities.
rs/​tests/​boundary_nodes/​performance_test_common/​BUILD.bazel Removes the matching test-utilities dependency.
rs/​sns/​test_utils/​Cargo.toml Removes unused NNS governance dependency.
rs/​sns/​governance/​Cargo.toml Removes two unused build dependencies.
rs/​sns/​governance/​BUILD.bazel Aligns build dependencies with Cargo.
rs/​sns/​governance/​api/​Cargo.toml Removes four unused API dependencies.
rs/​rust_canisters/​stable_memory_integrity/​Cargo.toml Moves canister-test to development dependencies.
rs/​rust_canisters/​dfn_http_metrics/​Cargo.toml Removes unused dfn_http.
rs/​node_rewards/​rewards_calculation/​Cargo.toml Removes unused CDK and NNS constants dependencies.
rs/​node_rewards/​canister/​api/​Cargo.toml Removes unused nervous-system protobuf dependency.
rs/​nns/​test_utils/​Cargo.toml Removes unused node-rewards API dependency.
rs/​nns/​test_utils/​BUILD.bazel Removes the matching node-rewards API dependency.
rs/​nns/​integration_tests/​Cargo.toml Removes unused dfn_json and rustc-hash.
rs/​nns/​integration_tests/​BUILD.bazel Mirrors the NNS integration-test dependency removals.
rs/​nervous_system/​integration_tests/​Cargo.toml Removes unused dependencies and makes SNS CLI test-only.
rs/​nervous_system/​integration_tests/​BUILD.bazel Removes unused dependencies and assigns SNS CLI to three tests.
rs/​cup_explorer/​Cargo.toml Removes unused registry client dependency.
rs/​crypto/​internal/​crypto_lib/​seed/​Cargo.toml Moves hex to development dependencies.
rs/​consensus/​Cargo.toml Moves certification to development dependencies.
rs/​consensus/​BUILD.bazel Removes certification from the malicious-consensus library.
packages/​ic-dummy-getrandom-for-wasm/​Cargo.toml Removes getrandom on non-canister targets.
packages/​ic-dummy-getrandom-for-wasm/​BUILD.bazel Selects getrandom only for wasm32-unknown-unknown.
Cargo.toml Removes workspace ring and rustc-hash entries.
Cargo.lock Records removed workspace-member dependency edges.
Cargo.Bazel.toml.lock Removes direct ring and rustc-hash dependencies.
Cargo.Bazel.json.lock Updates direct dependencies, checksum, and ring features.
bazel/​rust.MODULE.bazel Removes direct ring and rustc-hash crate specifications.

Review effort: Balanced

@basvandijk
basvandijk marked this pull request as ready for review November 18, 2026 08:15
@basvandijk
basvandijk requested review from a team as code owners November 18, 2026 08:15

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This pull request changes code owned by the Governance team. Therefore, make sure that
you have considered the following (for Governance-owned code):

  1. Update unreleased_changelog.md (if there are behavior changes, even if they are
    non-breaking).

  2. Are there BREAKING changes?

  3. Is a data migration needed?

  4. Security review?

How to Satisfy This Automatic Review

  1. Go to the bottom of the pull request page.

  2. Look for where it says this bot is requesting changes.

  3. Click the three dots to the right.

  4. Select "Dismiss review".

  5. In the text entry box, respond to each of the numbered items in the previous
    section, declare one of the following:

  • Done.

  • $REASON_WHY_NO_NEED. E.g. for unreleased_changelog.md, "No
    canister behavior changes.", or for item 2, "Existing APIs
    behave as before.".

Brief Guide to "Externally Visible" Changes

"Externally visible behavior change" is very often due to some NEW canister API.

Changes to EXISTING APIs are more likely to be "breaking".

If these changes are breaking, make sure that clients know how to migrate, how to
maintain their continuity of operations.

If your changes are behind a feature flag, then, do NOT add entrie(s) to
unreleased_changelog.md in this PR! But rather, add entrie(s) later, in the PR
that enables these changes in production.

Reference(s)

For a more comprehensive checklist, see here.

GOVERNANCE_CHECKLIST_REMINDER_DEDUP

@zeropath-ai

zeropath-ai Bot commented Nov 18, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to ea2155f.

Security Overview
Detected Code Changes
Change Type Relevant files
Refactor ► bazel/rust.MODULE.bazel
     Remove rustring/dependency specs in module (ring removed)
Bug Fix ► Cargo.toml
     Remove rustc-hash dependency from top-level Cargo.toml
Bug Fix ► Cargo.lock
     Remove rustc-hash and ring entries from lockfile
Bug Fix ► Cargo.Bazel.toml.lock
     Remove ring from dependencies
Bug Fix ► Cargo.Bazel.toml.lock
     Remove rustc-hash from dependencies
Enhancement ► rs/consensus/Cargo.toml
     Add ic-consensus-certification path dependency
Enhancement ► rs/consensus/BUILD.bazel
     Remove cert-related dependency "//rs/consensus/certification" from BUILD
Enhancement ► rs/consensus/BUILD.bazel
     Remove certification from BUILD dependencies
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
     Add sns cli to test dependencies
Enhancement ► rs/nervous_system/integration_tests/Cargo.toml
     Add dev-dependency ic-sns-cli; remove rustc-hash as a dev-dep
Enhancement ► rs/nns/integration_tests/BUILD.bazel
     Remove dfn_json and rustc-hash from BASE_DEPENDENCIES
Enhancement ► rs/nns/integration_tests/Cargo.toml
     Remove dfn_json and rustc-hash dev/test dependencies
Enhancement ► rs/nns/test_utils/Cargo.toml
     Remove ic-nns-governance dependency; remove ic-nns-governance from test utils
Enhancement ► rs/node_rewards/canister/api/Cargo.toml
     Remove ic-nervous-system-proto dependency
Enhancement ► rs/node_rewards/rewards_calculation/Cargo.toml
     Remove ic-cdk and ic-nns-constants dependencies
Enhancement ► rs/rust_canisters/dfn_http_metrics/Cargo.toml
     Remove dfn_http dependency
Enhancement ► rs/rust_canisters/stable_memory_integrity/Cargo.toml
     Add dev-dependency canister-test and remove canister_test from [dependencies]
Enhancement ► rs/sns/governance/Cargo.toml
     Remove base_types and prost_build from [build-dependencies]
Enhancement ► rs/sns/governance/api/Cargo.toml
     Remove ic-nns-common and ic-types from dependencies; adjust others
Refactor ► rs/validator/ingress_message/test_canister/BUILD.bazel
     Remove build-info from rust_canister dependencies
Refactor ► rs/validator/ingress_message/test_canister/Cargo.toml
     Remove build-info and adjust dependencies

@zeropath-ai

zeropath-ai Bot commented Nov 18, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to ea2155f.

Security Overview
Detected Code Changes
Change Type Relevant files
Refactor ► bazel/rust.MODULE.bazel
     Remove rustring/dependency specs in module (ring removed)
Bug Fix ► Cargo.toml
     Remove rustc-hash dependency from top-level Cargo.toml
Bug Fix ► Cargo.lock
     Remove rustc-hash and ring entries from lockfile
Bug Fix ► Cargo.Bazel.toml.lock
     Remove ring from dependencies
Bug Fix ► Cargo.Bazel.toml.lock
     Remove rustc-hash from dependencies
Enhancement ► rs/consensus/Cargo.toml
     Add ic-consensus-certification path dependency
Enhancement ► rs/consensus/BUILD.bazel
     Remove cert-related dependency "//rs/consensus/certification" from BUILD
Enhancement ► rs/consensus/BUILD.bazel
     Remove certification from BUILD dependencies
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
     Add sns cli to test dependencies
Enhancement ► rs/nervous_system/integration_tests/Cargo.toml
     Add dev-dependency ic-sns-cli; remove rustc-hash as a dev-dep
Enhancement ► rs/nns/integration_tests/BUILD.bazel
     Remove dfn_json and rustc-hash from BASE_DEPENDENCIES
Enhancement ► rs/nns/integration_tests/Cargo.toml
     Remove dfn_json and rustc-hash dev/test dependencies
Enhancement ► rs/nns/test_utils/Cargo.toml
     Remove ic-nns-governance dependency; remove ic-nns-governance from test utils
Enhancement ► rs/node_rewards/canister/api/Cargo.toml
     Remove ic-nervous-system-proto dependency
Enhancement ► rs/node_rewards/rewards_calculation/Cargo.toml
     Remove ic-cdk and ic-nns-constants dependencies
Enhancement ► rs/rust_canisters/dfn_http_metrics/Cargo.toml
     Remove dfn_http dependency
Enhancement ► rs/rust_canisters/stable_memory_integrity/Cargo.toml
     Add dev-dependency canister-test and remove canister_test from [dependencies]
Enhancement ► rs/sns/governance/Cargo.toml
     Remove base_types and prost_build from [build-dependencies]
Enhancement ► rs/sns/governance/api/Cargo.toml
     Remove ic-nns-common and ic-types from dependencies; adjust others
Refactor ► rs/validator/ingress_message/test_canister/BUILD.bazel
     Remove build-info from rust_canister dependencies
Refactor ► rs/validator/ingress_message/test_canister/Cargo.toml
     Remove build-info and adjust dependencies

@basvandijk
basvandijk added this pull request to the merge queue Nov 18, 2026
Merged via the queue into master with commit 0dc067a Nov 18, 2026
46 of 47 checks passed
@basvandijk
basvandijk deleted the bas/remove-unused-cargo-deps branch November 18, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants