Skip to content

Commit a49246a

Browse files
authored
Rollup merge of #147546 - chenyukang:yukang-fix-break-label-147542, r=jackh726
Suppress unused_parens for labeled break Fixes#147542
2 parents 428be2f + d658bcf commit a49246a

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ check-pass
2+
3+
// Regression test for #147542
4+
// Ensures that we don't suggest removing parens in a break with label and loop
5+
// when the parens are necessary for correct parsing.
6+
7+
#![warn(unused_parens)]
8+
#![warn(break_with_label_and_loop)]
9+
10+
fnxyz() -> usize{
11+
'foo:{
12+
// parens bellow are necessary break of break with label and loop
13+
break'foo ({
14+
println!("Hello!");
15+
123
16+
});
17+
}
18+
}
19+
20+
fnmain(){
21+
xyz();
22+
}

0 commit comments

Comments
 (0)