From 1ff7da6551a7cdf6ace2a9d00e92bbab550334ee Mon Sep 17 00:00:00 2001 From: dylni <46035563+dylni@users.noreply.github.com> Date: Fri, 18 Sep 2020 12:17:51 -0400 Subject: [PATCH 1/4] Move `slice::check_range` to `RangeBounds` --- library/alloc/src/collections/vec_deque.rs | 2 +- library/alloc/src/lib.rs | 2 +- library/alloc/src/slice.rs | 2 - library/alloc/src/string.rs | 5 +- library/alloc/src/vec.rs | 2 +- library/core/src/ops/range.rs | 82 ++++++++++++++++++ library/core/src/slice/index.rs | 83 ++----------------- library/core/src/slice/mod.rs | 7 +- .../range-bounds-for-length.md | 10 +++ .../src/library-features/slice-check-range.md | 10 --- 10 files changed, 104 insertions(+), 101 deletions(-) create mode 100644 src/doc/unstable-book/src/library-features/range-bounds-for-length.md delete mode 100644 src/doc/unstable-book/src/library-features/slice-check-range.md diff --git a/library/alloc/src/collections/vec_deque.rs b/library/alloc/src/collections/vec_deque.rs index 65cfe9a9b4996..0cb8d7a891a0d 100644 --- a/library/alloc/src/collections/vec_deque.rs +++ b/library/alloc/src/collections/vec_deque.rs @@ -1089,7 +1089,7 @@ impl VecDeque { where R: RangeBounds, { - let Range { start, end } = slice::check_range(self.len(), range); + let Range { start, end } = range.for_length(self.len()); let tail = self.wrap_add(self.tail, start); let head = self.wrap_add(self.tail, end); (tail, head) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 7881c101f9f60..002c770277970 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -116,11 +116,11 @@ #![feature(or_patterns)] #![feature(pattern)] #![feature(ptr_internals)] +#![feature(range_bounds_for_length)] #![feature(raw_ref_op)] #![feature(rustc_attrs)] #![feature(receiver_trait)] #![feature(min_specialization)] -#![feature(slice_check_range)] #![feature(slice_ptr_get)] #![feature(slice_ptr_len)] #![feature(staged_api)] diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 79403cf86873e..93501ef40852a 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -91,8 +91,6 @@ use crate::borrow::ToOwned; use crate::boxed::Box; use crate::vec::Vec; -#[unstable(feature = "slice_check_range", issue = "76393")] -pub use core::slice::check_range; #[unstable(feature = "array_chunks", issue = "74985")] pub use core::slice::ArrayChunks; #[unstable(feature = "array_chunks", issue = "74985")] diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 2b0ce5ede5630..26124e301115a 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -49,7 +49,6 @@ use core::iter::{FromIterator, FusedIterator}; use core::ops::Bound::{Excluded, Included, Unbounded}; use core::ops::{self, Add, AddAssign, Index, IndexMut, Range, RangeBounds}; use core::ptr; -use core::slice; use core::str::{lossy, pattern::Pattern}; use crate::borrow::{Cow, ToOwned}; @@ -1507,14 +1506,14 @@ impl String { // of the vector version. The data is just plain bytes. // Because the range removal happens in Drop, if the Drain iterator is leaked, // the removal will not happen. - let Range { start, end } = slice::check_range(self.len(), range); + let Range { start, end } = range.for_length(self.len()); assert!(self.is_char_boundary(start)); assert!(self.is_char_boundary(end)); // Take out two simultaneous borrows. The &mut String won't be accessed // until iteration is over, in Drop. let self_ptr = self as *mut _; - // SAFETY: `check_range` and `is_char_boundary` do the appropriate bounds checks. + // SAFETY: `for_length` and `is_char_boundary` do the appropriate bounds checks. let chars_iter = unsafe { self.get_unchecked(start..end) }.chars(); Drain { start, end, iter: chars_iter, string: self_ptr } diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 9dbea0dc9e68b..e668b17c46c0e 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -1312,7 +1312,7 @@ impl Vec { // the hole, and the vector length is restored to the new length. // let len = self.len(); - let Range { start, end } = slice::check_range(len, range); + let Range { start, end } = range.for_length(len); unsafe { // set self.vec length's to start, to be safe in case Drain is leaked diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 2eaf7601e54de..6ad55786176c1 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -1,5 +1,9 @@ use crate::fmt; use crate::hash::Hash; +use crate::slice::index::{ + slice_end_index_len_fail, slice_end_index_overflow_fail, slice_index_order_fail, + slice_start_index_overflow_fail, +}; /// An unbounded range (`..`). /// @@ -729,6 +733,84 @@ pub trait RangeBounds { Unbounded => true, }) } + + /// Performs bounds-checking of this range. + /// + /// The returned [`Range`] is safe to pass to [`slice::get_unchecked`] and + /// [`slice::get_unchecked_mut`] for slices of the given length. + /// + /// [`slice::get_unchecked`]: crate::slice::get_unchecked + /// [`slice::get_unchecked_mut`]: crate::slice::get_unchecked_mut + /// + /// # Panics + /// + /// Panics if the range would be out of bounds. + /// + /// # Examples + /// + /// ``` + /// #![feature(range_bounds_for_length)] + /// + /// let v = [10, 40, 30]; + /// assert_eq!(1..2, (1..2).for_length(v.len())); + /// assert_eq!(0..2, (..2).for_length(v.len())); + /// assert_eq!(1..3, (1..).for_length(v.len())); + /// ``` + /// + /// Panics when [`Index::index`] would panic: + /// + /// ```should_panic + /// #![feature(range_bounds_for_length)] + /// + /// (2..1).for_length(3); + /// ``` + /// + /// ```should_panic + /// #![feature(range_bounds_for_length)] + /// + /// (1..4).for_length(3); + /// ``` + /// + /// ```should_panic + /// #![feature(range_bounds_for_length)] + /// + /// (1..=usize::MAX).for_length(3); + /// ``` + /// + /// [`Index::index`]: crate::ops::Index::index + #[track_caller] + #[unstable(feature = "range_bounds_for_length", issue = "76393")] + fn for_length(self, len: usize) -> Range + where + Self: RangeBounds, + { + let start: Bound<&usize> = self.start_bound(); + let start = match start { + Bound::Included(&start) => start, + Bound::Excluded(start) => { + start.checked_add(1).unwrap_or_else(|| slice_start_index_overflow_fail()) + } + Bound::Unbounded => 0, + }; + + let end: Bound<&usize> = self.end_bound(); + let end = match end { + Bound::Included(end) => { + end.checked_add(1).unwrap_or_else(|| slice_end_index_overflow_fail()) + } + Bound::Excluded(&end) => end, + Bound::Unbounded => len, + }; + + if start > end { + slice_index_order_fail(start, end); + } + if end > len { + slice_end_index_len_fail(end, len); + } + + Range { start, end } + } } use self::Bound::{Excluded, Included, Unbounded}; diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index 16fcb6231dc09..f1f21c1d24b0b 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -1,6 +1,6 @@ //! Indexing implementations for `[T]`. -use crate::ops::{self, Bound, Range, RangeBounds}; +use crate::ops; use crate::ptr; #[stable(feature = "rust1", since = "1.0.0")] @@ -37,104 +37,31 @@ fn slice_start_index_len_fail(index: usize, len: usize) -> ! { #[inline(never)] #[cold] #[track_caller] -pub(super) fn slice_end_index_len_fail(index: usize, len: usize) -> ! { +pub(crate) fn slice_end_index_len_fail(index: usize, len: usize) -> ! { panic!("range end index {} out of range for slice of length {}", index, len); } #[inline(never)] #[cold] #[track_caller] -pub(super) fn slice_index_order_fail(index: usize, end: usize) -> ! { +pub(crate) fn slice_index_order_fail(index: usize, end: usize) -> ! { panic!("slice index starts at {} but ends at {}", index, end); } #[inline(never)] #[cold] #[track_caller] -pub(super) fn slice_start_index_overflow_fail() -> ! { +pub(crate) fn slice_start_index_overflow_fail() -> ! { panic!("attempted to index slice from after maximum usize"); } #[inline(never)] #[cold] #[track_caller] -pub(super) fn slice_end_index_overflow_fail() -> ! { +pub(crate) fn slice_end_index_overflow_fail() -> ! { panic!("attempted to index slice up to maximum usize"); } -/// Performs bounds-checking of the given range. -/// The returned [`Range`] is safe to pass to [`get_unchecked`] and [`get_unchecked_mut`] -/// for slices of the given length. -/// -/// [`get_unchecked`]: ../../std/primitive.slice.html#method.get_unchecked -/// [`get_unchecked_mut`]: ../../std/primitive.slice.html#method.get_unchecked_mut -/// -/// # Panics -/// -/// Panics if the range is out of bounds. -/// -/// # Examples -/// -/// ``` -/// #![feature(slice_check_range)] -/// use std::slice; -/// -/// let v = [10, 40, 30]; -/// assert_eq!(1..2, slice::check_range(v.len(), 1..2)); -/// assert_eq!(0..2, slice::check_range(v.len(), ..2)); -/// assert_eq!(1..3, slice::check_range(v.len(), 1..)); -/// ``` -/// -/// Panics when [`Index::index`] would panic: -/// -/// ```should_panic -/// #![feature(slice_check_range)] -/// -/// std::slice::check_range(3, 2..1); -/// ``` -/// -/// ```should_panic -/// #![feature(slice_check_range)] -/// -/// std::slice::check_range(3, 1..4); -/// ``` -/// -/// ```should_panic -/// #![feature(slice_check_range)] -/// -/// std::slice::check_range(3, 1..=usize::MAX); -/// ``` -/// -/// [`Index::index`]: ops::Index::index -#[track_caller] -#[unstable(feature = "slice_check_range", issue = "76393")] -pub fn check_range>(len: usize, range: R) -> Range { - let start = match range.start_bound() { - Bound::Included(&start) => start, - Bound::Excluded(start) => { - start.checked_add(1).unwrap_or_else(|| slice_start_index_overflow_fail()) - } - Bound::Unbounded => 0, - }; - - let end = match range.end_bound() { - Bound::Included(end) => { - end.checked_add(1).unwrap_or_else(|| slice_end_index_overflow_fail()) - } - Bound::Excluded(&end) => end, - Bound::Unbounded => len, - }; - - if start > end { - slice_index_order_fail(start, end); - } - if end > len { - slice_end_index_len_fail(end, len); - } - - Range { start, end } -} - mod private_slice_index { use super::ops; #[stable(feature = "slice_get_slice", since = "1.28.0")] diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 8e9d1eb98a86b..5ad57b23c4a40 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -29,7 +29,7 @@ pub mod memchr; mod ascii; mod cmp; -mod index; +pub(crate) mod index; mod iter; mod raw; mod rotate; @@ -75,9 +75,6 @@ pub use sort::heapsort; #[stable(feature = "slice_get_slice", since = "1.28.0")] pub use index::SliceIndex; -#[unstable(feature = "slice_check_range", issue = "76393")] -pub use index::check_range; - #[lang = "slice"] #[cfg(not(test))] impl [T] { @@ -2758,7 +2755,7 @@ impl [T] { where T: Copy, { - let Range { start: src_start, end: src_end } = check_range(self.len(), src); + let Range { start: src_start, end: src_end } = src.for_length(self.len()); let count = src_end - src_start; assert!(dest <= self.len() - count, "dest is out of bounds"); // SAFETY: the conditions for `ptr::copy` have all been checked above, diff --git a/src/doc/unstable-book/src/library-features/range-bounds-for-length.md b/src/doc/unstable-book/src/library-features/range-bounds-for-length.md new file mode 100644 index 0000000000000..47a1bd8dff1b8 --- /dev/null +++ b/src/doc/unstable-book/src/library-features/range-bounds-for-length.md @@ -0,0 +1,10 @@ +# `range_bounds_for_length` + +The tracking issue for this feature is: [#76393] + +------------------------ + +This adds [`RangeBounds::for_length`]. + +[#76393]: https://github.com/rust-lang/rust/issues/76393 +[`RangeBounds::for_length`]: https://doc.rust-lang.org/nightly/std/ops/trait.RangeBounds.html#method.for_length diff --git a/src/doc/unstable-book/src/library-features/slice-check-range.md b/src/doc/unstable-book/src/library-features/slice-check-range.md deleted file mode 100644 index 83e5738cf5412..0000000000000 --- a/src/doc/unstable-book/src/library-features/slice-check-range.md +++ /dev/null @@ -1,10 +0,0 @@ -# `slice_check_range` - -The tracking issue for this feature is: [#76393] - ------------------------- - -This adds [`slice::check_range`]. - -[#76393]: https://github.com/rust-lang/rust/issues/76393 -[`slice::check_range`]: https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.check_range From 1095dcab96d524e700b11edf366d45a0fd173fa0 Mon Sep 17 00:00:00 2001 From: dylni <46035563+dylni@users.noreply.github.com> Date: Fri, 18 Sep 2020 12:39:10 -0400 Subject: [PATCH 2/4] Fix links --- library/core/src/ops/range.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 6ad55786176c1..378aad5cb9e97 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -739,8 +739,8 @@ pub trait RangeBounds { /// The returned [`Range`] is safe to pass to [`slice::get_unchecked`] and /// [`slice::get_unchecked_mut`] for slices of the given length. /// - /// [`slice::get_unchecked`]: crate::slice::get_unchecked - /// [`slice::get_unchecked_mut`]: crate::slice::get_unchecked_mut + /// [`slice::get_unchecked`]: ../../std/primitive.slice.html#method.get_unchecked + /// [`slice::get_unchecked_mut`]: ../../std/primitive.slice.html#method.get_unchecked_mut /// /// # Panics /// From eb63168e007058dad4af758faf1dca449c049777 Mon Sep 17 00:00:00 2001 From: dylni <46035563+dylni@users.noreply.github.com> Date: Fri, 18 Sep 2020 13:05:54 -0400 Subject: [PATCH 3/4] Fix doctests --- library/core/src/ops/range.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 378aad5cb9e97..d9420616b4bc6 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -751,6 +751,8 @@ pub trait RangeBounds { /// ``` /// #![feature(range_bounds_for_length)] /// + /// use std::ops::RangeBounds; + /// /// let v = [10, 40, 30]; /// assert_eq!(1..2, (1..2).for_length(v.len())); /// assert_eq!(0..2, (..2).for_length(v.len())); @@ -762,18 +764,24 @@ pub trait RangeBounds { /// ```should_panic /// #![feature(range_bounds_for_length)] /// + /// use std::ops::RangeBounds; + /// /// (2..1).for_length(3); /// ``` /// /// ```should_panic /// #![feature(range_bounds_for_length)] /// + /// use std::ops::RangeBounds; + /// /// (1..4).for_length(3); /// ``` /// /// ```should_panic /// #![feature(range_bounds_for_length)] /// + /// use std::ops::RangeBounds; + /// /// (1..=usize::MAX).for_length(3); /// ``` /// From f055b0bb0847ecf08fe452a270faae8324b55b05 Mon Sep 17 00:00:00 2001 From: dylni <46035563+dylni@users.noreply.github.com> Date: Fri, 18 Sep 2020 13:55:03 -0400 Subject: [PATCH 4/4] Rename method to `assert_len` --- library/alloc/src/collections/vec_deque.rs | 2 +- library/alloc/src/lib.rs | 2 +- library/alloc/src/string.rs | 4 +- library/alloc/src/vec.rs | 2 +- library/core/src/ops/range.rs | 82 +++++++++---------- library/core/src/slice/mod.rs | 2 +- .../range-bounds-assert-len.md | 10 +++ .../range-bounds-for-length.md | 10 --- 8 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 src/doc/unstable-book/src/library-features/range-bounds-assert-len.md delete mode 100644 src/doc/unstable-book/src/library-features/range-bounds-for-length.md diff --git a/library/alloc/src/collections/vec_deque.rs b/library/alloc/src/collections/vec_deque.rs index 0cb8d7a891a0d..4d6c681e44c1c 100644 --- a/library/alloc/src/collections/vec_deque.rs +++ b/library/alloc/src/collections/vec_deque.rs @@ -1089,7 +1089,7 @@ impl VecDeque { where R: RangeBounds, { - let Range { start, end } = range.for_length(self.len()); + let Range { start, end } = range.assert_len(self.len()); let tail = self.wrap_add(self.tail, start); let head = self.wrap_add(self.tail, end); (tail, head) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 002c770277970..512a4a1cc1b44 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -116,7 +116,7 @@ #![feature(or_patterns)] #![feature(pattern)] #![feature(ptr_internals)] -#![feature(range_bounds_for_length)] +#![feature(range_bounds_assert_len)] #![feature(raw_ref_op)] #![feature(rustc_attrs)] #![feature(receiver_trait)] diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 26124e301115a..7b0ec1c43c0a4 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1506,14 +1506,14 @@ impl String { // of the vector version. The data is just plain bytes. // Because the range removal happens in Drop, if the Drain iterator is leaked, // the removal will not happen. - let Range { start, end } = range.for_length(self.len()); + let Range { start, end } = range.assert_len(self.len()); assert!(self.is_char_boundary(start)); assert!(self.is_char_boundary(end)); // Take out two simultaneous borrows. The &mut String won't be accessed // until iteration is over, in Drop. let self_ptr = self as *mut _; - // SAFETY: `for_length` and `is_char_boundary` do the appropriate bounds checks. + // SAFETY: `assert_len` and `is_char_boundary` do the appropriate bounds checks. let chars_iter = unsafe { self.get_unchecked(start..end) }.chars(); Drain { start, end, iter: chars_iter, string: self_ptr } diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index e668b17c46c0e..90c2708b9c9b2 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -1312,7 +1312,7 @@ impl Vec { // the hole, and the vector length is restored to the new length. // let len = self.len(); - let Range { start, end } = range.for_length(len); + let Range { start, end } = range.assert_len(len); unsafe { // set self.vec length's to start, to be safe in case Drain is leaked diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index d9420616b4bc6..16d86c8197803 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -705,35 +705,6 @@ pub trait RangeBounds { #[stable(feature = "collections_range", since = "1.28.0")] fn end_bound(&self) -> Bound<&T>; - /// Returns `true` if `item` is contained in the range. - /// - /// # Examples - /// - /// ``` - /// assert!( (3..5).contains(&4)); - /// assert!(!(3..5).contains(&2)); - /// - /// assert!( (0.0..1.0).contains(&0.5)); - /// assert!(!(0.0..1.0).contains(&f32::NAN)); - /// assert!(!(0.0..f32::NAN).contains(&0.5)); - /// assert!(!(f32::NAN..1.0).contains(&0.5)); - #[stable(feature = "range_contains", since = "1.35.0")] - fn contains(&self, item: &U) -> bool - where - T: PartialOrd, - U: ?Sized + PartialOrd, - { - (match self.start_bound() { - Included(ref start) => *start <= item, - Excluded(ref start) => *start < item, - Unbounded => true, - }) && (match self.end_bound() { - Included(ref end) => item <= *end, - Excluded(ref end) => item < *end, - Unbounded => true, - }) - } - /// Performs bounds-checking of this range. /// /// The returned [`Range`] is safe to pass to [`slice::get_unchecked`] and @@ -749,46 +720,46 @@ pub trait RangeBounds { /// # Examples /// /// ``` - /// #![feature(range_bounds_for_length)] + /// #![feature(range_bounds_assert_len)] /// /// use std::ops::RangeBounds; /// /// let v = [10, 40, 30]; - /// assert_eq!(1..2, (1..2).for_length(v.len())); - /// assert_eq!(0..2, (..2).for_length(v.len())); - /// assert_eq!(1..3, (1..).for_length(v.len())); + /// assert_eq!(1..2, (1..2).assert_len(v.len())); + /// assert_eq!(0..2, (..2).assert_len(v.len())); + /// assert_eq!(1..3, (1..).assert_len(v.len())); /// ``` /// /// Panics when [`Index::index`] would panic: /// /// ```should_panic - /// #![feature(range_bounds_for_length)] + /// #![feature(range_bounds_assert_len)] /// /// use std::ops::RangeBounds; /// - /// (2..1).for_length(3); + /// (2..1).assert_len(3); /// ``` /// /// ```should_panic - /// #![feature(range_bounds_for_length)] + /// #![feature(range_bounds_assert_len)] /// /// use std::ops::RangeBounds; /// - /// (1..4).for_length(3); + /// (1..4).assert_len(3); /// ``` /// /// ```should_panic - /// #![feature(range_bounds_for_length)] + /// #![feature(range_bounds_assert_len)] /// /// use std::ops::RangeBounds; /// - /// (1..=usize::MAX).for_length(3); + /// (1..=usize::MAX).assert_len(3); /// ``` /// /// [`Index::index`]: crate::ops::Index::index #[track_caller] - #[unstable(feature = "range_bounds_for_length", issue = "76393")] - fn for_length(self, len: usize) -> Range + #[unstable(feature = "range_bounds_assert_len", issue = "76393")] + fn assert_len(self, len: usize) -> Range where Self: RangeBounds, { @@ -819,6 +790,35 @@ pub trait RangeBounds { Range { start, end } } + + /// Returns `true` if `item` is contained in the range. + /// + /// # Examples + /// + /// ``` + /// assert!( (3..5).contains(&4)); + /// assert!(!(3..5).contains(&2)); + /// + /// assert!( (0.0..1.0).contains(&0.5)); + /// assert!(!(0.0..1.0).contains(&f32::NAN)); + /// assert!(!(0.0..f32::NAN).contains(&0.5)); + /// assert!(!(f32::NAN..1.0).contains(&0.5)); + #[stable(feature = "range_contains", since = "1.35.0")] + fn contains(&self, item: &U) -> bool + where + T: PartialOrd, + U: ?Sized + PartialOrd, + { + (match self.start_bound() { + Included(ref start) => *start <= item, + Excluded(ref start) => *start < item, + Unbounded => true, + }) && (match self.end_bound() { + Included(ref end) => item <= *end, + Excluded(ref end) => item < *end, + Unbounded => true, + }) + } } use self::Bound::{Excluded, Included, Unbounded}; diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 5ad57b23c4a40..43185bae3daec 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2755,7 +2755,7 @@ impl [T] { where T: Copy, { - let Range { start: src_start, end: src_end } = src.for_length(self.len()); + let Range { start: src_start, end: src_end } = src.assert_len(self.len()); let count = src_end - src_start; assert!(dest <= self.len() - count, "dest is out of bounds"); // SAFETY: the conditions for `ptr::copy` have all been checked above, diff --git a/src/doc/unstable-book/src/library-features/range-bounds-assert-len.md b/src/doc/unstable-book/src/library-features/range-bounds-assert-len.md new file mode 100644 index 0000000000000..0e95d5ded9296 --- /dev/null +++ b/src/doc/unstable-book/src/library-features/range-bounds-assert-len.md @@ -0,0 +1,10 @@ +# `range_bounds_assert_len` + +The tracking issue for this feature is: [#76393] + +------------------------ + +This adds [`RangeBounds::assert_len`]. + +[#76393]: https://github.com/rust-lang/rust/issues/76393 +[`RangeBounds::assert_len`]: https://doc.rust-lang.org/nightly/std/ops/trait.RangeBounds.html#method.assert_len diff --git a/src/doc/unstable-book/src/library-features/range-bounds-for-length.md b/src/doc/unstable-book/src/library-features/range-bounds-for-length.md deleted file mode 100644 index 47a1bd8dff1b8..0000000000000 --- a/src/doc/unstable-book/src/library-features/range-bounds-for-length.md +++ /dev/null @@ -1,10 +0,0 @@ -# `range_bounds_for_length` - -The tracking issue for this feature is: [#76393] - ------------------------- - -This adds [`RangeBounds::for_length`]. - -[#76393]: https://github.com/rust-lang/rust/issues/76393 -[`RangeBounds::for_length`]: https://doc.rust-lang.org/nightly/std/ops/trait.RangeBounds.html#method.for_length