-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
slice[slice.len()..]
doesn't result in an index out of bounds error
#32057
Comments
It's definitely intentional that |
Doc-comments in the source code would be enough for a start, even if they are not displayed by |
We need more people to tell about doc blind spots like this! |
…chton Clarify documentation for string slicing (Index impls) Clarify documentation for string slicing (Index impls) - Mention the sugared syntax for the implementations, since it's not apparent from the docs that `Index<Range<usize>>` corresponds to `&self[a..b]`. - Be specific in that start <= end and end <= len This is just one fix in response to rust-lang#32057
…chton Clarify documentation for string slicing (Index impls) Clarify documentation for string slicing (Index impls) - Mention the sugared syntax for the implementations, since it's not apparent from the docs that `Index<Range<usize>>` corresponds to `&self[a..b]`. - Be specific in that start <= end and end <= len This is just one fix in response to rust-lang#32057
Fixed by #32099 |
I need to follow it up with an improvement for slice slicing as well. (Pr was for strings). |
This is a follow up for PR rust-lang#32099 and rust-lang#32057
Clarify doc for slice slicing (Index impls) Clarify doc for slice slicing (Index impls) This is a follow up for PR rust-lang#32099 and rust-lang#32057
Clarify doc for slice slicing (Index impls) Clarify doc for slice slicing (Index impls) This is a follow up for PR rust-lang#32099 and rust-lang#32057
..
ranges are[inclusive, exclusive)
and index access is normally bounds checked, e.g.slice[slice.len()+100..]
orslice[slice.len()]
panics, howeverslice[slice.len()..]
/slice[slice.len()..slice.len()]
is an exception, it just returns an empty slice despite the first inclusive index being out of bounds.I agree this is convenient and I guess this was implemented intentionally, and we can't silently break this now, but it at least needs to be 1) documented as intentional behavior, 2) tested as intentional behavior.
So far I haven't found neither documentation, nor tests, nor design rationale in the range indexing RFCs and their implementations.
The text was updated successfully, but these errors were encountered: