Fix false positive in unused_parens caused by break

This commit is contained in:
yukang 2026-01-29 17:20:32 +08:00
parent ba284f468c
commit 4803644df9
2 changed files with 29 additions and 1 deletions

View file

@ -794,7 +794,10 @@ trait UnusedDelimLint {
ExprKind::Break(_label, None) => return false,
ExprKind::Break(_label, Some(break_expr)) => {
return matches!(break_expr.kind, ExprKind::Block(..));
// `if (break 'label i) { ... }` removing parens would make `i { ... }`
// be parsed as a struct literal, so keep parentheses if the break value
// ends with a path (which could be mistaken for a struct name).
return matches!(break_expr.kind, ExprKind::Block(..) | ExprKind::Path(..));
}
ExprKind::Range(_lhs, Some(rhs), _limits) => {