Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 702d104

Browse files
committed
Move is_top_level out of pcx
1 parent ab090d4 commit 702d104

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,9 @@ impl ConstructorSet {
956956
&self,
957957
pcx: &PatCtxt<'_, '_, 'tcx>,
958958
ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone,
959+
// Whether the current pattern is the whole pattern as found in a match arm, or if it's a
960+
// subpattern.
961+
is_top_level: bool,
959962
) -> SplitConstructorSet<'tcx>
960963
where
961964
'tcx: 'a,
@@ -1072,7 +1075,7 @@ impl ConstructorSet {
10721075
// expose its emptiness. The exception is if the pattern is at the top level, because we
10731076
// want empty matches to be considered exhaustive.
10741077
ConstructorSet::Uninhabited
1075-
if !pcx.cx.tcx.features().exhaustive_patterns && !pcx.is_top_level =>
1078+
if !pcx.cx.tcx.features().exhaustive_patterns && !is_top_level =>
10761079
{
10771080
missing.push(NonExhaustive);
10781081
}

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,6 @@ pub(super) struct PatCtxt<'a, 'p, 'tcx> {
362362
pub(super) ty: Ty<'tcx>,
363363
/// Span of the current pattern under investigation.
364364
pub(super) span: Span,
365-
/// Whether the current pattern is the whole pattern as found in a match arm, or if it's a
366-
/// subpattern.
367-
pub(super) is_top_level: bool,
368365
}
369366

370367
impl<'a, 'p, 'tcx> fmt::Debug for PatCtxt<'a, 'p, 'tcx> {
@@ -791,10 +788,10 @@ fn compute_usefulness<'p, 'tcx>(
791788

792789
let ty = matrix.head_ty();
793790
debug!("ty: {ty:?}");
794-
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP, is_top_level };
791+
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP };
795792

796793
let ctors = matrix.heads().map(|p| p.ctor());
797-
let split_set = ConstructorSet::for_ty(pcx.cx, pcx.ty).split(pcx, ctors);
794+
let split_set = ConstructorSet::for_ty(pcx.cx, pcx.ty).split(pcx, ctors, is_top_level);
798795
let mut split_ctors = split_set.present;
799796
let missing_ctors = split_set.missing;
800797
if !missing_ctors.is_empty() {
@@ -842,7 +839,7 @@ fn compute_usefulness<'p, 'tcx>(
842839
// usually prefer to report the full list of constructors.
843840
let all_missing = split_ctors.is_empty();
844841
let report_when_all_missing =
845-
pcx.is_top_level && !super::deconstruct_pat::IntRange::is_integral(pcx.ty);
842+
is_top_level && !super::deconstruct_pat::IntRange::is_integral(pcx.ty);
846843
let ctor = if all_missing && !report_when_all_missing {
847844
Constructor::Wildcard
848845
} else {
@@ -918,9 +915,10 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
918915
column: &[&DeconstructedPat<'p, 'tcx>],
919916
) -> Vec<WitnessPat<'tcx>> {
920917
let ty = column[0].ty();
921-
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP, is_top_level: false };
918+
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP };
922919

923-
let set = ConstructorSet::for_ty(pcx.cx, pcx.ty).split(pcx, column.iter().map(|p| p.ctor()));
920+
let column_ctors = column.iter().map(|p| p.ctor());
921+
let set = ConstructorSet::for_ty(pcx.cx, pcx.ty).split(pcx, column_ctors, false);
924922
if set.present.is_empty() {
925923
// We can't consistently handle the case where no constructors are present (since this would
926924
// require digging deep through any type in case there's a non_exhaustive enum somewhere),

0 commit comments

Comments
 (0)