Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f9c325f

Browse files
committed
Suggest to remove the semicolon of the last stmt in a block
1 parent 0f69caf commit f9c325f

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
@@ -794,6 +794,36 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
794794
if !args_to_recover.is_empty() {
795795
let mut applicability = Applicability::MachineApplicable;
796796
span_lint_and_then(cx, UNIT_ARG, expr.span, "passing a unit value to a function", |db| {
797+
let mut or = "";
798+
args_to_recover
799+
.iter()
800+
.filter_map(|arg| {
801+
if_chain! {
802+
if let ExprKind::Block(block, _) = arg.kind;
803+
if block.expr.is_none();
804+
if let Some(last_stmt) = block.stmts.iter().last();
805+
if let StmtKind::Semi(last_expr) = last_stmt.kind;
806+
if let Some(snip) = snippet_opt(cx, last_expr.span);
807+
then {
808+
Some((
809+
last_stmt.span,
810+
snip,
811+
))
812+
}
813+
else {
814+
None
815+
}
816+
}
817+
})
818+
.for_each(|(span, sugg)| {
819+
db.span_suggestion(
820+
span,
821+
"remove the semicolon from the last statement in the block",
822+
sugg,
823+
Applicability::MaybeIncorrect,
824+
);
825+
or = "or ";
826+
});
797827
let sugg = args_to_recover
798828
.iter()
799829
.enumerate()

0 commit comments

Comments
 (0)