diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c0766fe21b..0ca049007a64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.155 +* Update to *rustc 1.21.0-nightly (c11f689d2 2017-08-29)* +* New lint: [`infinite_iter`], [`maybe_infinite_iter`], [`cast_lossless`] ## 0.0.154 * Update to *rustc 1.21.0-nightly (2c0558f63 2017-08-24)* diff --git a/Cargo.toml b/Cargo.toml index 914d453ebf84..6ecfa3dfe500 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.154" +version = "0.0.155" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -31,7 +31,7 @@ path = "src/main.rs" [dependencies] # begin automatic update -clippy_lints = { version = "0.0.154", path = "clippy_lints" } +clippy_lints = { version = "0.0.155", path = "clippy_lints" } # end automatic update cargo_metadata = "0.2" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 8cdbbaaecf5a..7aae50a47456 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin automatic update -version = "0.0.154" +version = "0.0.155" # end automatic update authors = [ "Manish Goregaokar ", diff --git a/clippy_lints/src/block_in_if_condition.rs b/clippy_lints/src/block_in_if_condition.rs index eea44393e3d2..82a3eb00ab7f 100644 --- a/clippy_lints/src/block_in_if_condition.rs +++ b/clippy_lints/src/block_in_if_condition.rs @@ -56,7 +56,7 @@ struct ExVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx: 'a> Visitor<'tcx> for ExVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr) { - if let ExprClosure(_, _, eid, _) = expr.node { + if let ExprClosure(_, _, eid, _, _) = expr.node { let body = self.cx.tcx.hir.body(eid); let ex = &body.value; if matches!(ex.node, ExprBlock(_)) { diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index cbd0c6d20d50..a3a53b6dd47c 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { let ExprMethodCall(ref filter, _, ref filter_args) = count_args[0].node, filter.name == "filter", filter_args.len() == 2, - let ExprClosure(_, _, body_id, _) = filter_args[1].node, + let ExprClosure(_, _, body_id, _, _) = filter_args[1].node, ], { let body = cx.tcx.hir.body(body_id); if_let_chain!([ diff --git a/clippy_lints/src/cyclomatic_complexity.rs b/clippy_lints/src/cyclomatic_complexity.rs index 9596e9812adb..edfa5e0fb611 100644 --- a/clippy_lints/src/cyclomatic_complexity.rs +++ b/clippy_lints/src/cyclomatic_complexity.rs @@ -171,7 +171,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CCHelper<'a, 'tcx> { _ => (), } }, - ExprClosure(..) => (), + ExprClosure(.., _) => (), ExprBinary(op, _, _) => { walk_expr(self, e); match op.node { diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index b5667db920cd..42524da7ffc4 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -49,7 +49,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaPass { } fn check_closure(cx: &LateContext, expr: &Expr) { - if let ExprClosure(_, ref decl, eid, _) = expr.node { + if let ExprClosure(_, ref decl, eid, _, _) = expr.node { let body = cx.tcx.hir.body(eid); let ex = &body.value; if let ExprCall(ref caller, ref args) = ex.node { diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 549b621812d4..db952cd5d988 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -104,7 +104,7 @@ struct DivergenceVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { fn maybe_walk_expr(&mut self, e: &'tcx Expr) { match e.node { - ExprClosure(..) => {}, + ExprClosure(.., _) => {}, ExprMatch(ref e, ref arms, _) => { self.visit_expr(e); for arm in arms { @@ -239,7 +239,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St walk_expr(vis, expr); } }, - ExprClosure(_, _, _, _) => { + ExprClosure(_, _, _, _, _) => { // Either // // * `var` is defined in the closure body, in which case we've @@ -323,7 +323,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { // We're about to descend a closure. Since we don't know when (or // if) the closure will be evaluated, any reads in it might not // occur here (or ever). Like above, bail to avoid false positives. - ExprClosure(_, _, _, _) | + ExprClosure(_, _, _, _, _) | // We want to avoid a false positive when a variable name occurs // only to have its address taken, so we stop here. Technically, diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 72ff75dd9948..53f74c7afd63 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -148,7 +148,7 @@ fn is_infinite(cx: &LateContext, expr: &Expr) -> Finiteness { } } if method.name == "flat_map" && args.len() == 2 { - if let ExprClosure(_, _, body_id, _) = args[1].node { + if let ExprClosure(_, _, body_id, _, _) = args[1].node { let body = cx.tcx.hir.body(body_id); return is_infinite(cx, &body.value); } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index fcb84e90eb60..f0e19a3b5777 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -31,7 +31,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if let ExprMethodCall(ref method, _, ref args) = expr.node { if method.name == "map" && args.len() == 2 { match args[1].node { - ExprClosure(_, ref decl, closure_eid, _) => { + ExprClosure(_, ref decl, closure_eid, _, _) => { let body = cx.tcx.hir.body(closure_eid); let closure_expr = remove_blocks(&body.value); let ty = cx.tables.pat_ty(&body.arguments[0].pat); diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 782b4033645a..971309adb330 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -46,7 +46,7 @@ fn has_no_effect(cx: &LateContext, expr: &Expr) -> bool { } match expr.node { Expr_::ExprLit(..) | - Expr_::ExprClosure(..) | + Expr_::ExprClosure(.., _) | Expr_::ExprPath(..) => true, Expr_::ExprIndex(ref a, ref b) | Expr_::ExprBinary(_, ref a, ref b) => has_no_effect(cx, a) && has_no_effect(cx, b), diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index ba8f0022b32b..dfac7366553c 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -296,10 +296,16 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { println!("Match(ref expr, ref arms, ref desugaring) = {},", current); println!(" // unimplemented: `ExprMatch` is not further destructured at the moment"); }, - Expr_::ExprClosure(ref _capture_clause, ref _func, _, _) => { - println!("Closure(ref capture_clause, ref func, _, _) = {},", current); + Expr_::ExprClosure(ref _capture_clause, ref _func, _, _, _) => { + println!("Closure(ref capture_clause, ref func, _, _, _) = {},", current); println!(" // unimplemented: `ExprClosure` is not further destructured at the moment"); }, + Expr_::ExprYield(ref sub) => { + let sub_pat = self.next("sub"); + println!("Yield(ref sub) = {},", current); + self.current = sub_pat; + self.visit_expr(sub); + }, Expr_::ExprBlock(ref block) => { let block_pat = self.next("block"); println!("Block(ref {}) = {},", block_pat, current); diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 4890bb81dc3b..2a4439c4608b 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -321,6 +321,11 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { self.hash_name(&i.node.name); } }, + ExprYield(ref e) => { + let c: fn(_) -> _ = ExprYield; + c.hash(&mut self.s); + self.hash_expr(e); + }, ExprAssign(ref l, ref r) => { let c: fn(_, _) -> _ = ExprAssign; c.hash(&mut self.s); @@ -373,8 +378,8 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { self.hash_expr(e); // TODO: _ty }, - ExprClosure(cap, _, eid, _) => { - let c: fn(_, _, _, _) -> _ = ExprClosure; + ExprClosure(cap, _, eid, _, _) => { + let c: fn(_, _, _, _, _) -> _ = ExprClosure; c.hash(&mut self.s); cap.hash(&mut self.s); self.hash_expr(&self.cx.tcx.hir.body(eid).value); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 7b06190b2dbe..081b7ac277a0 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -245,10 +245,14 @@ fn print_expr(cx: &LateContext, expr: &hir::Expr, indent: usize) { print_expr(cx, cond, indent + 1); println!("{}source: {:?}", ind, source); }, - hir::ExprClosure(ref clause, _, _, _) => { + hir::ExprClosure(ref clause, _, _, _, _) => { println!("{}Closure", ind); println!("{}clause: {:?}", ind, clause); }, + hir::ExprYield(ref sub) => { + println!("{}Yield", ind); + print_expr(cx, sub, indent + 1); + } hir::ExprBlock(_) => { println!("{}Block", ind); }, diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index c08f7d4254fe..9b14dd125ba8 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -104,6 +104,7 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool { pub fn in_constant(cx: &LateContext, id: NodeId) -> bool { let parent_id = cx.tcx.hir.get_parent(id); match MirSource::from_node(cx.tcx, parent_id) { + MirSource::GeneratorDrop(_) | MirSource::Fn(_) => false, MirSource::Const(_) | MirSource::Static(..) | diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 6cfbe8c935e0..1c2e07960cbd 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -49,11 +49,12 @@ impl<'a> Sugg<'a> { match expr.node { hir::ExprAddrOf(..) | hir::ExprBox(..) | - hir::ExprClosure(..) | + hir::ExprClosure(.., _) | hir::ExprIf(..) | hir::ExprUnary(..) | hir::ExprMatch(..) => Sugg::MaybeParen(snippet), hir::ExprAgain(..) | + hir::ExprYield(..) | hir::ExprArray(..) | hir::ExprBlock(..) | hir::ExprBreak(..) | @@ -106,6 +107,7 @@ impl<'a> Sugg<'a> { ast::ExprKind::Call(..) | ast::ExprKind::Catch(..) | ast::ExprKind::Continue(..) | + ast::ExprKind::Yield(..) | ast::ExprKind::Field(..) | ast::ExprKind::ForLoop(..) | ast::ExprKind::Index(..) |