diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-19 16:52:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-19 16:52:54 +0100 |
| commit | e85fcabd9f28e7fea60d0f87273d3b9e00029cb6 (patch) | |
| tree | bc49e93cfa1cb960c664dcb116de53065a10ec42 | |
| parent | 9932e5e6694d9bd02f49418a765a59467e940d7d (diff) | |
| parent | 10cf3cb945b413c0fb81cf13c4bf4db762ba5377 (diff) | |
| download | rust-e85fcabd9f28e7fea60d0f87273d3b9e00029cb6.tar.gz rust-e85fcabd9f28e7fea60d0f87273d3b9e00029cb6.zip | |
Rollup merge of #138001 - meithecatte:privately-uninhabited, r=Nadrieril
mir_build: consider privacy when checking for irrefutable patterns This PR fixes #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.
| -rw-r--r-- | clippy_lints/src/default.rs | 2 | ||||
| -rw-r--r-- | clippy_lints/src/needless_update.rs | 5 | ||||
| -rw-r--r-- | clippy_lints/src/unneeded_struct_pattern.rs | 2 |
3 files changed, 5 insertions, 4 deletions
diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index ffdd946aadb..886c325b355 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { && let ty::Adt(adt, args) = *binding_type.kind() && adt.is_struct() && let variant = adt.non_enum_variant() - && (adt.did().is_local() || !variant.is_field_list_non_exhaustive()) + && !variant.field_list_has_applicable_non_exhaustive() && let module_did = cx.tcx.parent_module(stmt.hir_id) && variant .fields diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 0cba72bd2c6..cce0617ba39 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -54,8 +54,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessUpdate { if let ExprKind::Struct(_, fields, StructTailExpr::Base(base)) = expr.kind { let ty = cx.typeck_results().expr_ty(expr); if let ty::Adt(def, _) = ty.kind() { - if fields.len() == def.non_enum_variant().fields.len() - && !def.variant(0_usize.into()).is_field_list_non_exhaustive() + let variant = def.non_enum_variant(); + if fields.len() == variant.fields.len() + && !variant.is_field_list_non_exhaustive() { span_lint( cx, diff --git a/clippy_lints/src/unneeded_struct_pattern.rs b/clippy_lints/src/unneeded_struct_pattern.rs index a74eab8b6ae..3326dea8c5d 100644 --- a/clippy_lints/src/unneeded_struct_pattern.rs +++ b/clippy_lints/src/unneeded_struct_pattern.rs @@ -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; } |
