Skip to content

Add check for overlapping ranges to unreachable patterns lint #64007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 19, 2019
Prev Previous commit
Next Next commit
Deduplicate code for formatting RangeEnd
  • Loading branch information
estebank committed Oct 16, 2019
commit 1ec60730fecfc72eb7454f2b8d37f7de7068cd20
9 changes: 9 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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., `_`).
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_mir/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } |
Expand Down