Remove unimplemented!() case in matches code

This unbounded case never actually happens because `all_ranges(..)` uses
the scrutinee type bounds for open ranges. Switch to our own `Bound`
enum so that we don't have this case.
This commit is contained in:
Michael Wright 2021-11-09 05:44:02 +02:00
parent 830f2205d4
commit 98416d7f6c

View File

@ -33,7 +33,6 @@
use rustc_span::sym;
use std::cmp::Ordering;
use std::collections::hash_map::Entry;
use std::ops::Bound;
declare_clippy_lint! {
/// ### What it does
@ -1596,7 +1595,7 @@ fn opt_parent_let<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<&'a Local<'
None
}
/// Gets all arms that are unbounded `PatRange`s.
/// Gets the ranges for each range pattern arm. Applies `ty` bounds for open ranges.
fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) -> Vec<SpannedRange<FullInt>> {
arms.iter()
.filter_map(|arm| {
@ -1637,6 +1636,12 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
.collect()
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Bound<T> {
Included(T),
Excluded(T),
}
#[derive(Debug, Eq, PartialEq)]
pub struct SpannedRange<T> {
pub span: Span,
@ -1730,8 +1735,6 @@ fn cmp(&self, other: &Self) -> Ordering {
value_cmp
}
},
// Range patterns cannot be unbounded (yet)
(Bound::Unbounded, _) | (_, Bound::Unbounded) => unimplemented!(),
(Bound::Included(a), Bound::Excluded(b)) => match a.cmp(&b) {
Ordering::Equal => Ordering::Greater,
other => other,