Skip to content

Teach make-tidy to detect unused *.rs files #28711

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

Open
petrochenkov opened this issue Sep 28, 2015 · 7 comments
Open

Teach make-tidy to detect unused *.rs files #28711

petrochenkov opened this issue Sep 28, 2015 · 7 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@petrochenkov
Copy link
Contributor

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.

@hanna-kruppe
Copy link
Contributor

I second this motion. A while back I forgot to add a mod foo; line in libcoretest and went for days without noticing that some of my tests didn't run.

@jonas-schievink
Copy link
Contributor

cc #12565

@frewsxcv
Copy link
Member

It'd be cool if this was made generic enough such that any project could utilize it

@fhahn
Copy link
Contributor

fhahn commented Oct 15, 2015

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).

Manishearth added a commit to Manishearth/rust that referenced this issue Oct 16, 2015
…st, r=alexcrichton

While working on rust-lang#28711 I found out that 

*  src/libcoretest/clone.rs 
* src/libcoretest/fmt/float.rs  
* src/libcoretest/intrinsics.rs 

are not used. I am not sure if removing them is the right way to go. If it makes sense to keep (and fix and enable) them, I would be happy to update the PR.
bors added a commit that referenced this issue Oct 17, 2015
…richton

While working on #28711 I found out that 

*  src/libcoretest/clone.rs 
* src/libcoretest/fmt/float.rs  
* src/libcoretest/intrinsics.rs 

are not used. I am not sure if removing them is the right way to go. If it makes sense to keep (and fix and enable) them, I would be happy to update the PR.
@petrochenkov petrochenkov added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) and removed A-build labels Feb 19, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 24, 2017
@Mark-Simulacrum Mark-Simulacrum added the E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. label Sep 15, 2017
@steveklabnik
Copy link
Member

Triage: not aware of any changes here.

@jyn514
Copy link
Member

jyn514 commented Jan 13, 2022

One possible way to implement this (including as a third-party tool) is to parse the .d files rustc emits for cargo, and look for any .rs files that aren't mentioned.

@jyn514
Copy link
Member

jyn514 commented Jan 13, 2022

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)

@jyn514 jyn514 added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. and removed E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. labels Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

No branches or pull requests

8 participants