rustc_lint::types::improper_ctypes

Function check_non_exhaustive_variant

Source
pub(crate) fn check_non_exhaustive_variant(
    non_local_def: bool,
    variant: &VariantDef,
) -> ControlFlow<DiagMessage, ()>
Expand description

Check a variant of a non-exhaustive enum for improper ctypes

We treat #[non_exhaustive] enum as “ensure that code will compile if new variants are added”. This includes linting, on a best-effort basis. There are valid additions that are unlikely.

Adding a data-carrying variant to an existing C-like enum that is passed to C is “unlikely”, so we don’t need the lint to account for it. e.g. going from enum Foo { A, B, C } to enum Foo { A, B, C, D(u32) }.