Skip to content

Commit 34399d4

Browse files
authored
Merge pull request #1477 from tomprince/support-exclusive-patterns
Fix #1476: Add support for exclusive pattern matches.
2 parents 4ea0f72 + a140c3c commit 34399d4

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

clippy_lints/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![allow(indexing_slicing, shadow_reuse, unknown_lints, missing_docs_in_private_items)]
1515
#![allow(needless_lifetimes)]
1616

17-
#[macro_use]
1817
extern crate syntax;
1918
#[macro_use]
2019
extern crate rustc;

clippy_lints/src/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn all_ranges(cx: &LateContext, arms: &[Arm]) -> Vec<SpannedRange<ConstVal>> {
361361
}
362362
.filter_map(|pat| {
363363
if_let_chain! {[
364-
let PatKind::Range(ref lhs, ref rhs) = pat.node,
364+
let PatKind::Range(ref lhs, ref rhs, _) = pat.node,
365365
let Ok(lhs) = constcx.eval(lhs, ExprTypeChecked),
366366
let Ok(rhs) = constcx.eval(rhs, ExprTypeChecked)
367367
], {

clippy_lints/src/utils/hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
160160
(&PatKind::Tuple(ref l, ls), &PatKind::Tuple(ref r, rs)) => {
161161
ls == rs && over(l, r, |l, r| self.eq_pat(l, r))
162162
},
163-
(&PatKind::Range(ref ls, ref le), &PatKind::Range(ref rs, ref re)) => {
164-
self.eq_expr(ls, rs) && self.eq_expr(le, re)
163+
(&PatKind::Range(ref ls, ref le, ref li), &PatKind::Range(ref rs, ref re, ref ri)) => {
164+
self.eq_expr(ls, rs) && self.eq_expr(le, re) && (*li == *ri)
165165
},
166166
(&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re),
167167
(&PatKind::Slice(ref ls, ref li, ref le), &PatKind::Slice(ref rs, ref ri, ref re)) => {

clippy_lints/src/utils/inspector.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,14 @@ fn print_pat(cx: &LateContext, pat: &hir::Pat, indent: usize) {
475475
println!("{}Lit", ind);
476476
print_expr(cx, e, indent + 1);
477477
},
478-
hir::PatKind::Range(ref l, ref r) => {
478+
hir::PatKind::Range(ref l, ref r, ref range_end) => {
479479
println!("{}Range", ind);
480480
print_expr(cx, l, indent + 1);
481481
print_expr(cx, r, indent + 1);
482+
match *range_end {
483+
hir::RangeEnd::Included => println!("{} end included", ind),
484+
hir::RangeEnd::Excluded => println!("{} end excluded", ind),
485+
}
482486
},
483487
hir::PatKind::Slice(ref first_pats, ref range, ref last_pats) => {
484488
println!("{}Slice [a, b, ..i, y, z]", ind);

0 commit comments

Comments
 (0)