Skip to content

Commit feb769a

Browse files
committed
s/to_pat/to_diagnostic_pat/
1 parent a4875ae commit feb769a

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

Diff for: compiler/rustc_mir_build/src/errors.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -807,13 +807,19 @@ impl<'tcx> Uncovered<'tcx> {
807807
cx: &MatchCheckCtxt<'p, 'tcx>,
808808
witnesses: Vec<WitnessPat<'tcx>>,
809809
) -> Self {
810-
let witness_1 = witnesses.get(0).unwrap().to_pat(cx);
810+
let witness_1 = witnesses.get(0).unwrap().to_diagnostic_pat(cx);
811811
Self {
812812
span,
813813
count: witnesses.len(),
814814
// Substitute dummy values if witnesses is smaller than 3. These will never be read.
815-
witness_2: witnesses.get(1).map(|w| w.to_pat(cx)).unwrap_or_else(|| witness_1.clone()),
816-
witness_3: witnesses.get(2).map(|w| w.to_pat(cx)).unwrap_or_else(|| witness_1.clone()),
815+
witness_2: witnesses
816+
.get(1)
817+
.map(|w| w.to_diagnostic_pat(cx))
818+
.unwrap_or_else(|| witness_1.clone()),
819+
witness_3: witnesses
820+
.get(2)
821+
.map(|w| w.to_diagnostic_pat(cx))
822+
.unwrap_or_else(|| witness_1.clone()),
817823
witness_1,
818824
remainder: witnesses.len().saturating_sub(3),
819825
}

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ fn non_exhaustive_match<'p, 'tcx>(
760760
pattern = if witnesses.len() < 4 {
761761
witnesses
762762
.iter()
763-
.map(|witness| witness.to_pat(cx).to_string())
763+
.map(|witness| witness.to_diagnostic_pat(cx).to_string())
764764
.collect::<Vec<String>>()
765765
.join(" | ")
766766
} else {
@@ -915,13 +915,13 @@ pub(crate) fn joined_uncovered_patterns<'p, 'tcx>(
915915
witnesses: &[WitnessPat<'tcx>],
916916
) -> String {
917917
const LIMIT: usize = 3;
918-
let pat_to_str = |pat: &WitnessPat<'tcx>| pat.to_pat(cx).to_string();
918+
let pat_to_str = |pat: &WitnessPat<'tcx>| pat.to_diagnostic_pat(cx).to_string();
919919
match witnesses {
920920
[] => bug!(),
921-
[witness] => format!("`{}`", witness.to_pat(cx)),
921+
[witness] => format!("`{}`", witness.to_diagnostic_pat(cx)),
922922
[head @ .., tail] if head.len() < LIMIT => {
923923
let head: Vec<_> = head.iter().map(pat_to_str).collect();
924-
format!("`{}` and `{}`", head.join("`, `"), tail.to_pat(cx))
924+
format!("`{}` and `{}`", head.join("`, `"), tail.to_diagnostic_pat(cx))
925925
}
926926
_ => {
927927
let (head, tail) = witnesses.split_at(LIMIT);

Diff for: compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ impl MaybeInfiniteInt {
140140
PatRangeBoundary::PosInfinity => PosInfinity,
141141
}
142142
}
143-
// This could change from finite to infinite if we got `usize::MAX+1` after range splitting.
144-
fn to_pat_range_bdy<'tcx>(self, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> PatRangeBoundary<'tcx> {
143+
/// Used only for diagnostics.
144+
/// This could change from finite to infinite if we got `usize::MAX+1` after range splitting.
145+
fn to_diagnostic_pat_range_bdy<'tcx>(
146+
self,
147+
ty: Ty<'tcx>,
148+
tcx: TyCtxt<'tcx>,
149+
) -> PatRangeBoundary<'tcx> {
145150
match self {
146151
NegInfinity => PatRangeBoundary::NegInfinity,
147152
Finite(x) => {
@@ -326,25 +331,25 @@ impl IntRange {
326331
/// Whether the range denotes the values before `isize::MIN` or the values after
327332
/// `usize::MAX`/`isize::MAX`.
328333
pub(crate) fn is_beyond_boundaries<'tcx>(&self, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> bool {
329-
// First check if we are usize/isize to avoid unnecessary `to_pat_range_bdy`.
334+
// First check if we are usize/isize to avoid unnecessary `to_diagnostic_pat_range_bdy`.
330335
ty.is_ptr_sized_integral() && !tcx.features().precise_pointer_size_matching && {
331-
let lo = self.lo.to_pat_range_bdy(ty, tcx);
332-
let hi = self.hi.to_pat_range_bdy(ty, tcx);
336+
let lo = self.lo.to_diagnostic_pat_range_bdy(ty, tcx);
337+
let hi = self.hi.to_diagnostic_pat_range_bdy(ty, tcx);
333338
matches!(lo, PatRangeBoundary::PosInfinity)
334339
|| matches!(hi, PatRangeBoundary::NegInfinity)
335340
}
336341
}
337342
/// Only used for displaying the range.
338-
pub(super) fn to_pat<'tcx>(&self, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Pat<'tcx> {
343+
pub(super) fn to_diagnostic_pat<'tcx>(&self, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Pat<'tcx> {
339344
let kind = if matches!((self.lo, self.hi), (NegInfinity, PosInfinity)) {
340345
PatKind::Wild
341346
} else if self.is_singleton() {
342-
let lo = self.lo.to_pat_range_bdy(ty, tcx);
347+
let lo = self.lo.to_diagnostic_pat_range_bdy(ty, tcx);
343348
let value = lo.as_finite().unwrap();
344349
PatKind::Constant { value }
345350
} else {
346-
let mut lo = self.lo.to_pat_range_bdy(ty, tcx);
347-
let mut hi = self.hi.to_pat_range_bdy(ty, tcx);
351+
let mut lo = self.lo.to_diagnostic_pat_range_bdy(ty, tcx);
352+
let mut hi = self.hi.to_diagnostic_pat_range_bdy(ty, tcx);
348353
let end = if hi.is_finite() {
349354
RangeEnd::Included
350355
} else {
@@ -1803,13 +1808,14 @@ impl<'tcx> WitnessPat<'tcx> {
18031808
self.ty
18041809
}
18051810

1806-
/// Convert back to a `thir::Pat` for diagnostic purposes.
1807-
pub(crate) fn to_pat(&self, cx: &MatchCheckCtxt<'_, 'tcx>) -> Pat<'tcx> {
1811+
/// Convert back to a `thir::Pat` for diagnostic purposes. This panics for patterns that don't
1812+
/// appear in diagnostics, like float ranges.
1813+
pub(crate) fn to_diagnostic_pat(&self, cx: &MatchCheckCtxt<'_, 'tcx>) -> Pat<'tcx> {
18081814
let is_wildcard = |pat: &Pat<'_>| matches!(pat.kind, PatKind::Wild);
1809-
let mut subpatterns = self.iter_fields().map(|p| Box::new(p.to_pat(cx)));
1815+
let mut subpatterns = self.iter_fields().map(|p| Box::new(p.to_diagnostic_pat(cx)));
18101816
let kind = match &self.ctor {
18111817
Bool(b) => PatKind::Constant { value: mir::Const::from_bool(cx.tcx, *b) },
1812-
IntRange(range) => return range.to_pat(self.ty, cx.tcx),
1818+
IntRange(range) => return range.to_diagnostic_pat(self.ty, cx.tcx),
18131819
Single | Variant(_) => match self.ty.kind() {
18141820
ty::Tuple(..) => PatKind::Leaf {
18151821
subpatterns: subpatterns

Diff for: compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ fn lint_overlapping_range_endpoints<'p, 'tcx>(
10141014

10151015
if IntRange::is_integral(ty) {
10161016
let emit_lint = |overlap: &IntRange, this_span: Span, overlapped_spans: &[Span]| {
1017-
let overlap_as_pat = overlap.to_pat(ty, cx.tcx);
1017+
let overlap_as_pat = overlap.to_diagnostic_pat(ty, cx.tcx);
10181018
let overlaps: Vec<_> = overlapped_spans
10191019
.iter()
10201020
.copied()

0 commit comments

Comments
 (0)