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.13.5 at commit a460545ae901b01e1a9543d95cca4c51a9ba51ab.


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)

Installation

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

# Build from source.
cargo install cargo-shear

# 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.

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.13.5

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.13.5
File Actions
astral_dev_toolchain_cargo_shear-1.13.5-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for astral_dev_toolchain_cargo_shear-1.13.5-py3-none-win_arm64.whl
astral_dev_toolchain_cargo_shear-1.13.5-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for astral_dev_toolchain_cargo_shear-1.13.5-py3-none-win_amd64.whl
astral_dev_toolchain_cargo_shear-1.13.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for astral_dev_toolchain_cargo_shear-1.13.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
astral_dev_toolchain_cargo_shear-1.13.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for astral_dev_toolchain_cargo_shear-1.13.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
astral_dev_toolchain_cargo_shear-1.13.5-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for astral_dev_toolchain_cargo_shear-1.13.5-py3-none-macosx_11_0_arm64.whl
astral_dev_toolchain_cargo_shear-1.13.5-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for astral_dev_toolchain_cargo_shear-1.13.5-py3-none-macosx_10_12_x86_64.whl

Total release size: 8.7 MB

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

Download URL astral_dev_toolchain_cargo_shear-1.13.5-py3-none-win_arm64.whl
Size 1.4 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
1d6a1597126a9d962706d3d6f6ec41ab750bf79819339fa9b5990abe28f516ac
BLAKE2b-256 checksum
How to use checksums
90fdeafc03c034d0540ef9c94cfc229151ae5e8c7ef5c69b8593f9761e39a65a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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 Oct 6, 2026.

Transparency log

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

Download URL astral_dev_toolchain_cargo_shear-1.13.5-py3-none-win_amd64.whl
Size 1.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
7bcbfa279c3a22368b9009429e4f724d45a79d1158db8f9c544fe419c93604ae
BLAKE2b-256 checksum
How to use checksums
c2e453279b9f270f29f28b665ee47de3b6f03ce8a6934437f07470431ad6a427
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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 Oct 6, 2026.

Transparency log

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

Download URL astral_dev_toolchain_cargo_shear-1.13.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.6 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
f36603daaff16ca127672605a7d0a4e929a41332d711f3577638a898472024fa
BLAKE2b-256 checksum
How to use checksums
090063bdb5495206631a7f561701c92aa88e2b6edf87b4272bdae7db34c10d86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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 Oct 6, 2026.

Transparency log

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

Download URL astral_dev_toolchain_cargo_shear-1.13.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.5 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
24bf453145775b490d25be851de84fc9892bd61278e3c58fd424393534e71e06
BLAKE2b-256 checksum
How to use checksums
6dc41a5b422400a0f4583bbddaeab3a8616548facedce1277e69f5a9a9a64ec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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 Oct 6, 2026.

Transparency log

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

Download URL astral_dev_toolchain_cargo_shear-1.13.5-py3-none-macosx_11_0_arm64.whl
Size 1.3 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d3691bbdca1f8fdbd6d9eababeaae2e6951d7a1900aefea49aca4808cc4a2c8c
BLAKE2b-256 checksum
How to use checksums
6eb21415ccd7e788d36176634a6cc0183c5496b996f38555f395cc1e552542fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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 Oct 6, 2026.

Transparency log

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

Download URL astral_dev_toolchain_cargo_shear-1.13.5-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
2cadcac74cf236570ea3d24032c32dd4a940c5c667e978b4cb9e73d492afb7f4
BLAKE2b-256 checksum
How to use checksums
631884bef19eab73b702aa9192d17e2ca46a7e0c303eda0b16232177360154aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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 Oct 6, 2026.

Transparency log

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

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.13.5-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 Oct 6, 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