Skip to content

Commit

Permalink
simplify some unused lints code
Browse files Browse the repository at this point in the history
  • Loading branch information
llogiq committed Oct 3, 2018
1 parent de3d640 commit 989f480
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions src/librustc_lint/unused.rs
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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("*");
Expand Down

0 comments on commit 989f480

Please sign in to comment.