about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-10-04 12:20:07 +0200
committerGitHub <noreply@github.com>2018-10-04 12:20:07 +0200
commitbc4f86909ea5e08a9114c70eef29942a4ea2c459 (patch)
tree4818e26d63304b6921b8aeba3395a9132aead3f2
parent1dbc8b0d4bcdc404bdc2029b6a87972ec92707dc (diff)
parent989f480297cabee936403fd66baa429f2b8ed4ee (diff)
downloadrust-bc4f86909ea5e08a9114c70eef29942a4ea2c459.tar.gz
rust-bc4f86909ea5e08a9114c70eef29942a4ea2c459.zip
Rollup merge of #54746 - llogiq:simplify-unused-lints, r=michaelwoerister
simplify some unused lints code

Those are but small simplifications for readability.
-rw-r--r--src/librustc_lint/unused.rs37
1 files changed, 11 insertions, 26 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs
index 7a9d18676cf..ae178888b6a 100644
--- a/src/librustc_lint/unused.rs
+++ b/src/librustc_lint/unused.rs
@@ -65,9 +65,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
             ty::Adt(def, _) => {
                 if def.variants.is_empty() {
                     return;
-                } else {
-                    check_must_use(cx, def.did, s.span, "")
                 }
+                check_must_use(cx, def.did, s.span, "")
             },
             _ => false,
         };
@@ -337,21 +336,13 @@ impl EarlyLintPass for UnusedParens {
             AssignOp(.., ref value) => (value, "assigned value", false),
             // either function/method call, or something this lint doesn't care about
             ref call_or_other => {
-                let args_to_check;
-                let call_kind;
-                match *call_or_other {
-                    Call(_, ref args) => {
-                        call_kind = "function";
-                        args_to_check = &args[..];
-                    },
-                    MethodCall(_, ref args) => {
-                        call_kind = "method";
-                        // first "argument" is self (which sometimes needs parens)
-                        args_to_check = &args[1..];
-                    }
+                let (args_to_check, call_kind) = match *call_or_other {
+                    Call(_, ref args) => (&args[..], "function"),
+                    // first "argument" is self (which sometimes needs parens)
+                    MethodCall(_, ref args) => (&args[1..], "method"),
                     // actual catch-all arm
                     _ => { return; }
-                }
+                };
                 // Don't lint if this is a nested macro expansion: otherwise, the lint could
                 // trigger in situations that macro authors shouldn't have to care about, e.g.,
                 // when a parenthesized token tree matched in one macro expansion is matched as
@@ -372,16 +363,11 @@ impl EarlyLintPass for UnusedParens {
     }
 
     fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {
-        let (value, msg) = match s.node {
-            ast::StmtKind::Local(ref local) => {
-                match local.init {
-                    Some(ref value) => (value, "assigned value"),
-                    None => return,
-                }
+        if let ast::StmtKind::Local(ref local) = s.node {
+            if let Some(ref value) = local.init {
+                self.check_unused_parens_core(cx, &value, "assigned value", false);
             }
-            _ => return,
-        };
-        self.check_unused_parens_core(cx, &value, msg, false);
+        }
     }
 }
 
@@ -414,9 +400,8 @@ impl UnusedImportBraces {
                     let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
                     if orig_ident.name == keywords::SelfValue.name() {
                         return;
-                    } else {
-                        node_ident = rename.unwrap_or(orig_ident);
                     }
+                    node_ident = rename.unwrap_or(orig_ident);
                 }
                 ast::UseTreeKind::Glob => {
                     node_ident = ast::Ident::from_str("*");