Comment for why char boundaries aren't checked
This commit is contained in:
parent
09f8885b3b
commit
cd35794d5e
1 changed files with 6 additions and 0 deletions
|
|
@ -204,6 +204,12 @@ unsafe impl const SliceIndex<str> for ops::Range<usize> {
|
|||
assert_unsafe_precondition!(
|
||||
"str::get_unchecked requires that the range is within the string slice",
|
||||
(this: ops::Range<usize>, slice: *const [u8]) =>
|
||||
// We'd like to check that the bounds are on char boundaries,
|
||||
// but there's not really a way to do so without reading
|
||||
// behind the pointer, which has aliasing implications.
|
||||
// It's also not possible to move this check up to
|
||||
// `str::get_unchecked` without adding a special function
|
||||
// to `SliceIndex` just for this.
|
||||
this.end >= this.start && this.end <= slice.len()
|
||||
);
|
||||
slice.as_ptr().add(self.start)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue