Skip to content

Commit 7c81132

Browse files
committed
Use a multipart suggestion for the parentheses
1 parent 470cbc0 commit 7c81132

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/rustc_lint/src/context.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,12 @@ pub trait LintContext: Sized {
751751
}
752752
}
753753
BuiltinLintDiagnostics::BreakWithLabelAndLoop(span) => {
754-
if let Ok(code) = sess.source_map().span_to_snippet(span) {
755-
db.span_suggestion(span, "wrap this expression in parentheses", format!("({})", &code), Applicability::MachineApplicable);
756-
}
754+
db.multipart_suggestion(
755+
"wrap this expression in parentheses",
756+
vec![(span.shrink_to_lo(), "(".to_string()),
757+
(span.shrink_to_hi(), ")".to_string())],
758+
Applicability::MachineApplicable
759+
);
757760
}
758761
}
759762
// Rewrap `db`, and pass control to the user.

src/test/ui/parser/lifetime_starts_expressions.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ warning: this labeled break expression is easy to confuse with an unlabeled brea
3535
LL | / break 'label
3636
LL | |
3737
LL | | loop { break 42; };
38-
| |_____________-----------------^
39-
| |
40-
| help: wrap this expression in parentheses: `(loop { break 42; })`
38+
| |______________________________^
4139
|
4240
= note: `#[warn(break_with_label_and_loop)]` on by default
41+
help: wrap this expression in parentheses
42+
|
43+
LL | (loop { break 42; });
44+
| ^ ^
4345

4446
error: aborting due to 2 previous errors; 1 warning emitted
4547

0 commit comments

Comments
 (0)