Commit a6456cc
committed
refactor: fix bug in comments right before a Use
Root cause (in `rewrite/base.rs`, not the transform): the
`Right`/insert branches of `rewrite_seq` and `rewrite_seq_comma_sep` anchored
insertions at the neighbors' raw `splice_span()` boundaries, while the
neighbors' own rewrites and deletions claim their *comment-extended* spans
(`extend_span_comments`) — so an insertion anchored at the raw start of a
commented, rewritten item landed inside that item's claimed region and
`cleanup_rewrites` panicked. The insert branches now extend the neighbor
anchor spans over comments the same way the delete branch always did, and an
insertion at position 0 anchors before the first item's comment-extended span
(the sequence's outer span can start inside it). Inserting exactly at the
extended start of the next item is safe: `cleanup_rewrites` sorts the
insertion ahead of the following rewrite. The regression test keeps the
comment attached to the import and so covers this fix too.1 parent 7ab6fcf commit a6456cc
3 files changed
Lines changed: 47 additions & 14 deletions
File tree
- c2rust-refactor
- src/rewrite
- tests/snapshots
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
351 | 365 | | |
352 | | - | |
| 366 | + | |
353 | 367 | | |
354 | 368 | | |
355 | 369 | | |
356 | 370 | | |
357 | | - | |
| 371 | + | |
358 | 372 | | |
359 | 373 | | |
360 | 374 | | |
361 | 375 | | |
362 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
363 | 381 | | |
364 | 382 | | |
365 | 383 | | |
| |||
460 | 478 | | |
461 | 479 | | |
462 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
463 | 489 | | |
464 | | - | |
| 490 | + | |
465 | 491 | | |
466 | 492 | | |
467 | 493 | | |
468 | 494 | | |
469 | | - | |
| 495 | + | |
470 | 496 | | |
471 | 497 | | |
472 | 498 | | |
473 | 499 | | |
474 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
475 | 505 | | |
476 | 506 | | |
477 | 507 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | 50 | | |
55 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| |||
0 commit comments