about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorPeter Jaszkowiak <p.jaszkow@gmail.com>2023-03-04 15:11:24 -0700
committerPeter Jaszkowiak <p.jaszkow@gmail.com>2023-03-04 15:11:24 -0700
commitcd35794d5ea6688e77dd17e96556f5de0b410e8a (patch)
tree71fc92526aa1f2d0250acfdbd1c7005132c1f473 /library
parent09f8885b3b84bc9ba06652dc58383f0e3ab97445 (diff)
downloadrust-cd35794d5ea6688e77dd17e96556f5de0b410e8a.tar.gz
rust-cd35794d5ea6688e77dd17e96556f5de0b410e8a.zip
Comment for why char boundaries aren't checked
Diffstat (limited to 'library')
-rw-r--r--library/core/src/str/traits.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs
index a7a2b03774a..b6d605c52d1 100644
--- a/library/core/src/str/traits.rs
+++ b/library/core/src/str/traits.rs
@@ -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)