rust-lang / rust-lang/rust-clippy
`pub` in executable modules
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Warn of uses of pub in the top-level module of an executable-only target.
Specifically, pub outside of a mod block in any of these files would trigger the lint:
src/main.rssrc/bin/foo.rssrc/bin/foo/main.rs
Advantage
pubsuppresses "unused" lints, so inadvertently marking somethingpubmay mask that the user forgot to use it.pubhas no other effect (that I'm aware of) in top-level modules of executable-only targets.
I actually ran into this recently: I work on a project that has several executable targets, and I discovered that two of them were not actually using all of their declared arguments.
Drawbacks
There may be a use for pub inside of an executable-only module that I'm not aware of.
Example
use clap::Parser;
#[derive(Parser, Debug)]
struct Args {
#[arg(short, long)]
pub name: String,
}
Could be written as:
use clap::Parser;
#[derive(Parser, Debug)]
struct Args {
#[arg(short, long)]
name: String,
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue identifies executable entry points as src/main.rs, src/bin/foo.rs, and src/bin/foo/main.rs; start by checking how these module forms are represented. Define the lint behavior for pub outside mod blocks and verify it against the Args example, including that pub inside a mod is excluded. No test file or implementation entry point is named, so locate the relevant Clippy lint tests before confirming warning and non-warning cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100