We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 09f8885 commit cd35794Copy full SHA for cd35794
library/core/src/str/traits.rs
@@ -204,6 +204,12 @@ unsafe impl const SliceIndex<str> for ops::Range<usize> {
204
assert_unsafe_precondition!(
205
"str::get_unchecked requires that the range is within the string slice",
206
(this: ops::Range<usize>, slice: *const [u8]) =>
207
+ // We'd like to check that the bounds are on char boundaries,
208
+ // but there's not really a way to do so without reading
209
+ // behind the pointer, which has aliasing implications.
210
+ // It's also not possible to move this check up to
211
+ // `str::get_unchecked` without adding a special function
212
+ // to `SliceIndex` just for this.
213
this.end >= this.start && this.end <= slice.len()
214
);
215
slice.as_ptr().add(self.start)
0 commit comments