Skip to content

Commit bc4f869

Browse files
authored
Rollup merge of #54746 - llogiq:simplify-unused-lints, r=michaelwoerister
simplify some unused lints code Those are but small simplifications for readability.
2 parents 1dbc8b0 + 989f480 commit bc4f869

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

src/librustc_lint/unused.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
6565
ty::Adt(def, _) => {
6666
if def.variants.is_empty() {
6767
return;
68-
} else {
69-
check_must_use(cx, def.did, s.span, "")
7068
}
69+
check_must_use(cx, def.did, s.span, "")
7170
},
7271
_ => false,
7372
};
@@ -337,21 +336,13 @@ impl EarlyLintPass for UnusedParens {
337336
AssignOp(.., ref value) => (value, "assigned value", false),
338337
// either function/method call, or something this lint doesn't care about
339338
ref call_or_other => {
340-
let args_to_check;
341-
let call_kind;
342-
match *call_or_other {
343-
Call(_, ref args) => {
344-
call_kind = "function";
345-
args_to_check = &args[..];
346-
},
347-
MethodCall(_, ref args) => {
348-
call_kind = "method";
349-
// first "argument" is self (which sometimes needs parens)
350-
args_to_check = &args[1..];
351-
}
339+
let (args_to_check, call_kind) = match *call_or_other {
340+
Call(_, ref args) => (&args[..], "function"),
341+
// first "argument" is self (which sometimes needs parens)
342+
MethodCall(_, ref args) => (&args[1..], "method"),
352343
// actual catch-all arm
353344
_ => { return; }
354-
}
345+
};
355346
// Don't lint if this is a nested macro expansion: otherwise, the lint could
356347
// trigger in situations that macro authors shouldn't have to care about, e.g.,
357348
// when a parenthesized token tree matched in one macro expansion is matched as
@@ -372,16 +363,11 @@ impl EarlyLintPass for UnusedParens {
372363
}
373364

374365
fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {
375-
let (value, msg) = match s.node {
376-
ast::StmtKind::Local(ref local) => {
377-
match local.init {
378-
Some(ref value) => (value, "assigned value"),
379-
None => return,
380-
}
366+
if let ast::StmtKind::Local(ref local) = s.node {
367+
if let Some(ref value) = local.init {
368+
self.check_unused_parens_core(cx, &value, "assigned value", false);
381369
}
382-
_ => return,
383-
};
384-
self.check_unused_parens_core(cx, &value, msg, false);
370+
}
385371
}
386372
}
387373

@@ -414,9 +400,8 @@ impl UnusedImportBraces {
414400
let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
415401
if orig_ident.name == keywords::SelfValue.name() {
416402
return;
417-
} else {
418-
node_ident = rename.unwrap_or(orig_ident);
419403
}
404+
node_ident = rename.unwrap_or(orig_ident);
420405
}
421406
ast::UseTreeKind::Glob => {
422407
node_ident = ast::Ident::from_str("*");

0 commit comments

Comments
 (0)