Skip to content

Commit

Permalink
Merge pull request #1811 from dtolnay/confusablejump
Browse files Browse the repository at this point in the history
Tweak block confusable logic inside of jumps
  • Loading branch information
dtolnay authored Dec 29, 2024
2 parents ee76c9e + c811b33 commit 1a85848
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub(crate) fn confusable_with_adjacent_block(expr: &Expr) -> bool {
matches!(**value, Expr::Block(_))
|| confusable(value, true, rightmost_subexpression)
} else {
false
jump && rightmost_subexpression
}
}
Expr::Call(e) => confusable(&e.func, jump, false),
Expand All @@ -108,7 +108,7 @@ pub(crate) fn confusable_with_adjacent_block(expr: &Expr) -> bool {
matches!(**end, Expr::Block(_))
|| confusable(end, jump, rightmost_subexpression)
}
None => false,
None => jump && rightmost_subexpression,
})
}
Expr::RawAddr(e) => confusable(&e.expr, jump, rightmost_subexpression),
Expand All @@ -117,7 +117,7 @@ pub(crate) fn confusable_with_adjacent_block(expr: &Expr) -> bool {
Some(expr) => confusable(expr, true, rightmost_subexpression),
None => rightmost_subexpression,
},
Expr::Struct(_) => !jump,
Expr::Struct(_) => !jump || rightmost_subexpression,
Expr::Try(e) => confusable(&e.expr, jump, false),
Expr::Unary(e) => confusable(&e.expr, jump, rightmost_subexpression),
Expr::Yield(e) => match &e.expr {
Expand Down
3 changes: 3 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,9 @@ fn test_fixup() {
quote! { a + (|| b) + c },
quote! { if let _ = ((break) - 1 || true) {} },
quote! { if let _ = (break + 1 || true) {} },
quote! { if (break break) {} },
quote! { if (return ..) {} },
quote! { if (|| Struct {}) {} },
quote! { (break)() },
quote! { (..) = () },
quote! { (..) += () },
Expand Down

0 comments on commit 1a85848

Please sign in to comment.