]> git.lizzy.rs Git - rust.git/commitdiff
Fix #1476: Add support for exclusive pattern matches.
authorTom Prince <tom.prince@twistedmatrix.com>
Thu, 26 Jan 2017 22:32:34 +0000 (15:32 -0700)
committerTom Prince <tom.prince@twistedmatrix.com>
Thu, 26 Jan 2017 22:32:34 +0000 (15:32 -0700)
clippy_lints/src/matches.rs
clippy_lints/src/utils/hir.rs
clippy_lints/src/utils/inspector.rs

index e77251e0321e727ea7a47b7f0d3b124363297215..ab9819c53714b457beae7f8a34f483fdf318bdbe 100644 (file)
@@ -361,7 +361,7 @@ fn all_ranges(cx: &LateContext, arms: &[Arm]) -> Vec<SpannedRange<ConstVal>> {
                 }
                 .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)
                 ], {
index 3b1d1a46fac6740ea978334cfb5841d365ff7f02..3bce1b3d7e576b1d9e68d32aa45c4335c0f41770 100644 (file)
@@ -160,8 +160,8 @@ pub fn eq_pat(&self, left: &Pat, right: &Pat) -> bool {
             (&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)) => {
index d17ed28cd177c655861cc54b750cefc6eb98dcac..e08a7d3bfdb7d54a35b78bbbc28d925d066a798d 100644 (file)
@@ -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);