-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add lint to detect unused Rust files in crate directory #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
How will this interact with modules included conditionally, depending on |
I see four complications (one of which made the CI build fail):
|
@birkenfeld it seems like rustc populates CodeMap with all files for all modules, regardless of
Not sure what you meant by your first point, could you give additional information?
Should not be an issue (see above)
This is the issue that causes th CI to fail, for the following reason. Each file in |
Regarding cfg: That's certainly news to me. Look at the cargo docs for more information on build scripts. |
The canonical way is to |
I don't think this lint should be searching outside of src/ |
Also I don't think the lint should |
But isn't src/ only convention anyway? |
Sure, but there can be lots of things (including example files and benches!) that would reside out of it and it's really hard to tell them apart. Whereas you expect regular lib code under src. If there is no src, we don't know what to expect. |
I've updated the PR. It now only checks files if the crate root is in |
So I rebased this in https://github.com/Manishearth/rust-clippy/commits/unused-files3, but there's two big issues we need to fix.
Not sure how to proceed, but it feels to me like this should rather be something that a cargo subcommand should do. |
opinions? This could be something that |
cargo-modules shows unused modules, too. |
continued in cargo: rust-lang/cargo#3754 |
This PR adds an used files lint.
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
CodeMap
. It then computes the difference between the two sets to find unused files.It was initially suggest in rust-lang/rust#28711, but I think clippy is a better fit for this lint.