Skip to content

simplify some unused lints code #54746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 11 additions & 26 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
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