Remove unused code from multi-crate Rust projects.
The dead_code lint family of rustc is limited to one crate only and thus can't tell whether some public API is used inside a multi-crate project or not.
This tool, warnalyzer, provides unused code detection functionality for such multi-crate projects.
This backend supports stable, but it requires rust-analyzer to be available. Obtain it through rustup component add rust-analyzer.
warnalyzer, invoke it via warnalyzer <path-to-project-dir>. It will generate the needed .scip file in the target directory.scip file manually, via rust-analyzer scip for example, and pass it that file instead of the path.target directory into which to put the .scip files is a bit rudimentary. Ideally we would somehow involve cargo in finding out where the target directory is.[!NOTE] The save-analysis backend depends on the nightly feature
save-analysiswhich was removed in February 2023. In order to use warnalyzer, use a nightly Rust version before February 16, 2023. (Issue)
RUSTFLAGS="-Z save-analysis" cargo +nightly check.target/debug/deps/save-analysis/cratename-longhash.json.cargo run <path-to-json>It's still early on. There are a couple of bugs of the tool.
These are the false positives known to me:
#[allow(dead_code)] has no effectexpr part of for pat in expr {} is not seen as "use" of whatever the expression contains.dead_code lint of rustc, so if something only gets used by unused code, it doesn't get reported while it should.This crate is distributed under the terms of both the MIT license and the Apache License (Version 2.0), at your option.
See LICENSE for details.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Rust
95.1%
Shell
4.9%
Remove unused code from multi-crate Rust projects.
The dead_code lint family of rustc is limited to one crate only and thus can't tell whether some public API is used inside a multi-crate project or not.
This tool, warnalyzer, provides unused code detection functionality for such multi-crate projects.
This backend supports stable, but it requires rust-analyzer to be available. Obtain it through rustup component add rust-analyzer.
warnalyzer, invoke it via warnalyzer <path-to-project-dir>. It will generate the needed .scip file in the target directory.scip file manually, via rust-analyzer scip for example, and pass it that file instead of the path.target directory into which to put the .scip files is a bit rudimentary. Ideally we would somehow involve cargo in finding out where the target directory is.[!NOTE] The save-analysis backend depends on the nightly feature
save-analysiswhich was removed in February 2023. In order to use warnalyzer, use a nightly Rust version before February 16, 2023. (Issue)
RUSTFLAGS="-Z save-analysis" cargo +nightly check.target/debug/deps/save-analysis/cratename-longhash.json.cargo run <path-to-json>It's still early on. There are a couple of bugs of the tool.
These are the false positives known to me:
#[allow(dead_code)] has no effectexpr part of for pat in expr {} is not seen as "use" of whatever the expression contains.dead_code lint of rustc, so if something only gets used by unused code, it doesn't get reported while it should.This crate is distributed under the terms of both the MIT license and the Apache License (Version 2.0), at your option.
See LICENSE for details.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Rust
95.1%
Shell
4.9%