Skip to content

Commit 4a88c2b

Browse files
committed
Keep reference to the original Pat in DeconstructedPat
1 parent 00c54e4 commit 4a88c2b

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

compiler/rustc_mir_build/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'thir, 'tcx, 'm> {
460460
pub ty: Ty<'tcx>,
461461
}
462462

463-
impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
463+
impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_, '_> {
464464
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'_> {
465465
let mut diag = DiagnosticBuilder::new(
466466
dcx,

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
@@ -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)