Use a multipart suggestion for the parentheses
This commit is contained in:
parent
470cbc0e2e
commit
7c81132a60
2 changed files with 11 additions and 6 deletions
|
@ -751,9 +751,12 @@ pub trait LintContext: Sized {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BuiltinLintDiagnostics::BreakWithLabelAndLoop(span) => {
|
BuiltinLintDiagnostics::BreakWithLabelAndLoop(span) => {
|
||||||
if let Ok(code) = sess.source_map().span_to_snippet(span) {
|
db.multipart_suggestion(
|
||||||
db.span_suggestion(span, "wrap this expression in parentheses", format!("({})", &code), Applicability::MachineApplicable);
|
"wrap this expression in parentheses",
|
||||||
}
|
vec![(span.shrink_to_lo(), "(".to_string()),
|
||||||
|
(span.shrink_to_hi(), ")".to_string())],
|
||||||
|
Applicability::MachineApplicable
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Rewrap `db`, and pass control to the user.
|
// Rewrap `db`, and pass control to the user.
|
||||||
|
|
|
@ -35,11 +35,13 @@ warning: this labeled break expression is easy to confuse with an unlabeled brea
|
||||||
LL | / break 'label
|
LL | / break 'label
|
||||||
LL | |
|
LL | |
|
||||||
LL | | loop { break 42; };
|
LL | | loop { break 42; };
|
||||||
| |_____________-----------------^
|
| |______________________________^
|
||||||
| |
|
|
||||||
| help: wrap this expression in parentheses: `(loop { break 42; })`
|
|
||||||
|
|
|
|
||||||
= note: `#[warn(break_with_label_and_loop)]` on by default
|
= note: `#[warn(break_with_label_and_loop)]` on by default
|
||||||
|
help: wrap this expression in parentheses
|
||||||
|
|
|
||||||
|
LL | (loop { break 42; });
|
||||||
|
| ^ ^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors; 1 warning emitted
|
error: aborting due to 2 previous errors; 1 warning emitted
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue