Skip to content

Commit c5f410e

Browse files
committed
Suppress unused_parens for labeled break
1 parent 9725c4b commit c5f410e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,16 @@ trait UnusedDelimLint {
914914
(value, UnusedDelimsCtx::ReturnValue, false, Some(left), None, true)
915915
}
916916

917-
Break(_, Some(ref value)) => {
917+
Break(label, Some(ref value)) => {
918+
// Don't lint on `break 'label ({...})` - the parens are necessary
919+
// to disambiguate from `break 'label {...}` which would be a syntax error.
920+
// This avoids conflicts with the `break_with_label_and_loop` lint.
921+
if label.is_some()
922+
&& matches!(value.kind, ast::ExprKind::Paren(ref inner)
923+
if matches!(inner.kind, ast::ExprKind::Block(..)))
924+
{
925+
return;
926+
}
918927
(value, UnusedDelimsCtx::BreakValue, false, None, None, true)
919928
}
920929

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ check-pass
2+
3+
#![warn(unused_parens)]
4+
#![warn(break_with_label_and_loop)]
5+
6+
fn xyz() -> usize {
7+
'foo: {
8+
// parens are necessary
9+
break 'foo ({
10+
println!("Hello!");
11+
123
12+
});
13+
}
14+
}
15+
16+
fn main() {
17+
xyz();
18+
}

0 commit comments

Comments
 (0)