Crate Feature Auditor & Visualizer
cargo-feature-lens is a Cargo subcommand for auditing Cargo feature usage. It builds a resolved dependency and feature graph, reports feature-related findings, and can export graph views for review or documentation.
The tool uses cargo metadata, manifest parsing, configured rules, and conservative Rust source scanning. It does not compile the target project.
Cargo Feature Lens is an audit helper, not a replacement for Cargo, cargo check, or project-specific review. It treats cargo metadata as the source of truth for resolved packages and active features, then adds lightweight analysis for feature provenance, rule-driven findings, and simple source references.
Findings are review signals. They can highlight risky or redundant feature choices, but they do not automatically prove that a feature should be removed. Source scanning is intentionally conservative, and the tool does not evaluate generated code, build scripts, macros, or every possible cfg expression.
Run the included conflict fixture to see a short, reproducible audit report:
cargo run -- feature-lens --manifest-path tests/fixtures/conflict-reqwest/Cargo.toml --check --fail-on warningSample output (abridged):
Feature Footprint Report
────────────────────────
✓ 2 total features active across 2 crates
⚠ 3 findings detected
Finding summary: 3 visible findings
severity: info 0, warning 2, error 1
kind: Unused 2, Conflict 1
┌─ reqwest (0.0.0)
│ active features: native-tls, rustls-tls
│ ✖ Conflict: TLS backends are mutually exclusive. Choose exactly one (native-tls, rustls-tls, or default-tls).
Read this top-down: the summary is CI-friendly triage, then crate sections show exactly which feature set triggered each advisory finding. This complements Cargo's native tooling by focusing on feature provenance and rule-driven audit hints, not build correctness proof.
- Active crate features and where feature activation comes from.
- Unused feature candidates, including source-aware checks for simple
#[cfg(feature = "...")]andcfg!(feature = "...")usage. - Duplicate feature activation across dependency paths.
- Conflict, bloat, and default-feature opt-out findings from built-in and local rules.
- CI-friendly pass/fail results through
--checkand severity thresholds.
Reports can be rendered as:
- Terminal text
- Markdown
- JSON
- Graphviz DOT
- Mermaid
git clone https://github.com/billybox1926-jpg/Crate-Feature-Auditor-Visualizer.git
cd Crate-Feature-Auditor-Visualizer
cargo install --path .Requires Rust 1.70 or newer.
Analyze the current Cargo package or workspace:
cargo feature-lensAnalyze an explicit manifest:
cargo feature-lens --manifest-path Cargo.toml
cargo feature-lens --manifest-path path/to/workspace/Cargo.tomlWrite a report:
cargo feature-lens --format markdown --output report.md
cargo feature-lens --format json --output report.jsonExport a graph:
cargo feature-lens --format dot --output graph.dot
cargo feature-lens --format mermaid --output graph.mdFocus or gate results:
cargo feature-lens --unused
cargo feature-lens --bloat
cargo feature-lens --min-severity warning
cargo feature-lens --check --fail-on error
cargo feature-lens --manifest-path Cargo.toml --crate serdeAnalyze a crate from crates.io:
cargo feature-lens --remote --crate tokio
cargo feature-lens --remote --crate serde --crate-version 1Add an optional feature-lens.toml file in the working directory to define project-specific conflict, bloat, or default-feature guidance. Local rules are additive with the built-in rule database in docs/suggestions.json.
Use --check with --fail-on to turn advisory findings into a CI gate:
cargo feature-lens --check --fail-on warningUse --min-severity when you want reports to hide lower-severity findings but keep the full analysis behavior available for stricter runs.
Licensed under the Apache License, Version 2.0. See LICENSE.