Require parentheses to avoid confusions around labeled break and loop expressions

This commit is contained in:
Fabian Wolff 2021-07-10 16:38:55 +02:00
parent 7069a8c2b7
commit 470cbc0e2e
6 changed files with 152 additions and 21 deletions

View file

@ -750,6 +750,11 @@ pub trait LintContext: Sized {
db.note(&format!("to ignore the value produced by the macro, add a semicolon after the invocation of `{name}`"));
}
}
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);
}
}
}
// Rewrap `db`, and pass control to the user.
decorate(LintDiagnosticBuilder::new(db));