Skip to content

rustdoc: synthetic_non_exhaustive lint #10550

Closed
@Ezrashaw

Description

@Ezrashaw

What it does

See discussion in rust-lang/rust#108925 and rust-lang/rust#109007.

enum's which have a #[doc(hidden)] attribute are effectively #[non_exhaustive]. Sometimes a #[doc(hidden)] __Nonexhaustive variant (dating from before #[non_exhaustive]) exists, which . Even in the absence of a explicit variant to artificially synthesize a #[non_exhaustive] attribute, code which has "hidden" variants should mark itself as non exhaustive to be explicit; they are effectively non-exhaustive.

Lint Name

synthetic_non_exhaustive

Category

style

Advantage

Once again, see discussion in linked issues.

enums which have #[doc(hidden)] variants are effectively non-exhaustive and should be marked as such to give clarity to the consumer of the enum.

Drawbacks

See discussion in linked issues (last time I promise).

In summary, we aren't sure about the extent to which this affects existing code and how much of that code is, in actuality, valid. For example, libcore and libbacktrace are triggered by this lint: in libbacktrace at least, the offending code is not idiomatic and is a valid example of this lint.

Example

pub enum Foo {
    A,
    B,
    #[doc(hidden)]
    C,
}

Could be written as:

#[non_exhaustive]
pub enum Foo {
    A,
    B,
    #[doc(hidden)]
    C,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions