cargo-neat

July 29, 2026 · View on GitHub

continuous-integration

cargo-neat

Keep your cargo workspace neat

About

A command to complement existing tools like cargo-machete when working with a Cargo workspace.

Features:

  • detect unused dependencies in workspace.dependencies
  • optionally require dependencies to be inherited (-m option)*
  • optionally require declared package metadata keys to be inherited (-p option)*. Keys default to DEFAULT_PACKAGE_META, set via --package-workspace-meta-values or Cargo.toml metadata
  • optionally require opting out of default features (-f option)

* requires a [workspace], skipped otherwise

Installation

Install with cargo:

cargo install cargo-neat --locked

Usage

cd my-directory && cargo neat

or alternatively

cargo neat my-directory

Sample output

cargo neat -m -p -f my-workspace

Unused workspace dependencies :
└── /home/user/my-workspace/Cargo.toml
    ├── anyhow
    └── clappen

Non workspace dependencies :
├── /home/user/my-workspace/crate1/Cargo.toml
   ├── argh
   └── futures-lite
└── /home/user/my-workspace/crate2/Cargo.toml
    └── clap

Non workspace metadata :
└── /home/user/my-workspace/crate1/Cargo.toml
    └── edition

Workspace default-features enabled :
├── /home/user/my-workspace/Cargo.toml
   └── trycmd
└── /home/user/my-workspace/crate1/Cargo.toml
    └── argh

The return code indicates whether any issue was found:

  • 0 if it found no issue,
  • 1 if it found at least one issue,
  • 2 if there was an error during processing (in which case there's no indication whether any issue was found or not).

Usage with github actions

name: Cargo neat checks
on:
  pull_request: { branches: "*" }

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: taiki-e/checkout-action@v1 # or standard actions/checkout
      - name: Install cargo neat
        uses: taiki-e/install-action@v2
        with:
          tool: cargo-neat
      - name: Run cargo neat
        run: cargo neat -m -p -f

A working example can be found in cargo-neat CI

Inspiration

A lot of the code structure is drawn from the great cargo-machete. If you don't already use it, you probably should.

Similar tools

  • est31/cargo-udeps: slow and requires Nightly rust, has no workspace features
  • bnjbvr/cargo-machete: fast but does not remove unused workspace dependencies
  • Boshen/cargo-shear: removes unused workspace dependencies, and can fix wrong dependency section, but cannot enforce using workspace dependencies only

I would need a mix of cargo-machete/shear and cargo-neat. However cargo-shear is marked feature complete and not accepting new features, so here is cargo-neat.