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, 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)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum PatKind { pub enum PatKind {
/// Represents a wildcard pattern (i.e., `_`). /// Represents a wildcard pattern (i.e., `_`).

View file

@ -482,12 +482,9 @@ impl<'tcx> Constructor<'tcx> {
// Get the right sign on the output: // Get the right sign on the output:
let ty = ty::ParamEnv::empty().and(*ty); let ty = ty::ParamEnv::empty().and(*ty);
format!( format!(
"{}..{}{}", "{}{}{}",
ty::Const::from_bits(tcx, *lo, ty), ty::Const::from_bits(tcx, *lo, ty),
match range_end { range_end,
RangeEnd::Included => "=",
RangeEnd::Excluded => "",
},
ty::Const::from_bits(tcx, *hi, ty), 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 }) => { PatKind::Range(PatRange { lo, hi, end }) => {
write!(f, "{}", lo)?; write!(f, "{}", lo)?;
match end { write!(f, "{}", end)?;
RangeEnd::Included => write!(f, "..=")?,
RangeEnd::Excluded => write!(f, "..")?,
}
write!(f, "{}", hi) write!(f, "{}", hi)
} }
PatKind::Slice { ref prefix, ref slice, ref suffix } | PatKind::Slice { ref prefix, ref slice, ref suffix } |