]> git.lizzy.rs Git - rust.git/commitdiff
fix
authorManish Goregaokar <manishsmail@gmail.com>
Thu, 13 Aug 2015 14:41:51 +0000 (20:11 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Thu, 13 Aug 2015 16:15:42 +0000 (21:45 +0530)
src/collapsible_if.rs
src/loops.rs
src/misc.rs

index f0f53622c47dbd34c65a18387b4a4c1584578f2e..be34458e0dc87b32a693fd8b232b13dda8c8c2a6 100644 (file)
@@ -45,8 +45,12 @@ fn check_expr_expd(cx: &Context, e: &Expr, info: Option<&ExpnInfo>) {
     if in_macro(cx, info) { return; }
 
     if let ExprIf(ref check, ref then, None) = e.node {
-        if let Some(&Expr{ node: ExprIf(ref check_inner, ref content, None), ..}) =
+        if let Some(&Expr{ node: ExprIf(ref check_inner, ref content, None), span: sp, ..}) =
             single_stmt_of_block(then) {
+                if e.span.expn_id != sp.expn_id {
+                    return;
+                }
+                cx.sess().note(&format!("{:?} -- {:?}", e.span, sp));
                 span_help_and_lint(cx, COLLAPSIBLE_IF, e.span,
                     "this if statement can be collapsed",
                     &format!("try\nif {} && {} {}",
index 937e95970ef20e45a55d3943c1342ec4ed92c26e..74015bdc6beddf676a7645d293aada3104d93912 100644 (file)
@@ -72,13 +72,12 @@ fn check_expr(&mut self, cx: &Context, expr: &Expr) {
 
 /// Recover the essential nodes of a desugared for loop:
 /// `for pat in arg { body }` becomes `(pat, arg, body)`.
-fn recover_for_loop<'a>(expr: &Expr) -> Option<(&Pat, &Expr, &Expr)> {
+fn recover_for_loop(expr: &Expr) -> Option<(&Pat, &Expr, &Expr)> {
     if_let_chain! {
         [
             let ExprMatch(ref iterexpr, ref arms, _) = expr.node,
             let ExprCall(_, ref iterargs) = iterexpr.node,
-            iterargs.len() == 1,
-            arms.len() == 1 && arms[0].guard.is_none(),
+            iterargs.len() == 1 && arms.len() == 1 && arms[0].guard.is_none(),
             let ExprLoop(ref block, _) = arms[0].body.node,
             block.stmts.is_empty(),
             let Some(ref loopexpr) = block.expr,
index 6c9a7d92ce8ce5d7d4a89ebfbec3c69f39ccd20d..7372bfed6c5455f9cca7067d5e4f19fec6a9f644 100644 (file)
@@ -73,7 +73,7 @@ fn get_lints(&self) -> LintArray {
     }
 
     fn check_fn(&mut self, cx: &Context, _: FnKind, decl: &FnDecl, _: &Block, _: Span, _: NodeId) {
-        for ref arg in decl.inputs.iter() {
+        for ref arg in &decl.inputs {
             if let PatIdent(BindByRef(_), _, _) = arg.pat.node {
                 span_lint(cx,
                     TOPLEVEL_REF_ARG,