about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
diff options
context:
space:
mode:
authorMaja Kądziołka <maya@compilercrim.es>2025-03-03 12:54:26 +0100
committerMaja Kądziołka <maya@compilercrim.es>2025-03-07 16:16:36 +0100
commit61f70003c2122313faf77185b6e5ec4bc2ba3bb5 (patch)
treec3bc0b0b03c47959e4b5d0de200f1679b5e9f0db /compiler/rustc_mir_build/src
parent59a9b9e9d776cb5d6bc02e99c4dce4f94f622232 (diff)
downloadrust-61f70003c2122313faf77185b6e5ec4bc2ba3bb5.tar.gz
rust-61f70003c2122313faf77185b6e5ec4bc2ba3bb5.zip
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.
Diffstat (limited to 'compiler/rustc_mir_build/src')
-rw-r--r--compiler/rustc_mir_build/src/builder/matches/match_pair.rs3
-rw-r--r--compiler/rustc_mir_build/src/errors.rs6
2 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_mir_build/src/builder/matches/match_pair.rs b/compiler/rustc_mir_build/src/builder/matches/match_pair.rs
index c6f3e22e95f..c41538a2817 100644
--- a/compiler/rustc_mir_build/src/builder/matches/match_pair.rs
+++ b/compiler/rustc_mir_build/src/builder/matches/match_pair.rs
@@ -277,8 +277,7 @@ impl<'tcx> MatchPairTree<'tcx> {
                             .inhabited_predicate(cx.tcx, adt_def)
                             .instantiate(cx.tcx, args)
                             .apply_ignore_module(cx.tcx, cx.infcx.typing_env(cx.param_env))
-                }) && (adt_def.did().is_local()
-                    || !adt_def.is_variant_list_non_exhaustive());
+                }) && !adt_def.variant_list_has_applicable_non_exhaustive();
                 if irrefutable { None } else { Some(TestCase::Variant { adt_def, variant_index }) }
             }
 
diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs
index 17b22f25dbb..0e16f871b16 100644
--- a/compiler/rustc_mir_build/src/errors.rs
+++ b/compiler/rustc_mir_build/src/errors.rs
@@ -613,9 +613,9 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NonExhaustivePatternsTypeNo
             diag.span_note(span, fluent::mir_build_def_note);
         }
 
-        let is_variant_list_non_exhaustive = matches!(self.ty.kind(),
-            ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
-        if is_variant_list_non_exhaustive {
+        let is_non_exhaustive = matches!(self.ty.kind(),
+            ty::Adt(def, _) if def.variant_list_has_applicable_non_exhaustive());
+        if is_non_exhaustive {
             diag.note(fluent::mir_build_non_exhaustive_type_note);
         } else {
             diag.note(fluent::mir_build_type_note);