Skip to main content

Build provenance: This package is built and distributed by Astral as part of astral-dev-toolchain. It packages cargo-shear from tag v1.14.1 at commit 66b62cb43ca6a153db29c8229a2396656141dec9.


Cargo Shear ✂️ 🐑

Detect and fix issues in Rust projects:

  • Unused dependencies in Cargo.toml
  • Misplaced dependencies (dev/build dependencies in wrong sections)
  • Unlinked source files (Rust files not reachable from any module tree)

Comparison with Cargo lints

Cargo's unused_dependencies uses rustc's unused-extern results. unused_workspace_dependencies checks manifest inheritance. cargo-shear instead collects crate references from source files and compares them with manifest entries.

Check Cargo lints cargo-shear
Unused normal/build dependencies cargo check checks these tables; cargo check --bin foo skips normal dependencies, even for a single-bin package. Only selected packages are checked. Checks all workspace members by default, including normal, build, dev, and target-specific dependency tables.
Unused dev-dependencies Currently unchecked, including with --all-targets. Checks references collected from source files, including unit tests, integration tests, examples, benchmarks, and Rust doc-comment code blocks.
Features and platforms Checks dependencies participating in the selected build configuration. Does not evaluate cfg: references in disabled feature/platform branches count as usage. A single scan can cover these branches without building each configuration.
Macro-generated references Uses compiler results after expansion. Can miss generated references by default. --expand adds expanded references using nightly rustc and all features; build scripts are not expanded.
Workspace dependencies Reports entries that no member inherits. An inherited but unused dependency satisfies this lint. Checks whether the underlying package has a source reference, feature reference, or ignore exemption in any member. Inheritance alone does not keep it.
Moving dependencies to dev-dependencies Can suggest a move when development-only usage is observed. --fix moves non-optional normal dependencies referenced only by integration tests, examples, or benchmarks. References inside #[cfg(test)] in src/ count as normal usage, so these are not moved.
Other cleanup These two lints concern dependencies. Also reports unlinked and empty source files; --fix removes unused non-optional dependencies and unused workspace entries. Optional and feature-only dependencies are reported separately for manual review.

For example, an unused dependency declared only in [dev-dependencies] is a reason to run cargo-shear even with Cargo's lints enabled. A dependency used only in a Windows cfg branch is retained by cargo-shear when scanning on Linux, without a Windows build.

Source references are a heuristic: cargo-shear also counts references in scanned files that are not linked into a module tree, so stale code can keep a dependency from being reported. Default analysis does not compile the project, but it runs cargo metadata --all-features, which still requires dependency resolution. See Limitations.

Installation

# Install from pre-built binaries.
cargo binstall cargo-shear

# Build from source.
cargo install cargo-shear --locked

# Install from brew.
brew install cargo-shear

Usage

Check for issues without making changes:

cargo shear

Automatically fix unused dependencies:

cargo shear --fix

Treat warnings as errors (exit with failure code):

cargo shear --deny-warnings

This is useful for CI/CD pipelines to enforce strict checking of warnings such as empty files, unlinked files, and unused optional dependencies.

Generate machine-readable JSON output:

cargo shear --format=json

This is particularly useful for CI/CD pipelines and custom tooling that need to programmatically process the results.

Detect mismatches between [lib] target settings and source content:

cargo shear --check-test-targets

When set, cargo-shear warns when test = false is paired with source that contains tests (or doctest = false with source that contains doc tests), and — within a workspace — when test / doctest are left at their default of true for lib targets that contain none. Disabled by default; pair with --fix to automatically reconcile the flags.

Limitations

To expand macros:

cargo shear --expand --fix

The --expand flag uses cargo expand, which requires nightly and is significantly slower.

Configuration

Ignore false positives

False positives can be ignored by adding them to the package's Cargo.toml:

[package.metadata.cargo-shear]
ignored = ["crate-name"]

Ignore unlinked files

Unlinked files can be ignored using glob patterns:

[package.metadata.cargo-shear]
ignored-paths = ["src/proto/*.rs", "examples/old/*"]

Both options work in workspace Cargo.toml as well:

[workspace.metadata.cargo-shear]
ignored = ["crate-name"]
ignored-paths = ["*/proto/*.rs"]

Ignore scope

  • Package ignore ([package.metadata.cargo-shear]) applies only to that package.
  • Workspace ignore ([workspace.metadata.cargo-shear]) applies to every member and to the workspace dependency itself. ignored-paths globs are matched relative to the workspace root.

An ignore that suppresses nothing is reported as redundant so it can be removed. A workspace ignore is considered redundant only when no member needs it — a dependency that is used in one crate but unused in another stays covered by the workspace ignore.

Keep pre-declared path dependencies

Some workflows declare a new crate in [workspace.dependencies] before any member depends on it, so later commits can inherit it. To keep such entries:

[workspace.metadata.cargo-shear]
keep-path-dependencies = true

A [workspace.dependencies] entry with path = "..." is then treated as used as long as a crate exists at the declared path. A stale entry — one whose crate has been deleted or moved — is still reported as unused.

cargo-hakari workspace-hack crates

cargo-hakari generates a workspace-hack crate that declares many dependencies it never imports (to unify Cargo features) and is depended on by every workspace member without being imported. cargo shear detects such a crate automatically — via the ### BEGIN HAKARI SECTION marker in its Cargo.toml — and skips both the crate itself and the dependency edges pointing at it, so no ignored configuration is needed.

Otherwise please report the issue as a bug.

CI

- name: Install cargo-binstall
  uses: cargo-bins/cargo-binstall@main

- name: Install cargo-shear
  run: cargo binstall --no-confirm cargo-shear

- run: cargo shear

JSON Output for CI Integration

For CI systems that require structured output, use the --format=json flag:

- name: Check for unused dependencies
  run: cargo shear --format=json > shear-results.json

The JSON output includes:

  • summary: Counts of errors, warnings, and fixes
  • findings: Detailed information about each issue including:
    • code: The diagnostic code (e.g., shear/unused_dependency)
    • severity: Error or warning level
    • message: Human-readable description
    • file: Path to the file with the issue
    • location: Byte offset and length within the file
    • help: Suggested fix
    • fixable: Boolean indicating if issue can be auto-fixed with --fix

Exit Code (for CI)

Exit Code Without --fix With --fix
0 No issues found No issues found, no changes made
1 Issues found Issues found and fixed
2 Error during processing Error during processing

Strict Mode with --deny-warnings

By default, warnings (such as empty files, unlinked files, and unused optional dependencies) exit with code 0. Use the --deny-warnings flag to treat warnings as errors for stricter CI enforcement:

Exit Code Without --deny-warnings With --deny-warnings
0 No errors (warnings allowed) No errors or warnings
1 Errors found Errors or warnings found
2 Error during processing Error during processing

GitHub Actions Example:

- name: cargo-shear
  shell: bash
  run: |
    if ! cargo shear --fix; then
      cargo check
    fi

Strict CI Example with --deny-warnings:

- name: cargo-shear (strict)
  run: cargo shear --deny-warnings

Technique

  1. Use the cargo_metadata crate to list all dependencies specified in [workspace.dependencies] and [dependencies]
  2. Iterate through all package targets (lib, bin, example, test and bench) to locate all Rust files
  3. Use rust-analyzer's parser (ra_ap_syntax) to parse these Rust files and extract imports
    • Alternatively, use the --expand option with cargo expand to first expand macros and then parse the expanded code (though this is significantly slower)
  4. Find the difference between the imports and the package dependencies

Prior Art

Trophy Cases

Sponsored By

My sponsors

Metadata

Release files for astral-dev-toolchain-cargo-shear 1.14.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for astral-dev-toolchain-cargo-shear 1.14.1
File Actions
astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_arm64.whl
astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_amd64.whl
astral_dev_toolchain_cargo_shear-1.14.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for astral_dev_toolchain_cargo_shear-1.14.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
astral_dev_toolchain_cargo_shear-1.14.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for astral_dev_toolchain_cargo_shear-1.14.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
astral_dev_toolchain_cargo_shear-1.14.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for astral_dev_toolchain_cargo_shear-1.14.1-py3-none-macosx_11_0_arm64.whl
astral_dev_toolchain_cargo_shear-1.14.1-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for astral_dev_toolchain_cargo_shear-1.14.1-py3-none-macosx_10_12_x86_64.whl

Total release size: 8.9 MB

Release files / astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_arm64.whl

Download URL astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_arm64.whl
Size 1.4 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
2ff6dd4f7584210878f343e685b4f44942d7fc54c742e5d9fed78bc8a8d20105
BLAKE2b-256 checksum
How to use checksums
af129ac636d549529d9dbe94e6aba572fee401761c9eabbd9b9d6f1c884067e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_amd64.whl

Download URL astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_amd64.whl
Size 1.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
f82c7db56da0ccebe1f0b530758ab91ce4447ff83fedd51ec45522209f044315
BLAKE2b-256 checksum
How to use checksums
f5ba2e8cb67dccc24b9a91918964b27a7c1103894ed3e7e0cd0432dc06412cac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_shear-1.14.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL astral_dev_toolchain_cargo_shear-1.14.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.6 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
d543408f388e3feaf03fbe69c89150e9b451dc52d03e447e092661bdbba5b849
BLAKE2b-256 checksum
How to use checksums
c14709b227d41d9236f908736d366766b0d69f7fc7f1f23d127cbed8ec293e75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_shear-1.14.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL astral_dev_toolchain_cargo_shear-1.14.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.5 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
d7618465b8e3525b1c42a5fdc6489803c277eaba7dfee867ba4642c201ed56f9
BLAKE2b-256 checksum
How to use checksums
7af6ff0d9b63ebecde5148bef5a93a2f6341f0b6c5f00d818c353082cf4838ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_shear-1.14.1-py3-none-macosx_11_0_arm64.whl

Download URL astral_dev_toolchain_cargo_shear-1.14.1-py3-none-macosx_11_0_arm64.whl
Size 1.4 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
09cf397759dff8ec9aa955837b6351ad2277ec3a644040943c6213980ffa8ee3
BLAKE2b-256 checksum
How to use checksums
9bddd2aee4c19b77de6fa19540beb4fdc5e0442b81f6b2738b2a1a84a3625c6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_shear-1.14.1-py3-none-macosx_10_12_x86_64.whl

Download URL astral_dev_toolchain_cargo_shear-1.14.1-py3-none-macosx_10_12_x86_64.whl
Size 1.5 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
369b4ed997862c5928cd71ffb1633d2dc250b8b5e63b814b6c1a7c8e44e5ef79
BLAKE2b-256 checksum
How to use checksums
68a8bbb9a3688b3b1aed58b933ba0d5ace23d2ddfda9c0c88791960439e0244d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for astral-dev-toolchain-cargo-shear 1.14.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for astral_dev_toolchain_cargo_shear-1.14.1-py3-none-win_arm64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page