Skip to content

rustdoc: synthetic_non_exhaustive lint #10550

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

Closed
Ezrashaw opened this issue Mar 26, 2023 · 1 comment · Fixed by #11844
Closed

rustdoc: synthetic_non_exhaustive lint #10550

Ezrashaw opened this issue Mar 26, 2023 · 1 comment · Fixed by #11844
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@Ezrashaw
Copy link

Ezrashaw commented Mar 26, 2023

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,
}
@Ezrashaw Ezrashaw added the A-lint Area: New lints label Mar 26, 2023
@ghost
Copy link

ghost commented Mar 28, 2023

Hi! This didn't seem too tricky, hoping to push a PR for this today.

@rustbot claim

@rustbot rustbot assigned ghost Mar 28, 2023
@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages and removed A-lint Area: New lints labels Nov 22, 2023
@bors bors closed this as completed in a72730e Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
2 participants