From a892a96eeb6bb0b485dc3d4a436612a77ead5c40 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 27 May 2016 14:24:28 +0200 Subject: [PATCH] Rustup to *1.10.0-nightly (7bddce693 2016-05-27)* --- clippy_lints/src/copies.rs | 5 ++-- clippy_lints/src/format.rs | 2 +- clippy_lints/src/loops.rs | 4 ++-- clippy_lints/src/matches.rs | 3 +-- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/unused_label.rs | 2 +- clippy_lints/src/utils/hir.rs | 14 +++++------ clippy_lints/src/utils/mod.rs | 2 +- tests/compile-fail/copies.rs | 41 ++++++++++++++++++++++++++++++++ 9 files changed, 57 insertions(+), 18 deletions(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 4344ba461..3873e82b6 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -187,7 +187,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap bindings_impl(cx, pat, map), - PatKind::TupleStruct(_, Some(ref pats)) => { + PatKind::TupleStruct(_, ref pats, _) => { for pat in pats { bindings_impl(cx, pat, map); } @@ -205,7 +205,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap { + PatKind::Tuple(ref fields, _) => { for pat in fields { bindings_impl(cx, pat, map); } @@ -221,7 +221,6 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap bool { let ExprMatch(_, ref arms, _) = expr.node, arms.len() == 1, arms[0].pats.len() == 1, - let PatKind::Tup(ref pat) = arms[0].pats[0].node, + let PatKind::Tuple(ref pat, None) = arms[0].pats[0].node, pat.len() == 1, let ExprVec(ref exprs) = arms[0].body.node, exprs.len() == 1, diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 061b8efaa..c7f34d338 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -280,7 +280,7 @@ impl LateLintPass for LoopsPass { } if let ExprMatch(ref match_expr, ref arms, MatchSource::WhileLetDesugar) = expr.node { let pat = &arms[0].pats[0].node; - if let (&PatKind::TupleStruct(ref path, Some(ref pat_args)), + if let (&PatKind::TupleStruct(ref path, ref pat_args, _), &ExprMethodCall(method_name, _, ref method_args)) = (pat, &match_expr.node) { let iter_expr = &method_args[0]; if let Some(lhs_constructor) = path.segments.last() { @@ -575,7 +575,7 @@ fn check_for_loop_explicit_counter(cx: &LateContext, arg: &Expr, body: &Expr, ex /// Check for the `FOR_KV_MAP` lint. fn check_for_loop_over_map_kv(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &Expr) { - if let PatKind::Tup(ref pat) = pat.node { + if let PatKind::Tuple(ref pat, _) = pat.node { if pat.len() == 2 { let (pat_span, kind) = match (&pat[0].node, &pat[1].node) { (key, _) if pat_is_wild(key, body) => (&pat[1].span, "values"), diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index db4ccf2dc..ad3b958f5 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -193,14 +193,13 @@ fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: (&paths::RESULT, "Ok")]; let path = match arms[1].pats[0].node { - PatKind::TupleStruct(ref path, Some(ref inner)) => { + PatKind::TupleStruct(ref path, ref inner, _) => { // contains any non wildcard patterns? e.g. Err(err) if inner.iter().any(|pat| pat.node != PatKind::Wild) { return; } path.to_string() } - PatKind::TupleStruct(ref path, None) => path.to_string(), PatKind::Ident(BindByValue(MutImmutable), ident, None) => ident.node.to_string(), _ => return, }; diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 2a0d36a80..bdaef590d 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -161,7 +161,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span, bind } } } - PatKind::Tup(ref inner) => { + PatKind::Tuple(ref inner, _) => { if let Some(ref init_tup) = *init { if let ExprTup(ref tup) = init_tup.node { for (i, p) in inner.iter().enumerate() { diff --git a/clippy_lints/src/unused_label.rs b/clippy_lints/src/unused_label.rs index d408f16a3..6539b835d 100644 --- a/clippy_lints/src/unused_label.rs +++ b/clippy_lints/src/unused_label.rs @@ -68,7 +68,7 @@ impl<'v> Visitor<'v> for UnusedLabelVisitor { self.labels.remove(&label.node.as_str()); } hir::ExprLoop(_, Some(label)) | hir::ExprWhile(_, _, Some(label)) => { - self.labels.insert(label.as_str(), expr.span); + self.labels.insert(label.node.as_str(), expr.span); } _ => (), } diff --git a/clippy_lints/src/utils/hir.rs b/clippy_lints/src/utils/hir.rs index 0f0a7312e..92b14b651 100644 --- a/clippy_lints/src/utils/hir.rs +++ b/clippy_lints/src/utils/hir.rs @@ -95,7 +95,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { } (&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node, (&ExprLoop(ref lb, ref ll), &ExprLoop(ref rb, ref rl)) => { - self.eq_block(lb, rb) && both(ll, rl, |l, r| l.as_str() == r.as_str()) + self.eq_block(lb, rb) && both(ll, rl, |l, r| l.node.as_str() == r.node.as_str()) } (&ExprMatch(ref le, ref la, ref ls), &ExprMatch(ref re, ref ra, ref rs)) => { ls == rs && self.eq_expr(le, re) && @@ -124,7 +124,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { (&ExprUnary(l_op, ref le), &ExprUnary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re), (&ExprVec(ref l), &ExprVec(ref r)) => self.eq_exprs(l, r), (&ExprWhile(ref lc, ref lb, ref ll), &ExprWhile(ref rc, ref rb, ref rl)) => { - self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.as_str() == r.as_str()) + self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.node.as_str() == r.node.as_str()) } _ => false, } @@ -142,8 +142,8 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { pub fn eq_pat(&self, left: &Pat, right: &Pat) -> bool { match (&left.node, &right.node) { (&PatKind::Box(ref l), &PatKind::Box(ref r)) => self.eq_pat(l, r), - (&PatKind::TupleStruct(ref lp, ref la), &PatKind::TupleStruct(ref rp, ref ra)) => { - self.eq_path(lp, rp) && both(la, ra, |l, r| over(l, r, |l, r| self.eq_pat(l, r))) + (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => { + self.eq_path(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs } (&PatKind::Ident(ref lb, ref li, ref lp), &PatKind::Ident(ref rb, ref ri, ref rp)) => { lb == rb && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r)) @@ -152,7 +152,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { (&PatKind::QPath(ref ls, ref lp), &PatKind::QPath(ref rs, ref rp)) => { self.eq_qself(ls, rs) && self.eq_path(lp, rp) } - (&PatKind::Tup(ref l), &PatKind::Tup(ref r)) => over(l, r, |l, r| self.eq_pat(l, r)), + (&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) } @@ -374,7 +374,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { c.hash(&mut self.s); self.hash_block(b); if let Some(i) = *i { - self.hash_name(&i); + self.hash_name(&i.node); } } ExprMatch(ref e, ref arms, ref s) => { @@ -468,7 +468,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { self.hash_expr(cond); self.hash_block(b); if let Some(l) = l { - self.hash_name(&l); + self.hash_name(&l.node); } } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 3ff616762..c1cbd7ffe 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -828,7 +828,7 @@ pub fn recover_for_loop(expr: &Expr) -> Option<(&Pat, &Expr, &Expr)> { let Some(ref loopexpr) = block.expr, let ExprMatch(_, ref innerarms, MatchSource::ForLoopDesugar) = loopexpr.node, innerarms.len() == 2 && innerarms[0].pats.len() == 1, - let PatKind::TupleStruct(_, Some(ref somepats)) = innerarms[0].pats[0].node, + let PatKind::TupleStruct(_, ref somepats, _) = innerarms[0].pats[0].node, somepats.len() == 1 ], { return Some((&somepats[0], diff --git a/tests/compile-fail/copies.rs b/tests/compile-fail/copies.rs index bbdd73dc0..6f3076f77 100644 --- a/tests/compile-fail/copies.rs +++ b/tests/compile-fail/copies.rs @@ -1,4 +1,5 @@ #![feature(plugin, inclusive_range_syntax)] +#![feature(dotdot_in_tuple_patterns)] #![plugin(clippy)] #![allow(dead_code, no_effect, unnecessary_operation)] @@ -129,6 +130,34 @@ fn if_same_then_else() -> Result<&'static str, ()> { if let Some(a) = Some(42) {} } + if true { + if let (1, .., 3) = (1, 2, 3) {} + } + else { //~ERROR this `if` has identical blocks + if let (1, .., 3) = (1, 2, 3) {} + } + + if true { + if let (1, .., 3) = (1, 2, 3) {} + } + else { + if let (.., 3) = (1, 2, 3) {} + } + + if true { + if let (1, .., 3) = (1, 2, 3) {} + } + else { + if let (.., 4) = (1, 2, 3) {} + } + + if true { + if let (1, .., 3) = (1, 2, 3) {} + } + else { + if let (.., 1, 3) = (1, 2, 3) {} + } + if true { if let Some(a) = Some(42) {} } @@ -165,6 +194,18 @@ fn if_same_then_else() -> Result<&'static str, ()> { _ => (), } + match (Some(42), Some(42)) { + (Some(a), ..) => bar(a), + (.., Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies + _ => (), + } + + match (1, 2, 3) { + (1, .., 3) => 42, + (.., 3) => 42, //~ERROR this `match` has identical arm bodies + _ => 0, + }; + match (Some(42), Some("")) { (Some(a), None) => bar(a), (None, Some(a)) => bar(a), // bindings have different types