Skip to content

Commit e579fc6

Browse files
committed
Keep reference to the original Pat in DeconstructedPat
1 parent cb9be3e commit e579fc6

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

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
@@ -539,7 +539,7 @@ impl<'p, 'thir, 'tcx> RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
539539
// `Ref`), and has one field. That field has constructor `Str(value)` and no
540540
// subfields.
541541
// Note: `t` is `str`, not `&str`.
542-
let subpattern = DeconstructedPat::new(Str(*value), &[], *t, pat.span);
542+
let subpattern = DeconstructedPat::new(Str(*value), &[], *t, pat);
543543
ctor = Ref;
544544
fields = singleton(subpattern)
545545
}
@@ -623,7 +623,7 @@ impl<'p, 'thir, 'tcx> RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
623623
fields = &[];
624624
}
625625
}
626-
DeconstructedPat::new(ctor, fields, pat.ty, pat.span)
626+
DeconstructedPat::new(ctor, fields, pat.ty, pat)
627627
}
628628

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

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

0 commit comments

Comments
 (0)