Deduplicate code for formatting RangeEnd
This commit is contained in:
parent
be9e6af65e
commit
1ec60730fe
3 changed files with 12 additions and 9 deletions
|
@ -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., `_`).
|
||||
|
|
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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 } |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue