Teach make-tidy to detect unused *.rs files
As an example, the file https://github.com/rust-lang/rust/blob/master/src/librustc_front/attr.rs is currently dead and can be removed, but before realizing it I spent several minutes trying to understand what's wrong with my text editor and why can't it find the definition of unlower_attribute.
I second this motion. A while back I forgot to add a
mod foo;line inlibcoretestand went for days without noticing that some of my tests didn't run.Hanna Kruppe at 2015-09-29 09:44:23
cc #12565
Jonas Schievink at 2015-09-29 09:57:41
It'd be cool if this was made generic enough such that any project could utilize it
Corey Farwell at 2015-09-30 01:46:24
I've started working on a compiler plugin that does that. I would be happy to add this to the lints shipped with Rust.
It works as follows. It collects all Rust source files in the source directory and all subdirectories and also generates a set of all files used in the crate using the
CodeMap. It then computes the difference between the two sets to find unused files.There is one catch however. Because it uses the
CodeMap, modules that are included conditionally (e.g. with#[cfg(test)]) are treated as "unused" if they are not included in the particular build. But in order to handle thoses cases correctly, work has to be done early during parsing (which I would also be happy to look into if you decide this should be the way to go).Florian Hahn at 2015-10-15 19:17:02
Triage: not aware of any changes here.
Steve Klabnik at 2019-01-23 22:00:52
One possible way to implement this (including as a third-party tool) is to parse the
.dfiles rustc emits for cargo, and look for any .rs files that aren't mentioned.jyn at 2022-01-13 18:58:36
A small hack to do this with shell:
rg --no-filename '^[^/].*\.rs:$' target/debug/deps/*.d | sed 's/:$//' | sort -u | diff - <(fd '\.rs$' | sort -u)jyn at 2022-01-13 19:04:08