Skip to content

Commit

Permalink
Merge pull request #1829 from dtolnay/ifbreakbreak
Browse files Browse the repository at this point in the history
Fix classification of nested breaks/ranges inside condition
  • Loading branch information
dtolnay authored Jan 1, 2025
2 parents 9dd90b7 + 4d1f6c0 commit 6187a08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(crate) fn confusable_with_adjacent_block(expr: &Expr) -> bool {
}
Expr::Break(e) => {
if let Some(value) = &e.expr {
confusable(value, true, true, rightmost_subexpression)
confusable(value, true, !allow_struct, rightmost_subexpression)
} else {
allow_struct && rightmost_subexpression
}
Expand Down Expand Up @@ -157,7 +157,9 @@ pub(crate) fn confusable_with_adjacent_block(expr: &Expr) -> bool {
}
None => false,
} || match &e.end {
Some(end) => confusable(end, allow_struct, true, rightmost_subexpression),
Some(end) => {
confusable(end, allow_struct, !allow_struct, rightmost_subexpression)
}
None => allow_struct && rightmost_subexpression,
})
}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,9 @@ fn test_fixup() {
quote! { if let _ = ((break) - 1 || true) {} },
quote! { if let _ = (break + 1 || true) {} },
quote! { if (break break) {} },
quote! { if break break {} {} },
quote! { if (return ..) {} },
quote! { if return .. {} {} },
quote! { if (|| Struct {}) {} },
quote! { if (|| Struct {}.await) {} },
quote! { if break || Struct {}.await {} },
Expand Down

0 comments on commit 6187a08

Please sign in to comment.