Skip to content

Commit 10cf3cb

Browse files
committed
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.
1 parent e5c1d1c commit 10cf3cb

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

clippy_lints/src/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
134134
&& let ty::Adt(adt, args) = *binding_type.kind()
135135
&& adt.is_struct()
136136
&& let variant = adt.non_enum_variant()
137-
&& (adt.did().is_local() || !variant.is_field_list_non_exhaustive())
137+
&& !variant.field_list_has_applicable_non_exhaustive()
138138
&& let module_did = cx.tcx.parent_module(stmt.hir_id)
139139
&& variant
140140
.fields

clippy_lints/src/needless_update.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessUpdate {
5454
if let ExprKind::Struct(_, fields, StructTailExpr::Base(base)) = expr.kind {
5555
let ty = cx.typeck_results().expr_ty(expr);
5656
if let ty::Adt(def, _) = ty.kind() {
57-
if fields.len() == def.non_enum_variant().fields.len()
58-
&& !def.variant(0_usize.into()).is_field_list_non_exhaustive()
57+
let variant = def.non_enum_variant();
58+
if fields.len() == variant.fields.len()
59+
&& !variant.is_field_list_non_exhaustive()
5960
{
6061
span_lint(
6162
cx,

clippy_lints/src/unneeded_struct_pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl LateLintPass<'_> for UnneededStructPattern {
5151
let variant = cx.tcx.adt_def(enum_did).variant_with_id(did);
5252

5353
let has_only_fields_brackets = variant.ctor.is_some() && variant.fields.is_empty();
54-
let non_exhaustive_activated = !variant.def_id.is_local() && variant.is_field_list_non_exhaustive();
54+
let non_exhaustive_activated = variant.field_list_has_applicable_non_exhaustive();
5555
if !has_only_fields_brackets || non_exhaustive_activated {
5656
return;
5757
}

0 commit comments

Comments
 (0)