Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 98416d7

Browse files
author
Michael Wright
committed
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.
1 parent 830f220 commit 98416d7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

clippy_lints/src/matches.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use rustc_span::source_map::{Span, Spanned};
3333
use rustc_span::sym;
3434
use std::cmp::Ordering;
3535
use std::collections::hash_map::Entry;
36-
use std::ops::Bound;
3736

3837
declare_clippy_lint! {
3938
/// ### What it does
@@ -1596,7 +1595,7 @@ fn opt_parent_let<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<&'a Local<'
15961595
None
15971596
}
15981597

1599-
/// Gets all arms that are unbounded `PatRange`s.
1598+
/// Gets the ranges for each range pattern arm. Applies `ty` bounds for open ranges.
16001599
fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) -> Vec<SpannedRange<FullInt>> {
16011600
arms.iter()
16021601
.filter_map(|arm| {
@@ -1637,6 +1636,12 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
16371636
.collect()
16381637
}
16391638

1639+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
1640+
pub enum Bound<T> {
1641+
Included(T),
1642+
Excluded(T),
1643+
}
1644+
16401645
#[derive(Debug, Eq, PartialEq)]
16411646
pub struct SpannedRange<T> {
16421647
pub span: Span,
@@ -1730,8 +1735,6 @@ where
17301735
value_cmp
17311736
}
17321737
},
1733-
// Range patterns cannot be unbounded (yet)
1734-
(Bound::Unbounded, _) | (_, Bound::Unbounded) => unimplemented!(),
17351738
(Bound::Included(a), Bound::Excluded(b)) => match a.cmp(&b) {
17361739
Ordering::Equal => Ordering::Greater,
17371740
other => other,

0 commit comments

Comments
 (0)