unused-pub

Crates.iounused-pub
lib.rsunused-pub
version0.1.3
created_at2026-01-23 02:57:53.609564+00
updated_at2026-01-23 03:39:17.787542+00
descriptionA tool to detect unused public items (structs, enums, functions, etc.) in a Rust codebase.
homepage
repositoryhttps://github.com/kroucher/unused-pub
max_upload_size
id2063263
size36,738
Kroucher (kroucher)

documentation

README

unused-pub

A Cargo subcommand/CLI tool to detect potentially unused pub items in your Rust crate.

It identifies public structs, enums, functions, consts, traits, and types that are defined but never used within the codebase. This is useful for cleaning up libraries or identifying dead code in large workspaces.

Features

  • Deep Analysis: Scans definition sites and usage sites.
  • Accurate: Handles complex paths (foo::bar::Baz), imports (use), macro invocations (format!("{Foo}")), and doc comments (/// [Foo]).
  • Workspace Support: Runs on any target directory.

Installation

cargo install unused-pub

Usage

Run the tool on your project directory:

unused-pub <path-to-project>

Example:

unused-pub .

Filtering

You can filter by type (struct, enum, fn, const, trait, type) using the -f flag:

# Only find unused structs
unused-pub . -f struct

# Find unused structs and enums
unused-pub . -f struct -f enum

How it works

  1. Scans: Walks the target directory for .rs files.
  2. Parses: Uses syn to parse ASTs.
  3. Collects:
    • Definitions: Finds all pub items.
    • Usages: Finds all identifiers, paths, and macro tokens used in function bodies, struct fields, expressions, etc.
  4. Reports: Any pub item that is not found in the "usages" set is reported.

License

MIT

PRs

Are welcome!

Commit count: 6

cargo fmt