Commit 7f0acb3
committed
fix: wrap match scrutinee in parens when needed in replace_if_let_with_match
`if (return) {}` caused a panic in `replace_if_let_with_match`:
`let_and_guard` recursed through the `ParenExpr`, producing a bare
`return` as the scrutinee. `make::expr_match` formatted `match return
{ ... }`, which the parser reinterpreted as `match (return { ... })`,
consuming the arm list as the return value. The resulting match expr
had no `MatchArmList`, so the `unwrap()` in `SyntaxFactory::expr_match`
panicked.
Mirror the fix pattern from #22067: build a fake
`match () { }` and ask whether the scrutinee needs parens in that
position via `needs_parens_in_place_of`. Wrap when required.
fixes #220721 parent 26d7ba3 commit 7f0acb3
1 file changed
Lines changed: 36 additions & 0 deletions
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
135 | 140 | | |
136 | 141 | | |
137 | 142 | | |
| |||
419 | 424 | | |
420 | 425 | | |
421 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
422 | 438 | | |
423 | 439 | | |
424 | 440 | | |
| |||
447 | 463 | | |
448 | 464 | | |
449 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
450 | 486 | | |
451 | 487 | | |
452 | 488 | | |
| |||
0 commit comments