Skip to content

Commit edd099c

Browse files
committed
[semicolon_if_nothing_returned]: add an autofix
1 parent 2b03bb0 commit edd099c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

clippy_lints/src/semicolon_if_nothing_returned.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::rustc_lint::LintContext;
2-
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::source::snippet_with_context;
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
@@ -33,7 +33,6 @@ declare_clippy_lint! {
3333
pedantic,
3434
"add a semicolon if nothing is returned"
3535
}
36-
3736
declare_lint_pass!(SemicolonIfNothingReturned => [SEMICOLON_IF_NOTHING_RETURNED]);
3837

3938
impl<'tcx> LateLintPass<'tcx> for SemicolonIfNothingReturned {
@@ -52,14 +51,19 @@ impl<'tcx> LateLintPass<'tcx> for SemicolonIfNothingReturned {
5251
if let ExprKind::DropTemps(..) = &expr.kind {
5352
return;
5453
}
55-
span_lint_and_sugg(
54+
span_lint_and_then(
5655
cx,
5756
SEMICOLON_IF_NOTHING_RETURNED,
5857
expr.span.source_callsite(),
5958
"consider adding a `;` to the last statement for consistent formatting",
60-
"add a `;` here",
61-
format!("{snippet};"),
62-
app,
59+
|diag| {
60+
diag.span_suggestion(
61+
expr.span,
62+
"add a `;` here",
63+
format!("{snippet};"),
64+
Applicability::MachineApplicable,
65+
);
66+
}
6367
);
6468
}
6569
}

0 commit comments

Comments
 (0)