Skip to content

Make pub in a binary equivalent to pub(crate) for diagnostics #74970

Open
@jhpratt

Description

@jhpratt

(copy-pasting from IRLO)

Consider the code snippet

pub fn foo() {
    // unused function!
}

fn main() {}

cargo check reports no errors or warnings. However, the same snippet using pub(crate) fn foo() gives a warning:

warning: function is never used: `foo`
 --> src/main.rs:1:15
  |
1 | pub(crate) fn foo() {
  |               ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

Given that binaries can't be used in anything else (as far as I'm aware?), would it make sense to treat pub as equivalent to pub(crate) in binaries? I don't believe there is any difference in semantics, but it certainly makes a difference regarding warnings.


CC @estebank, who suggested I file an issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions