diff options
| author | bors <bors@rust-lang.org> | 2024-03-15 17:30:23 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-15 17:30:23 +0000 |
| commit | c9f24827b3ebe3bda28f5315b50717662661d87e (patch) | |
| tree | ee57234df009a5d037709db6a621696dd4690412 /tests/codegen/patchable-function-entry/patchable-function-entry-both-flags.rs | |
| parent | 5a11fefc259e56ef305a9d53caf0ac7a0835b609 (diff) | |
| parent | d3f8f3e9d7e59cce5875920eddfef54970e9fe51 (diff) | |
| download | rust-c9f24827b3ebe3bda28f5315b50717662661d87e.tar.gz rust-c9f24827b3ebe3bda28f5315b50717662661d87e.zip | |
Auto merge of #12493 - y21:issue12491, r=Alexendoo
fix span calculation for non-ascii in `needless_return`
Fixes #12491
Probably fixes #12328 as well, but that one has no reproducer, so 🤷
The bug was that the lint used `rfind()` for finding the byte index of the start of the previous non-whitespace character:
```
// abc\n return;
^
```
... then subtracting one to get the byte index of the actual whitespace (the `\n` here).
(Subtracting instead of adding because it treats this as the length from the `return` token to the `\n`)
That's correct for ascii, like here, and will get us to the `\n`, however for non ascii, the `c` could be multiple bytes wide, which would put us in the middle of a codepoint if we simply subtract 1 and is what caused the ICE.
There's probably a lot of ways we could fix this.
This PR changes it to iterate backwards using bytes instead of characters, so that when `rposition()` finally finds a non-whitespace byte, we *know* that we've skipped exactly 1 byte. This was *probably*(?) what the code was intending to do
changelog: Fix ICE in [`needless_return`] when previous line end in a non-ascii character
Diffstat (limited to 'tests/codegen/patchable-function-entry/patchable-function-entry-both-flags.rs')
0 files changed, 0 insertions, 0 deletions
