RS.CLIPPY.PUB_UNDERSCORE_FIELDS

Struct field prefixed with underscore and marked public

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: pub_underscore_fields. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks whether any field of the struct is prefixed with an _ (underscore) and also marked pub (public)

Why is this bad?

Fields prefixed with an _ are inferred as unused, which suggests it should not be marked as pub, because marking it as pub infers it will be used.

Example

struct FileHandle {
    pub _descriptor: usize,
}

Use instead:

struct FileHandle {
    _descriptor: usize,
}

OR

struct FileHandle {
    pub descriptor: usize,
}

Configuration

  • pub-underscore-fields-behavior: Lint "public" fields in a struct that are prefixed with an underscore based on their exported visibility, or whether they are marked as "pub".

    (default: "PubliclyExported")