diff options
| author | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-08-03 21:23:29 +0200 |
|---|---|---|
| committer | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-08-03 21:23:29 +0200 |
| commit | 7c81132a60579de56bd4baa7866fa9db2ecd5ddd (patch) | |
| tree | d7cbe68e459e0cd624cf22ead7f01075cfdec8ad | |
| parent | 470cbc0e2eb52c2b80ba6940b6446aecb20f9b04 (diff) | |
| download | rust-7c81132a60579de56bd4baa7866fa9db2ecd5ddd.tar.gz rust-7c81132a60579de56bd4baa7866fa9db2ecd5ddd.zip | |
Use a multipart suggestion for the parentheses
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/parser/lifetime_starts_expressions.stderr | 8 |
2 files changed, 11 insertions, 6 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index a20ceacdd3a..4a646013ff8 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -751,9 +751,12 @@ pub trait LintContext: Sized { } } BuiltinLintDiagnostics::BreakWithLabelAndLoop(span) => { - if let Ok(code) = sess.source_map().span_to_snippet(span) { - db.span_suggestion(span, "wrap this expression in parentheses", format!("({})", &code), Applicability::MachineApplicable); - } + db.multipart_suggestion( + "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. diff --git a/src/test/ui/parser/lifetime_starts_expressions.stderr b/src/test/ui/parser/lifetime_starts_expressions.stderr index 3af2c6b9e57..6f3320e283c 100644 --- a/src/test/ui/parser/lifetime_starts_expressions.stderr +++ b/src/test/ui/parser/lifetime_starts_expressions.stderr @@ -35,11 +35,13 @@ warning: this labeled break expression is easy to confuse with an unlabeled brea LL | / break 'label LL | | LL | | loop { break 42; }; - | |_____________-----------------^ - | | - | help: wrap this expression in parentheses: `(loop { break 42; })` + | |______________________________^ | = 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 |
