-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix sliced_string_as_bytes FP with a RangeFull
#15873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I mean this it's really a char boundary alignment check, so "UTF-8 alignment" isn't incorrect?
The closest I could find is Adding support for that could be an improvement to the lint. |
| let bytes = &"consectetur adipiscing".as_bytes()[..=5]; | ||
| //~^ sliced_string_as_bytes | ||
|
|
||
| let bytes = s[..].as_bytes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some comment as to why this is not linted.
|
Just a very tiny nit, otherwise this looks good to merge. |
a6d596b to
386451c
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@llogiq thanks! |
|
I'm pretty sure |
it doesn't (I checked), but also, why not lint on e.g. |
Ah, that's because it calls
I'd say that generally, if someone is having a need to spell out |
No worries, thanks for taking a look!
Good point. |
|
@yotamofek thank you. I will merge this now, any other extension can be a followup PR. |
changelog: [
sliced_string_as_bytes]: don't fire onstr[..].as_bytes()So I ran into this in some codebase I was working on,
where the lint fired on this line:
So I was trying to understand the rationale behind this lint, and it says:
This is obviously not true in the case where a
RangeFullslice is being taken, since there is no UTF-8 boundary check, and no panic can be caused. So I created an exemption forRangeFulls.Two other notes:
str[..].len()orslice[..].len(), wherestrandsliceare&strand&[T], respectively. If we had one, I would expect it to fire for the example code I quoted above.