From 3e03b5d1a70d906c74baf0ca62fca58eabd9527d Mon Sep 17 00:00:00 2001 From: Tom Prince Date: Thu, 26 Jan 2017 15:32:34 -0700 Subject: [PATCH 1/2] Fix #1476: Add support for exclusive pattern matches. --- clippy_lints/src/matches.rs | 2 +- clippy_lints/src/utils/hir.rs | 4 ++-- clippy_lints/src/utils/inspector.rs | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index e77251e03..ab9819c53 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -361,7 +361,7 @@ fn all_ranges(cx: &LateContext, arms: &[Arm]) -> Vec> { } .filter_map(|pat| { if_let_chain! {[ - let PatKind::Range(ref lhs, ref rhs) = pat.node, + let PatKind::Range(ref lhs, ref rhs, _) = pat.node, let Ok(lhs) = constcx.eval(lhs, ExprTypeChecked), let Ok(rhs) = constcx.eval(rhs, ExprTypeChecked) ], { diff --git a/clippy_lints/src/utils/hir.rs b/clippy_lints/src/utils/hir.rs index 3b1d1a46f..3bce1b3d7 100644 --- a/clippy_lints/src/utils/hir.rs +++ b/clippy_lints/src/utils/hir.rs @@ -160,8 +160,8 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { (&PatKind::Tuple(ref l, ls), &PatKind::Tuple(ref r, rs)) => { ls == rs && over(l, r, |l, r| self.eq_pat(l, r)) }, - (&PatKind::Range(ref ls, ref le), &PatKind::Range(ref rs, ref re)) => { - self.eq_expr(ls, rs) && self.eq_expr(le, re) + (&PatKind::Range(ref ls, ref le, ref li), &PatKind::Range(ref rs, ref re, ref ri)) => { + self.eq_expr(ls, rs) && self.eq_expr(le, re) && (*li == *ri) }, (&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re), (&PatKind::Slice(ref ls, ref li, ref le), &PatKind::Slice(ref rs, ref ri, ref re)) => { diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index d17ed28cd..e08a7d3bf 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -475,10 +475,14 @@ fn print_pat(cx: &LateContext, pat: &hir::Pat, indent: usize) { println!("{}Lit", ind); print_expr(cx, e, indent + 1); }, - hir::PatKind::Range(ref l, ref r) => { + hir::PatKind::Range(ref l, ref r, ref range_end) => { println!("{}Range", ind); print_expr(cx, l, indent + 1); print_expr(cx, r, indent + 1); + match *range_end { + hir::RangeEnd::Included => println!("{} end included", ind), + hir::RangeEnd::Excluded => println!("{} end excluded", ind), + } }, hir::PatKind::Slice(ref first_pats, ref range, ref last_pats) => { println!("{}Slice [a, b, ..i, y, z]", ind); From a140c3c1bfc7db23febf38b79c6ed5842003426f Mon Sep 17 00:00:00 2001 From: Tom Prince Date: Thu, 26 Jan 2017 15:39:01 -0700 Subject: [PATCH 2/2] Remove unused import. --- clippy_lints/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2b778e12c..b6729d797 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -14,7 +14,6 @@ #![allow(indexing_slicing, shadow_reuse, unknown_lints, missing_docs_in_private_items)] #![allow(needless_lifetimes)] -#[macro_use] extern crate syntax; #[macro_use] extern crate rustc;