Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,16 @@ trait UnusedDelimLint {
(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)
}

Expand Down
18 changes: 18 additions & 0 deletions tests/ui/lint/break-label-with-parens-147542.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ check-pass

#![warn(unused_parens)]
#![warn(break_with_label_and_loop)]

fn xyz() -> usize {
'foo: {
// parens are necessary
break 'foo ({
println!("Hello!");
123
});
}
}

fn main() {
xyz();
}
Loading