]> git.lizzy.rs Git - rust.git/commitdiff
More initial work
authorZaki Manian <zaki@manian.org>
Sat, 2 Sep 2017 21:09:41 +0000 (14:09 -0700)
committerZaki Manian <zaki@manian.org>
Sat, 2 Sep 2017 21:09:41 +0000 (14:09 -0700)
clippy_lints/src/is_unit_expr.rs

index b8c85813d3f9344c6d71356bc15f19786c7a719d..07991082872cef5f7a956052b743fc39717d5c55 100644 (file)
@@ -35,19 +35,55 @@ fn get_lints(&self) -> LintArray {
 impl EarlyLintPass for UnitExpr {
     fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
         if let ExprKind::Assign(ref left, ref right) = expr.node {
-            unimplemented!();
-        }
-        if let ExprKind::MethodCall(ref path, ref args) = expr.node {
-            unimplemented!();
-        }
-        if let ExprKind::Call(ref path, ref args) = expr.node{
-            unimplemented!();
+            if is_unit_expr(right){
+                span_lint_and_sugg(
+                    cx,
+                    UNIT_EXPR,
+                    right.span,
+                    "trailing semicolons can be tricky",
+                    "remove the last semicolon",
+                    "TODO".to_owned()
+                )
+            }
         }
+        // if let ExprKind::MethodCall(ref path, ref args) = expr.node {
+        //     unimplemented!();
+        // }
+        // if let ExprKind::Call(ref path, ref args) = expr.node{
+        //     unimplemented!();
+        // }
     }
 
     fn check_stmt(&mut self, cx: &EarlyContext, stmt: &Stmt) {
-        if let StmtKind::Local(ref data) = stmt.node{
-            unimplemented!();
-        }
+        if let StmtKind::Local(ref local) = stmt.node{
+            if local.pat.node == PatKind::Wild {return;}
+            if let Some(ref expr) = local.init{
+                if is_unit_expr(expr){
+                    span_lint_and_sugg(
+                        cx,
+                        UNIT_EXPR,
+                        local.span,
+                        "trailing semicolons can be tricky",
+                        "remove the last semicolon",
+                        "TODO".to_owned()
+                    )
+                }
+            }        
+            }
     }
 }
+
+fn is_unit_expr(expr: &Expr)->bool{
+    match expr.node{
+         ExprKind::Block(ref next) => {
+            let ref final_stmt = &next.stmts[next.stmts.len()-1];
+            if let StmtKind::Expr(_) = final_stmt.node{
+                return false;
+            }
+            else{
+                return true;
+            }
+        },
+        _ => return false,
+    }
+}
\ No newline at end of file