Skip to content

Commit 125b32c

Browse files
committed
Stabilize SliceIndex trait.
Fixes #35729 According to recommendations in #35729 (comment)
1 parent 5bf68db commit 125b32c

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
#![feature(ptr_internals)]
105105
#![feature(ptr_offset_from)]
106106
#![feature(rustc_attrs)]
107-
#![feature(slice_get_slice)]
108107
#![feature(specialization)]
109108
#![feature(staged_api)]
110109
#![feature(str_internals)]

src/liballoc/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub use core::slice::{RSplit, RSplitMut};
121121
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
122122
#[stable(feature = "from_ref", since = "1.28.0")]
123123
pub use core::slice::{from_ref, from_mut};
124-
#[unstable(feature = "slice_get_slice", issue = "35729")]
124+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
125125
pub use core::slice::SliceIndex;
126126
#[unstable(feature = "exact_chunks", issue = "47115")]
127127
pub use core::slice::{ExactChunks, ExactChunksMut};

src/libcore/slice/mod.rs

+36-2
Original file line numberDiff line numberDiff line change
@@ -1977,35 +1977,69 @@ fn slice_index_overflow_fail() -> ! {
19771977
panic!("attempted to index slice up to maximum usize");
19781978
}
19791979

1980+
mod private_slice_index {
1981+
use super::ops;
1982+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1983+
pub trait Sealed {}
1984+
1985+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1986+
impl Sealed for usize {}
1987+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1988+
impl Sealed for ops::Range<usize> {}
1989+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1990+
impl Sealed for ops::RangeTo<usize> {}
1991+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1992+
impl Sealed for ops::RangeFrom<usize> {}
1993+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1994+
impl Sealed for ops::RangeFull {}
1995+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1996+
impl Sealed for ops::RangeInclusive<usize> {}
1997+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1998+
impl Sealed for ops::RangeToInclusive<usize> {}
1999+
}
2000+
19802001
/// A helper trait used for indexing operations.
1981-
#[unstable(feature = "slice_get_slice", issue = "35729")]
2002+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
19822003
#[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"]
1983-
pub trait SliceIndex<T: ?Sized> {
2004+
pub trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
19842005
/// The output type returned by methods.
2006+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
19852007
type Output: ?Sized;
19862008

19872009
/// Returns a shared reference to the output at this location, if in
19882010
/// bounds.
2011+
#[unstable(feature = "slice_index_methods", issue = "0")]
2012+
#[doc(hidden)]
19892013
fn get(self, slice: &T) -> Option<&Self::Output>;
19902014

19912015
/// Returns a mutable reference to the output at this location, if in
19922016
/// bounds.
2017+
#[unstable(feature = "slice_index_methods", issue = "0")]
2018+
#[doc(hidden)]
19932019
fn get_mut(self, slice: &mut T) -> Option<&mut Self::Output>;
19942020

19952021
/// Returns a shared reference to the output at this location, without
19962022
/// performing any bounds checking.
2023+
#[unstable(feature = "slice_index_methods", issue = "0")]
2024+
#[doc(hidden)]
19972025
unsafe fn get_unchecked(self, slice: &T) -> &Self::Output;
19982026

19992027
/// Returns a mutable reference to the output at this location, without
20002028
/// performing any bounds checking.
2029+
#[unstable(feature = "slice_index_methods", issue = "0")]
2030+
#[doc(hidden)]
20012031
unsafe fn get_unchecked_mut(self, slice: &mut T) -> &mut Self::Output;
20022032

20032033
/// Returns a shared reference to the output at this location, panicking
20042034
/// if out of bounds.
2035+
#[unstable(feature = "slice_index_methods", issue = "0")]
2036+
#[doc(hidden)]
20052037
fn index(self, slice: &T) -> &Self::Output;
20062038

20072039
/// Returns a mutable reference to the output at this location, panicking
20082040
/// if out of bounds.
2041+
#[unstable(feature = "slice_index_methods", issue = "0")]
2042+
#[doc(hidden)]
20092043
fn index_mut(self, slice: &mut T) -> &mut Self::Output;
20102044
}
20112045

0 commit comments

Comments
 (0)