Skip to content

Labeled break lint collides with unused parens lint #147542

@jacob-greenfield

Description

@jacob-greenfield

This code:

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

Produces the following warning:

warning: this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
 --> src/main.rs:3:9
  |
3 | /         break 'foo {
4 | |             println!("Hello!");
5 | |             123
6 | |         };
  | |_________^
  |
  = note: `#[warn(break_with_label_and_loop)]` on by default
help: wrap this expression in parentheses
  |
3 ~         break 'foo ({
4 |             println!("Hello!");
5 |             123
6 ~         });
  |

But after running cargo fix, the compiler seems to have a change of heart:

warning: unnecessary parentheses around `break` value
 --> src/main.rs:3:20
  |
3 |         break 'foo ({
  |                    ^
...
6 |         });
  |          ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
3 ~         break 'foo {
4 |             println!("Hello!");
5 |             123
6 ~         };
  |

In fact, you can run cargo fix over and over, and it will add, remove, add, remove the parentheses back and forth 😄

Probably one of the two lints should be disabled here... I'm leaning towards unused_parens being the problem, since it seems break_with_label_and_loop is specifically designed to suggest parentheses for this exact kind of expression.

Meta

rustc --version --verbose:

rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: aarch64-apple-darwin
release: 1.90.0
LLVM version: 20.1.8

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.L-break_with_label_and_loopLint: break_with_label_and_loopL-unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions