Skip to content

Commit fad122e

Browse files
committed
Suggest to remove the semicolon of the last stmt in a block
1 parent 540a0d6 commit fad122e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

clippy_lints/src/types.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,36 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
675675
if !args_to_recover.is_empty() {
676676
let mut applicability = Applicability::MachineApplicable;
677677
span_lint_and_then(cx, UNIT_ARG, expr.span, "passing a unit value to a function", |db| {
678+
let mut or = "";
679+
args_to_recover
680+
.iter()
681+
.filter_map(|arg| {
682+
if_chain! {
683+
if let ExprKind::Block(block, _) = arg.kind;
684+
if block.expr.is_none();
685+
if let Some(last_stmt) = block.stmts.iter().last();
686+
if let StmtKind::Semi(last_expr) = last_stmt.kind;
687+
if let Some(snip) = snippet_opt(cx, last_expr.span);
688+
then {
689+
Some((
690+
last_stmt.span,
691+
snip,
692+
))
693+
}
694+
else {
695+
None
696+
}
697+
}
698+
})
699+
.for_each(|(span, sugg)| {
700+
db.span_suggestion(
701+
span,
702+
"remove the semicolon from the last statement in the block",
703+
sugg,
704+
Applicability::MaybeIncorrect,
705+
);
706+
or = "or ";
707+
});
678708
let sugg = args_to_recover
679709
.iter()
680710
.enumerate()

0 commit comments

Comments
 (0)