mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-23 13:13:17 +00:00
Suggest to remove the semicolon of the last stmt in a block
This commit is contained in:
parent
0f69cafc2d
commit
f9c325f5b6
@ -794,6 +794,36 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
|
|||||||
if !args_to_recover.is_empty() {
|
if !args_to_recover.is_empty() {
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
span_lint_and_then(cx, UNIT_ARG, expr.span, "passing a unit value to a function", |db| {
|
span_lint_and_then(cx, UNIT_ARG, expr.span, "passing a unit value to a function", |db| {
|
||||||
|
let mut or = "";
|
||||||
|
args_to_recover
|
||||||
|
.iter()
|
||||||
|
.filter_map(|arg| {
|
||||||
|
if_chain! {
|
||||||
|
if let ExprKind::Block(block, _) = arg.kind;
|
||||||
|
if block.expr.is_none();
|
||||||
|
if let Some(last_stmt) = block.stmts.iter().last();
|
||||||
|
if let StmtKind::Semi(last_expr) = last_stmt.kind;
|
||||||
|
if let Some(snip) = snippet_opt(cx, last_expr.span);
|
||||||
|
then {
|
||||||
|
Some((
|
||||||
|
last_stmt.span,
|
||||||
|
snip,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.for_each(|(span, sugg)| {
|
||||||
|
db.span_suggestion(
|
||||||
|
span,
|
||||||
|
"remove the semicolon from the last statement in the block",
|
||||||
|
sugg,
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
or = "or ";
|
||||||
|
});
|
||||||
let sugg = args_to_recover
|
let sugg = args_to_recover
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
Loading…
Reference in New Issue
Block a user