Skip to content
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

pub in executable modules #13644

Open
BatmanAoD opened this issue Nov 2, 2024 · 0 comments
Open

pub in executable modules #13644

BatmanAoD opened this issue Nov 2, 2024 · 0 comments
Labels
A-lint Area: New lints

Comments

@BatmanAoD
Copy link
Member

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.rs
  • src/bin/foo.rs
  • src/bin/foo/main.rs

Advantage

  • pub suppresses "unused" lints, so inadvertently marking something pub may mask that the user forgot to use it.
  • pub has 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,
}
@BatmanAoD BatmanAoD added the A-lint Area: New lints label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant