Skip to content

Commit 9da4432

Browse files
committed
Auto merge of #119233 - Nadrieril:keep-whole-pat-around, r=compiler-errors
Exhaustiveness: keep the original `thir::Pat` around This PR makes it possible for exhaustiveness to look at the original `thir::Pat`, which I'll need at least for the [`small_gaps`](#118879) lint (without that we can't distinguish inclusive and exclusive ranges within exhaustiveness). This PR is almost entirely lifetime-wrangling.
2 parents 625c2c4 + fc0be3c commit 9da4432

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -856,21 +856,21 @@ fn report_arm_reachability<'p, 'tcx>(
856856
for (arm, is_useful) in report.arm_usefulness.iter() {
857857
match is_useful {
858858
Usefulness::Redundant => {
859-
report_unreachable_pattern(*arm.pat.data().unwrap(), arm.arm_data, catchall)
859+
report_unreachable_pattern(arm.pat.data().unwrap().span, arm.arm_data, catchall)
860860
}
861861
Usefulness::Useful(redundant_subpats) if redundant_subpats.is_empty() => {}
862862
// The arm is reachable, but contains redundant subpatterns (from or-patterns).
863863
Usefulness::Useful(redundant_subpats) => {
864864
let mut redundant_subpats = redundant_subpats.clone();
865865
// Emit lints in the order in which they occur in the file.
866-
redundant_subpats.sort_unstable_by_key(|pat| pat.data());
866+
redundant_subpats.sort_unstable_by_key(|pat| pat.data().unwrap().span);
867867
for pat in redundant_subpats {
868-
report_unreachable_pattern(*pat.data().unwrap(), arm.arm_data, None);
868+
report_unreachable_pattern(pat.data().unwrap().span, arm.arm_data, None);
869869
}
870870
}
871871
}
872872
if !arm.has_guard && catchall.is_none() && pat_is_catchall(arm.pat) {
873-
catchall = Some(*arm.pat.data().unwrap());
873+
catchall = Some(arm.pat.data().unwrap().span);
874874
}
875875
}
876876
}

compiler/rustc_pattern_analysis/src/lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
203203
};
204204

205205
use rustc_errors::DecorateLint;
206-
let mut err = rcx.tcx.dcx().struct_span_warn(*arm.pat.data().unwrap(), "");
206+
let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().unwrap().span, "");
207207
err.set_primary_message(decorator.msg());
208208
decorator.decorate_lint(&mut err);
209209
err.emit();
@@ -254,7 +254,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
254254
// Iterate on patterns that contained `overlap`.
255255
for pat in column.iter() {
256256
let Constructor::IntRange(this_range) = pat.ctor() else { continue };
257-
let this_span = *pat.data().unwrap();
257+
let this_span = pat.data().unwrap().span;
258258
if this_range.is_singleton() {
259259
// Don't lint when one of the ranges is a singleton.
260260
continue;

compiler/rustc_pattern_analysis/src/rustc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
540540
// `Ref`), and has one field. That field has constructor `Str(value)` and no
541541
// subfields.
542542
// Note: `t` is `str`, not `&str`.
543-
let subpattern = DeconstructedPat::new(Str(*value), &[], *t, pat.span);
543+
let subpattern = DeconstructedPat::new(Str(*value), &[], *t, pat);
544544
ctor = Ref;
545545
fields = singleton(subpattern)
546546
}
@@ -624,7 +624,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
624624
fields = &[];
625625
}
626626
}
627-
DeconstructedPat::new(ctor, fields, pat.ty, pat.span)
627+
DeconstructedPat::new(ctor, fields, pat.ty, pat)
628628
}
629629

630630
/// Convert back to a `thir::PatRangeBoundary` for diagnostic purposes.
@@ -894,7 +894,7 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
894894
type VariantIdx = VariantIdx;
895895
type StrLit = Const<'tcx>;
896896
type ArmData = HirId;
897-
type PatData = Span;
897+
type PatData = &'p Pat<'tcx>;
898898

899899
fn is_exhaustive_patterns_feature_on(&self) -> bool {
900900
self.tcx.features().exhaustive_patterns

0 commit comments

Comments
 (0)