new lint: `chars_enumerate_for_byte_indices`
Closes #10202.
This adds a new lint that checks for uses of the .chars().enumerate() position in a context where a byte index is required and suggests changing it to use .char_indices() instead.
I'm planning to extend this lint to also detect uses of the position in iterator chains, e.g. s.chars().enumerate().for_each(|(i, _)| s.split_at(i));, but that's for another time
changelog: new lint: chars_enumerate_for_byte_indices
r? @Centri3
rustbot has assigned @Centri3. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r? to explicitly pick a reviewer
Thank you for working on this.
The linter we are working on (oxlint) has encountered dozens of crashes because of this, and there were no ways to forbid such usages.
:umbrella: The latest upstream changes (presumably 1f966e98db0c83fc76657fbc0bd50d11526787b1) made this pull request unmergeable. Please resolve the merge conflicts.
Added a note for str::bytes and also renamed the lint to be slightly more general in case we have other sources of char indices in the future as Jarcho suggested on zulip. Left them as separate commits for now so it's easier to review but will squash once you think it's ok
Hey @y21, can you take a look at this again? Is there anything from my review that doesn't make sense/you're stuck on?
Oops, I got busy and forgot about this. I'll look at this again over the weekend!