A workspace-aware Cargo lint for unnecessary Rust visibility.
Experimental: This project was authored by GPT-5.5 and is not intended for public consumption. Use at your own risk.
Hawk finds pub declarations that are unused or can be restricted to
pub(crate) when a Cargo workspace builds one or more shipped binaries. It
also finds explicit restricted visibility modifiers that can be removed.
Optionally, it can suggest restricting pub(crate) declarations to
pub(super).
Hawk is intended for projects like Ruff
and uv, where the product is a binary but
the workspace itself is decomposed into many crates. In such projects, the
workspace is largely the only client of its pub APIs: pub is commonly
needed only to make symbols visible across crates within the workspace.
rustc's dead_code lint identifies unused, unexported items, and its
opt-in unreachable_pub lint identifies pub items that cannot be reached
outside a single crate. It does not perform the closed-world analysis needed
to decide which workspace-internal pub APIs are actually required. Hawk
assumes that the workspace represents the world and identifies dead code and
unnecessarily public symbols across crates within a single workspace.
hawk::dead_public for unused public items,
hawk::unnecessary_public for pub items that can become pub(crate), and
hawk::unnecessary_restricted_visibility for restricted items that can
become private.hawk::unnecessary_crate_visibility for pub(crate)
items that can become pub(super).cargo fix.-A/-W/-D lint levels for incremental CI adoption.Hawk uses rustc_private and must run with the exact Rust toolchain it was
built against. Prebuilt releases are available for macOS and Linux, but they
are not independent of Rust. Install the normal Rust 1.95.0 toolchain:
rustup toolchain install 1.95.0
Install the latest prebuilt release:
curl --proto '=https' --tlsv1.2 -LsSf \
https://github.com/astral-sh/hawk/releases/latest/download/cargo-hawk-installer.sh | sh
The installer places cargo-hawk and its internal cargo-hawk-driver
executable together on your PATH. You can instead download the archive for
your platform from GitHub Releases
and place both executables on your PATH in the same directory. A prebuilt
release does not require rustc-dev, RUSTC_BOOTSTRAP, or a source build.
Hawk validates the selected compiler before analysis. If a workspace selects another Rust version, invoke Hawk with its pinned toolchain:
cargo +1.95.0 hawk
To build Hawk from source, install the compiler development component:
rustup toolchain install 1.95.0 --component rustc-dev
To install the current development version from Git:
RUSTC_BOOTSTRAP=1 cargo +1.95.0 install --locked \
--git https://github.com/astral-sh/hawk cargo-hawk
Install a released version from crates.io with:
RUSTC_BOOTSTRAP=1 cargo +1.95.0 install --locked cargo-hawk
RUSTC_BOOTSTRAP=1 is required during installation because cargo install
does not use this repository's Cargo configuration when it compiles the
installed package.
Declare each shipped binary in a workspace-root hawk.toml:
[[production]]
package = "app"
bin = "app"
reason = "shipped application binary"
Analyze the workspace:
cargo hawk \
--manifest-path /path/to/workspace/Cargo.toml
To enforce findings in CI or apply visibility fixes:
cargo hawk \
--manifest-path /path/to/workspace/Cargo.toml \
-D warnings
cargo hawk \
--manifest-path /path/to/workspace/Cargo.toml \
--fix
Hawk is experimental. It assumes workspace library crates are internal to the configured binary product unless they are explicitly excluded from analysis. Because it integrates with compiler internals, it is pinned to Rust 1.95.0. Hawk was authored entirely by GPT-5.5 in Codex.
hawk is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in hawk by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.