From 989f480297cabee936403fd66baa429f2b8ed4ee Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Mon, 1 Oct 2018 23:15:22 +0200 Subject: [PATCH] simplify some unused lints code --- src/librustc_lint/unused.rs | 37 +++++++++++-------------------------- 1 file 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("*");