mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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.
This commit is contained in:
@@ -134,7 +134,7 @@ fn check_block(&mut self, cx: &LateContext<'tcx>, block: &Block<'tcx>) {
|
||||
&& 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
|
||||
|
||||
@@ -54,8 +54,9 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
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,
|
||||
|
||||
@@ -51,7 +51,7 @@ fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user