diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-07-11 09:24:42 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-07-15 08:27:15 +0000 |
| commit | 2b4ede7e3d37de731821b5b04a6f1fce269c1afb (patch) | |
| tree | 4c4c7f29648eba79b916e7cdf432ca3d0099ded7 /library | |
| parent | cb7d52f6430922b5ffd29073f6605b19b80e7f36 (diff) | |
| download | rust-2b4ede7e3d37de731821b5b04a6f1fce269c1afb.tar.gz rust-2b4ede7e3d37de731821b5b04a6f1fce269c1afb.zip | |
constify `Index` trait and its slice impls
Diffstat (limited to 'library')
| -rw-r--r-- | library/core/src/array/mod.rs | 10 | ||||
| -rw-r--r-- | library/core/src/ops/index.rs | 6 | ||||
| -rw-r--r-- | library/core/src/slice/index.rs | 10 | ||||
| -rw-r--r-- | library/core/src/str/traits.rs | 10 |
4 files changed, 23 insertions, 13 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 16356f749c9..62203e132b7 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -374,9 +374,10 @@ impl<'a, T, const N: usize> IntoIterator for &'a mut [T; N] { } #[stable(feature = "index_trait_on_arrays", since = "1.50.0")] -impl<T, I, const N: usize> Index<I> for [T; N] +#[rustc_const_unstable(feature = "const_index", issue = "143775")] +impl<T, I, const N: usize> const Index<I> for [T; N] where - [T]: Index<I>, + [T]: ~const Index<I>, { type Output = <[T] as Index<I>>::Output; @@ -387,9 +388,10 @@ where } #[stable(feature = "index_trait_on_arrays", since = "1.50.0")] -impl<T, I, const N: usize> IndexMut<I> for [T; N] +#[rustc_const_unstable(feature = "const_index", issue = "143775")] +impl<T, I, const N: usize> const IndexMut<I> for [T; N] where - [T]: IndexMut<I>, + [T]: ~const IndexMut<I>, { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index 8092fa9eb2f..d8489e9a949 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -55,6 +55,8 @@ #[doc(alias = "]")] #[doc(alias = "[")] #[doc(alias = "[]")] +#[const_trait] +#[rustc_const_unstable(feature = "const_index", issue = "143775")] pub trait Index<Idx: ?Sized> { /// The returned type after indexing. #[stable(feature = "rust1", since = "1.0.0")] @@ -165,7 +167,9 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind #[doc(alias = "[")] #[doc(alias = "]")] #[doc(alias = "[]")] -pub trait IndexMut<Idx: ?Sized>: Index<Idx> { +#[rustc_const_unstable(feature = "const_index", issue = "143775")] +#[const_trait] +pub trait IndexMut<Idx: ?Sized>: ~const Index<Idx> { /// Performs the mutable indexing (`container[index]`) operation. /// /// # Panics diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index c9b8e9c71b4..322b3580ede 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -6,9 +6,10 @@ use crate::ub_checks::assert_unsafe_precondition; use crate::{ops, range}; #[stable(feature = "rust1", since = "1.0.0")] -impl<T, I> ops::Index<I> for [T] +#[rustc_const_unstable(feature = "const_index", issue = "143775")] +impl<T, I> const ops::Index<I> for [T] where - I: SliceIndex<[T]>, + I: ~const SliceIndex<[T]>, { type Output = I::Output; @@ -19,9 +20,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, I> ops::IndexMut<I> for [T] +#[rustc_const_unstable(feature = "const_index", issue = "143775")] +impl<T, I> const ops::IndexMut<I> for [T] where - I: SliceIndex<[T]>, + I: ~const SliceIndex<[T]>, { #[inline(always)] fn index_mut(&mut self, index: I) -> &mut I::Output { diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index 2ed5e686399..42ffc591b5b 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -49,9 +49,10 @@ impl PartialOrd for str { } #[stable(feature = "rust1", since = "1.0.0")] -impl<I> ops::Index<I> for str +#[rustc_const_unstable(feature = "const_index", issue = "143775")] +impl<I> const ops::Index<I> for str where - I: SliceIndex<str>, + I: ~const SliceIndex<str>, { type Output = I::Output; @@ -62,9 +63,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<I> ops::IndexMut<I> for str +#[rustc_const_unstable(feature = "const_index", issue = "143775")] +impl<I> const ops::IndexMut<I> for str where - I: SliceIndex<str>, + I: ~const SliceIndex<str>, { #[inline] fn index_mut(&mut self, index: I) -> &mut I::Output { |
