Commit 81c4dd6
committed
fix(formatter): avoid usize underflow on over-wide comment prefixes
format_leading_comment computed max_comment_width as
`max_line_width - cur_indent - n_slashes - n_exclamations - n_leading_spaces`
in usize. When the prefix exceeds max_line_width (a deeply-indented or long
divider comment), this underflows: debug panics, release wraps. Use
saturating_sub so the width floors at 0 and the comment is left unwrapped.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 0ef1296 commit 81c4dd6
4 files changed
Lines changed: 20 additions & 4 deletions
File tree
- crates/cairo-lang-formatter
- src
- test_data
- cairo_files
- expected_results
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
794 | 794 | | |
795 | 795 | | |
796 | 796 | | |
| 797 | + | |
| 798 | + | |
797 | 799 | | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
802 | 804 | | |
803 | 805 | | |
804 | 806 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
101 | 110 | | |
102 | 111 | | |
103 | 112 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments