2 ms·
Show HN: Warnalyzer, scan multi-crate Rust projects for unused code
The Rust compiler has a multitude of lints to detect dead code that's used by no other code. These lints are limited to the crate itself only and therefore can't work across crates.
Often, you built your crate for public consumption and publish it on crates.io. Then your entire public API is potentially usable. Sometimes however, crates are part of a multi-crate project and if some public item is not used by any other crate in that project, the code is dead. For this second case, I built warnalyzer [1]. It uses save-analysis info generated by rustc to find and print unused definitions (despite the name, it doesn't use rust-analyzer yet, but it's certainly on the radar[2]!). Note that this method is not perfect, as it generates false positives due to unimplemented features in my tool as well as bugs in rustc. Therefore, manual verification to the tool's output is needed.
In such a manual removal effort, I was able to remove 815 lines of unused code from the servo browser project: https://github.com/servo/servo/pull/23532 https://github.com/servo/servo/pull/23532
[1]: https://github.com/est31/warnalyzer https://github.com/est31/warnalyzer
[2]: https://github.com/est31/warnalyzer/issues/1 https://github.com/est31/warnalyzer/issues/1