Skip to content

Commit 1ec6073

Browse files
committed
Deduplicate code for formatting RangeEnd
1 parent be9e6af commit 1ec6073

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/librustc/hir/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,15 @@ pub enum RangeEnd {
989989
Excluded,
990990
}
991991

992+
impl fmt::Display for RangeEnd {
993+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
994+
f.write_str(match self {
995+
RangeEnd::Included => "..=",
996+
RangeEnd::Excluded => "..",
997+
})
998+
}
999+
}
1000+
9921001
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
9931002
pub enum PatKind {
9941003
/// Represents a wildcard pattern (i.e., `_`).

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,9 @@ impl<'tcx> Constructor<'tcx> {
482482
// Get the right sign on the output:
483483
let ty = ty::ParamEnv::empty().and(*ty);
484484
format!(
485-
"{}..{}{}",
485+
"{}{}{}",
486486
ty::Const::from_bits(tcx, *lo, ty),
487-
match range_end {
488-
RangeEnd::Included => "=",
489-
RangeEnd::Excluded => "",
490-
},
487+
range_end,
491488
ty::Const::from_bits(tcx, *hi, ty),
492489
)
493490
}

src/librustc_mir/hair/pattern/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
312312
}
313313
PatKind::Range(PatRange { lo, hi, end }) => {
314314
write!(f, "{}", lo)?;
315-
match end {
316-
RangeEnd::Included => write!(f, "..=")?,
317-
RangeEnd::Excluded => write!(f, "..")?,
318-
}
315+
write!(f, "{}", end)?;
319316
write!(f, "{}", hi)
320317
}
321318
PatKind::Slice { ref prefix, ref slice, ref suffix } |

0 commit comments

Comments
 (0)