Add helper methods checking for "#[non_exhaustive] that's active"

A check for `#[non_exhaustive]` is often done in combination with
checking whether the type is local to the crate, in a variety of ways.
Create a helper method and standardize on it as the way to check for
this.
This commit is contained in:
Maja Kądziołka 2025-03-03 12:54:26 +01:00
parent e5c1d1cb7e
commit 10cf3cb945
3 changed files with 5 additions and 4 deletions

View file

@ -51,7 +51,7 @@ impl LateLintPass<'_> for UnneededStructPattern {
let variant = cx.tcx.adt_def(enum_did).variant_with_id(did);
let has_only_fields_brackets = variant.ctor.is_some() && variant.fields.is_empty();
let non_exhaustive_activated = !variant.def_id.is_local() && variant.is_field_list_non_exhaustive();
let non_exhaustive_activated = variant.field_list_has_applicable_non_exhaustive();
if !has_only_fields_brackets || non_exhaustive_activated {
return;
}