Print thir::PatRange, not its surrounding thir::Pat

This further reduces the amount of code that relies on `thir::Pat` being
printable.
This commit is contained in:
Zalathar 2024-07-30 17:28:37 +10:00
parent 83dcdb3a5d
commit a2b3256374

View File

@ -1003,12 +1003,11 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
} }
// `pat` is an exclusive range like `lo..gap`. `gapped_with` contains ranges that start with // `pat` is an exclusive range like `lo..gap`. `gapped_with` contains ranges that start with
// `gap+1`. // `gap+1`.
let suggested_range: thir::Pat<'_> = { let suggested_range: String = {
// Suggest `lo..=gap` instead. // Suggest `lo..=gap` instead.
let mut suggested_range = thir_pat.clone(); let mut suggested_range = PatRange::clone(range);
let thir::PatKind::Range(range) = &mut suggested_range.kind else { unreachable!() }; suggested_range.end = rustc_hir::RangeEnd::Included;
range.end = rustc_hir::RangeEnd::Included; suggested_range.to_string()
suggested_range
}; };
let gap_as_pat = self.hoist_pat_range(&gap, *pat.ty()); let gap_as_pat = self.hoist_pat_range(&gap, *pat.ty());
if gapped_with.is_empty() { if gapped_with.is_empty() {
@ -1023,7 +1022,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
// That's the gap that isn't covered. // That's the gap that isn't covered.
max: gap_as_pat.to_string(), max: gap_as_pat.to_string(),
// Suggest `lo..=max` instead. // Suggest `lo..=max` instead.
suggestion: suggested_range.to_string(), suggestion: suggested_range,
}, },
); );
} else { } else {
@ -1037,7 +1036,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
// That's the gap that isn't covered. // That's the gap that isn't covered.
gap: gap_as_pat.to_string(), gap: gap_as_pat.to_string(),
// Suggest `lo..=gap` instead. // Suggest `lo..=gap` instead.
suggestion: suggested_range.to_string(), suggestion: suggested_range,
// All these ranges skipped over `gap` which we think is probably a // All these ranges skipped over `gap` which we think is probably a
// mistake. // mistake.
gap_with: gapped_with gap_with: gapped_with
@ -1045,7 +1044,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
.map(|pat| errors::GappedRange { .map(|pat| errors::GappedRange {
span: pat.data().span, span: pat.data().span,
gap: gap_as_pat.to_string(), gap: gap_as_pat.to_string(),
first_range: thir_pat.to_string(), first_range: range.to_string(),
}) })
.collect(), .collect(),
}, },