Skip to content

Commit

Permalink
Keep reference to the original Pat in DeconstructedPat
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Dec 24, 2023
1 parent d6b1b1e commit 87e93f6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,21 +857,21 @@ fn report_arm_reachability<'p, 'thir, 'tcx>(
for (arm, is_useful) in report.arm_usefulness.iter() {
match is_useful {
Usefulness::Redundant => {
report_unreachable_pattern(*arm.pat.data().unwrap(), arm.arm_data, catchall)
report_unreachable_pattern(arm.pat.data().unwrap().span, arm.arm_data, catchall)
}
Usefulness::Useful(redundant_subpats) if redundant_subpats.is_empty() => {}
// The arm is reachable, but contains redundant subpatterns (from or-patterns).
Usefulness::Useful(redundant_subpats) => {
let mut redundant_subpats = redundant_subpats.clone();
// Emit lints in the order in which they occur in the file.
redundant_subpats.sort_unstable_by_key(|pat| pat.data());
redundant_subpats.sort_unstable_by_key(|pat| pat.data().unwrap().span);
for pat in redundant_subpats {
report_unreachable_pattern(*pat.data().unwrap(), arm.arm_data, None);
report_unreachable_pattern(pat.data().unwrap().span, arm.arm_data, None);
}
}
}
if !arm.has_guard && catchall.is_none() && pat_is_catchall(arm.pat) {
catchall = Some(*arm.pat.data().unwrap());
catchall = Some(arm.pat.data().unwrap().span);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_pattern_analysis/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'thir, 'tcx>(
};

use rustc_errors::DecorateLint;
let mut err = rcx.tcx.sess.struct_span_warn(*arm.pat.data().unwrap(), "");
let mut err = rcx.tcx.sess.struct_span_warn(arm.pat.data().unwrap().span, "");
err.set_primary_message(decorator.msg());
decorator.decorate_lint(&mut err);
err.emit();
Expand Down Expand Up @@ -259,7 +259,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'thir, 'tcx>(
// Iterate on patterns that contained `overlap`.
for pat in column.iter() {
let Constructor::IntRange(this_range) = pat.ctor() else { continue };
let this_span = *pat.data().unwrap();
let this_span = pat.data().unwrap().span;
if this_range.is_singleton() {
// Don't lint when one of the ranges is a singleton.
continue;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_pattern_analysis/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl<'p, 'thir, 'tcx> RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
// `Ref`), and has one field. That field has constructor `Str(value)` and no
// subfields.
// Note: `t` is `str`, not `&str`.
let subpattern = DeconstructedPat::new(Str(*value), &[], *t, pat.span);
let subpattern = DeconstructedPat::new(Str(*value), &[], *t, pat);
ctor = Ref;
fields = singleton(subpattern)
}
Expand Down Expand Up @@ -633,7 +633,7 @@ impl<'p, 'thir, 'tcx> RustcMatchCheckCtxt<'p, 'thir, 'tcx> {
fields = &[];
}
}
DeconstructedPat::new(ctor, fields, pat.ty, pat.span)
DeconstructedPat::new(ctor, fields, pat.ty, pat)
}

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

fn is_exhaustive_patterns_feature_on(&self) -> bool {
self.tcx.features().exhaustive_patterns
Expand Down

0 comments on commit 87e93f6

Please sign in to comment.