Skip to content

Extend dead code detection to cover files that are not loaded #12565

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

Closed
chris-morgan opened this issue Feb 26, 2014 · 4 comments
Closed

Extend dead code detection to cover files that are not loaded #12565

chris-morgan opened this issue Feb 26, 2014 · 4 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@chris-morgan
Copy link
Member

If I have a whole tree of *.rs files and one of them is not included in the compilation, that is probably an error on my part. I propose a new lint to this effect.

When compiling without cfg(test), I suggest that files named test.rs or tests.rs and the contents of directories named test or tests be ignored.

To suppress this lint for individual files, we would add an attribute such as #[allow_unloaded_file = "foo.rs"]. That could go on a module in the appropriate place in the filesystem or on the crate itself.

This occurred to me when I found src/librustc/middle/typeck/infer/test.rs with a few syntax errors (#12564).

@SiegeLord
Copy link
Contributor

I'm not sure which files this is meant to trigger for. E.g. in my projects I have a directory examples with several example#.rs files. If I compile one of them, would it tell me that I forgot to compile the rest alongside with it?

It seems like this would have too many false positives and (or false negatives depending on how you handle the above case) in legitimate directory structures.

@chris-morgan
Copy link
Member Author

@SiegeLord I see your point there. I see several primary options (mutually inclusive):

  • By default, only complain if at least one other file is used. This will take care of the majority of examples.

  • Don't turn this lint on by default.

  • Push people back into the structure that was the rustpkg recommendation whereby each directory will be self-contained:

    + src/
      + mycrate/
        - lib.rs
        - test.rs
        - foo.rs
      + examples/
        + example1/
          - main.rs
        + example2/
          - main.rs
    

    (i.e. move your exampleN.rs to exampleN/main.rs.)

@steveklabnik steveklabnik added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 23, 2015
@fhahn
Copy link
Contributor

fhahn commented Oct 15, 2015

I've started working on a compiler plugin that adds a lint to detect unused files. At the moment, it only analysis a single crate (e.g. src/lib.rs) and all files in subdirectories of the crate root.

@steveklabnik
Copy link
Member

Since new lints have a big impact on users of rustc, the policy is that they should go through the RFC process like other user-facing changes. As such, I'm going to give this one a close, but if anyone comes across this ticket and wants this lint, consider adding it to clippy and/or writing up an RFC. Thanks!

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

4 participants