1
Fork 0

Deduplicate code for formatting RangeEnd

This commit is contained in:
Esteban Küber 2019-08-29 17:42:45 -07:00
parent be9e6af65e
commit 1ec60730fe
3 changed files with 12 additions and 9 deletions

View file

@ -989,6 +989,15 @@ pub enum RangeEnd {
Excluded,
}
impl fmt::Display for RangeEnd {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
RangeEnd::Included => "..=",
RangeEnd::Excluded => "..",
})
}
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum PatKind {
/// Represents a wildcard pattern (i.e., `_`).

View file

@ -482,12 +482,9 @@ impl<'tcx> Constructor<'tcx> {
// Get the right sign on the output:
let ty = ty::ParamEnv::empty().and(*ty);
format!(
"{}..{}{}",
"{}{}{}",
ty::Const::from_bits(tcx, *lo, ty),
match range_end {
RangeEnd::Included => "=",
RangeEnd::Excluded => "",
},
range_end,
ty::Const::from_bits(tcx, *hi, ty),
)
}

View file

@ -312,10 +312,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
}
PatKind::Range(PatRange { lo, hi, end }) => {
write!(f, "{}", lo)?;
match end {
RangeEnd::Included => write!(f, "..=")?,
RangeEnd::Excluded => write!(f, "..")?,
}
write!(f, "{}", end)?;
write!(f, "{}", hi)
}
PatKind::Slice { ref prefix, ref slice, ref suffix } |