Skip to content

Commit

Permalink
Merge pull request #95 from dtolnay/parseablestmt
Browse files Browse the repository at this point in the history
Fix some parseable_as_stmt edge cases
  • Loading branch information
dtolnay authored Jan 12, 2025
2 parents f2117b8 + d6d8424 commit 4d65c3c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,6 @@ fn parseable_as_stmt(mut expr: &Expr) -> bool {
| Expr::ForLoop(_)
| Expr::If(_)
| Expr::Infer(_)
| Expr::Let(_)
| Expr::Lit(_)
| Expr::Loop(_)
| Expr::Macro(_)
Expand All @@ -1422,30 +1421,37 @@ fn parseable_as_stmt(mut expr: &Expr) -> bool {
| Expr::While(_)
| Expr::Yield(_) => return true,

Expr::Assign(e) => expr = &e.left,
Expr::Let(_) => return false,

Expr::Assign(e) => {
if !classify::requires_semi_to_be_stmt(&e.left) {
return false;
}
expr = &e.left;
}
Expr::Await(e) => expr = &e.base,
Expr::Binary(e) => {
if !classify::requires_comma_to_be_match_arm(&e.left) {
if !classify::requires_semi_to_be_stmt(&e.left) {
return false;
}
expr = &e.left;
}
Expr::Call(e) => {
if !classify::requires_comma_to_be_match_arm(&e.func) {
if !classify::requires_semi_to_be_stmt(&e.func) {
return false;
}
expr = &e.func;
}
Expr::Cast(e) => {
if !classify::requires_comma_to_be_match_arm(&e.expr) {
if !classify::requires_semi_to_be_stmt(&e.expr) {
return false;
}
expr = &e.expr;
}
Expr::Field(e) => expr = &e.base,
Expr::Group(e) => expr = &e.expr,
Expr::Index(e) => {
if !classify::requires_comma_to_be_match_arm(&e.expr) {
if !classify::requires_semi_to_be_stmt(&e.expr) {
return false;
}
expr = &e.expr;
Expand All @@ -1454,7 +1460,7 @@ fn parseable_as_stmt(mut expr: &Expr) -> bool {
Expr::Range(e) => match &e.start {
None => return true,
Some(start) => {
if !classify::requires_comma_to_be_match_arm(start) {
if !classify::requires_semi_to_be_stmt(start) {
return false;
}
expr = start;
Expand Down

0 comments on commit 4d65c3c

Please sign in to comment.