diff options
| author | Michael Wright <mikerite@lavabit.com> | 2021-11-09 05:44:02 +0200 |
|---|---|---|
| committer | Michael Wright <mikerite@lavabit.com> | 2021-11-09 05:44:02 +0200 |
| commit | 98416d7f6ca4cc803d423e0897ccdf1deb08fe31 (patch) | |
| tree | b513de9a320a044e888922321c1bca8c4784be08 | |
| parent | 830f2205d4002b26f7fd36d8467fb491eb2306ac (diff) | |
| download | rust-98416d7f6ca4cc803d423e0897ccdf1deb08fe31.tar.gz rust-98416d7f6ca4cc803d423e0897ccdf1deb08fe31.zip | |
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.
| -rw-r--r-- | clippy_lints/src/matches.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 88b1685f52f..6973a3743c7 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -33,7 +33,6 @@ use rustc_span::source_map::{Span, Spanned}; 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 @@ where 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, |
