Skip to content

Commit 87e93f6

Browse files
committed
Keep reference to the original Pat in DeconstructedPat
1 parent d6b1b1e commit 87e93f6

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
@@ -857,21 +857,21 @@ fn report_arm_reachability<'p, 'thir, 'tcx>(
857857
for (arm, is_useful) in report.arm_usefulness.iter() {
858858
match is_useful {
859859
Usefulness::Redundant => {
860-
report_unreachable_pattern(*arm.pat.data().unwrap(), arm.arm_data, catchall)
860+
report_unreachable_pattern(arm.pat.data().unwrap().span, arm.arm_data, catchall)
861861
}
862862
Usefulness::Useful(redundant_subpats) if redundant_subpats.is_empty() => {}
863863
// The arm is reachable, but contains redundant subpatterns (from or-patterns).
864864
Usefulness::Useful(redundant_subpats) => {
865865
let mut redundant_subpats = redundant_subpats.clone();
866866
// Emit lints in the order in which they occur in the file.
867-
redundant_subpats.sort_unstable_by_key(|pat| pat.data());
867+
redundant_subpats.sort_unstable_by_key(|pat| pat.data().unwrap().span);
868868
for pat in redundant_subpats {
869-
report_unreachable_pattern(*pat.data().unwrap(), arm.arm_data, None);
869+
report_unreachable_pattern(pat.data().unwrap().span, arm.arm_data, None);
870870
}
871871
}
872872
}
873873
if !arm.has_guard && catchall.is_none() && pat_is_catchall(arm.pat) {
874-
catchall = Some(*arm.pat.data().unwrap());
874+
catchall = Some(arm.pat.data().unwrap().span);
875875
}
876876
}
877877
}

compiler/rustc_pattern_analysis/src/lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'thir, 'tcx>(
208208
};
209209

210210
use rustc_errors::DecorateLint;
211-
let mut err = rcx.tcx.sess.struct_span_warn(*arm.pat.data().unwrap(), "");
211+
let mut err = rcx.tcx.sess.struct_span_warn(arm.pat.data().unwrap().span, "");
212212
err.set_primary_message(decorator.msg());
213213
decorator.decorate_lint(&mut err);
214214
err.emit();
@@ -259,7 +259,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'thir, 'tcx>(
259259
// Iterate on patterns that contained `overlap`.
260260
for pat in column.iter() {
261261
let Constructor::IntRange(this_range) = pat.ctor() else { continue };
262-
let this_span = *pat.data().unwrap();
262+
let this_span = pat.data().unwrap().span;
263263
if this_range.is_singleton() {
264264
// Don't lint when one of the ranges is a singleton.
265265
continue;

compiler/rustc_pattern_analysis/src/rustc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'p, 'thir, 'tcx> RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
549549
// `Ref`), and has one field. That field has constructor `Str(value)` and no
550550
// subfields.
551551
// Note: `t` is `str`, not `&str`.
552-
let subpattern = DeconstructedPat::new(Str(*value), &[], *t, pat.span);
552+
let subpattern = DeconstructedPat::new(Str(*value), &[], *t, pat);
553553
ctor = Ref;
554554
fields = singleton(subpattern)
555555
}
@@ -633,7 +633,7 @@ impl<'p, 'thir, 'tcx> RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
633633
fields = &[];
634634
}
635635
}
636-
DeconstructedPat::new(ctor, fields, pat.ty, pat.span)
636+
DeconstructedPat::new(ctor, fields, pat.ty, pat)
637637
}
638638

639639
/// Convert back to a `thir::PatRangeBoundary` for diagnostic purposes.
@@ -903,7 +903,7 @@ impl<'p, 'thir, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
903903
type VariantIdx = VariantIdx;
904904
type StrLit = Const<'tcx>;
905905
type ArmData = HirId;
906-
type PatData = Span;
906+
type PatData = &'thir Pat<'tcx>;
907907

908908
fn is_exhaustive_patterns_feature_on(&self) -> bool {
909909
self.tcx.features().exhaustive_patterns

0 commit comments

Comments
 (0)