Skip to content

Commit e85fcab

Browse files
authored
Rollup merge of rust-lang#138001 - meithecatte:privately-uninhabited, r=Nadrieril
mir_build: consider privacy when checking for irrefutable patterns This PR fixes rust-lang#137999. Note that, since this makes the compiler reject code that was previously accepted, it will probably need a crater run. I include a commit that factors out a common code pattern into a helper function, purely because the fact that this was repeated all over the place was bothering me. Let me know if I should split that into a separate PR instead.
2 parents 9932e5e + 10cf3cb commit e85fcab

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)