Suppress unused_parens for labeled break
This commit is contained in:
@@ -914,7 +914,16 @@ trait UnusedDelimLint {
|
|||||||
(value, UnusedDelimsCtx::ReturnValue, false, Some(left), None, true)
|
(value, UnusedDelimsCtx::ReturnValue, false, Some(left), None, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
Break(_, Some(ref value)) => {
|
Break(label, Some(ref value)) => {
|
||||||
|
// Don't lint on `break 'label ({...})` - the parens are necessary
|
||||||
|
// to disambiguate from `break 'label {...}` which would be a syntax error.
|
||||||
|
// This avoids conflicts with the `break_with_label_and_loop` lint.
|
||||||
|
if label.is_some()
|
||||||
|
&& matches!(value.kind, ast::ExprKind::Paren(ref inner)
|
||||||
|
if matches!(inner.kind, ast::ExprKind::Block(..)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
(value, UnusedDelimsCtx::BreakValue, false, None, None, true)
|
(value, UnusedDelimsCtx::BreakValue, false, None, None, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
tests/ui/lint/unused/break-label-with-parens-147542.rs
Normal file
22
tests/ui/lint/unused/break-label-with-parens-147542.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
// Regression test for #147542
|
||||||
|
// Ensures that we don't suggest removing parens in a break with label and loop
|
||||||
|
// when the parens are necessary for correct parsing.
|
||||||
|
|
||||||
|
#![warn(unused_parens)]
|
||||||
|
#![warn(break_with_label_and_loop)]
|
||||||
|
|
||||||
|
fn xyz() -> usize {
|
||||||
|
'foo: {
|
||||||
|
// parens bellow are necessary break of break with label and loop
|
||||||
|
break 'foo ({
|
||||||
|
println!("Hello!");
|
||||||
|
123
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
xyz();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user