Skip to content

Commit d5e943b

Browse files
committed
std: Remove index notation on slice iterators
These implementations were intended to be unstable, but currently the stability attributes cannot handle a stable trait with an unstable `impl` block. This commit also audits the rest of the standard library for explicitly-`#[unstable]` impl blocks. No others were removed but some annotations were changed to `#[stable]` as they're defacto stable anyway. One particularly interesting `impl` marked `#[stable]` as part of this commit is the `Add<&[T]>` impl for `Vec<T>`, which uses `push_all` and implicitly clones all elements of the vector provided. Closes #24791 Conflicts: src/libcoretest/slice.rs src/librustc_driver/lib.rs
1 parent 1fcfba1 commit d5e943b

File tree

9 files changed

+29
-189
lines changed

9 files changed

+29
-189
lines changed

src/libcollections/string.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,7 @@ impl<'a> FromIterator<&'a str> for String {
742742
}
743743
}
744744

745-
#[unstable(feature = "collections",
746-
reason = "waiting on Extend stabilization")]
745+
#[stable(feature = "rust1", since = "1.0.0")]
747746
impl Extend<char> for String {
748747
fn extend<I: IntoIterator<Item=char>>(&mut self, iterable: I) {
749748
let iterator = iterable.into_iter();
@@ -755,8 +754,7 @@ impl Extend<char> for String {
755754
}
756755
}
757756

758-
#[unstable(feature = "collections",
759-
reason = "waiting on Extend stabilization")]
757+
#[stable(feature = "rust1", since = "1.0.0")]
760758
impl<'a> Extend<&'a str> for String {
761759
fn extend<I: IntoIterator<Item=&'a str>>(&mut self, iterable: I) {
762760
let iterator = iterable.into_iter();
@@ -871,8 +869,7 @@ impl hash::Hash for String {
871869
}
872870
}
873871

874-
#[unstable(feature = "collections",
875-
reason = "recent addition, needs more experience")]
872+
#[stable(feature = "rust1", since = "1.0.0")]
876873
impl<'a> Add<&'a str> for String {
877874
type Output = String;
878875

@@ -965,11 +962,17 @@ pub fn as_string<'a>(x: &'a str) -> DerefString<'a> {
965962
DerefString { x: as_vec(x.as_bytes()) }
966963
}
967964

968-
#[unstable(feature = "collections", reason = "associated error type may change")]
965+
/// Error returned from `String::from_str`
966+
#[unstable(feature = "str_parse_error", reason = "may want to be replaced with \
967+
Void if it ever exists")]
968+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
969+
pub struct ParseError(());
970+
971+
#[stable(feature = "rust1", since = "1.0.0")]
969972
impl FromStr for String {
970-
type Err = ();
973+
type Err = ParseError;
971974
#[inline]
972-
fn from_str(s: &str) -> Result<String, ()> {
975+
fn from_str(s: &str) -> Result<String, ParseError> {
973976
Ok(String::from_str(s))
974977
}
975978
}

src/libcollections/vec.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ pub fn from_elem<T: Clone>(elem: T, n: usize) -> Vec<T> {
12761276
// Common trait implementations for Vec
12771277
////////////////////////////////////////////////////////////////////////////////
12781278

1279-
#[unstable(feature = "collections")]
1279+
#[stable(feature = "rust1", since = "1.0.0")]
12801280
impl<T:Clone> Clone for Vec<T> {
12811281
#[cfg(not(test))]
12821282
fn clone(&self) -> Vec<T> { <[T]>::to_vec(&**self) }
@@ -1531,7 +1531,7 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
15311531
}
15321532
}
15331533

1534-
#[unstable(feature = "collections", reason = "waiting on Extend stability")]
1534+
#[stable(feature = "rust1", since = "1.0.0")]
15351535
impl<T> Extend<T> for Vec<T> {
15361536
#[inline]
15371537
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
@@ -1591,8 +1591,7 @@ impl<T: Ord> Ord for Vec<T> {
15911591
}
15921592
}
15931593

1594-
#[unstable(feature = "collections",
1595-
reason = "recent addition, needs more experience")]
1594+
#[stable(feature = "rust1", since = "1.0.0")]
15961595
impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
15971596
type Output = Vec<T>;
15981597

@@ -1672,7 +1671,7 @@ impl<'a> From<&'a str> for Vec<u8> {
16721671
// Clone-on-write
16731672
////////////////////////////////////////////////////////////////////////////////
16741673

1675-
#[unstable(feature = "collections")]
1674+
#[stable(feature = "rust1", since = "1.0.0")]
16761675
impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
16771676
fn from_iter<I: IntoIterator<Item=T>>(it: I) -> Cow<'a, [T]> {
16781677
Cow::Owned(FromIterator::from_iter(it))

src/libcore/iter.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,10 @@ pub trait Iterator {
626626
/// # Examples
627627
///
628628
/// ```
629-
/// # #![feature(core)]
630629
/// let a = [1, 2, 3, 4, 5];
631630
/// let mut it = a.iter();
632631
/// assert!(it.any(|x| *x == 3));
633-
/// assert_eq!(&it[..], [4, 5]);
634-
///
632+
/// assert_eq!(it.collect::<Vec<_>>(), [&4, &5]);
635633
/// ```
636634
#[inline]
637635
#[stable(feature = "rust1", since = "1.0.0")]
@@ -654,11 +652,10 @@ pub trait Iterator {
654652
/// # Examples
655653
///
656654
/// ```
657-
/// # #![feature(core)]
658655
/// let a = [1, 2, 3, 4, 5];
659656
/// let mut it = a.iter();
660657
/// assert_eq!(it.find(|&x| *x == 3).unwrap(), &3);
661-
/// assert_eq!(&it[..], [4, 5]);
658+
/// assert_eq!(it.collect::<Vec<_>>(), [&4, &5]);
662659
#[inline]
663660
#[stable(feature = "rust1", since = "1.0.0")]
664661
fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where
@@ -678,11 +675,10 @@ pub trait Iterator {
678675
/// # Examples
679676
///
680677
/// ```
681-
/// # #![feature(core)]
682678
/// let a = [1, 2, 3, 4, 5];
683679
/// let mut it = a.iter();
684680
/// assert_eq!(it.position(|x| *x == 3).unwrap(), 2);
685-
/// assert_eq!(&it[..], [4, 5]);
681+
/// assert_eq!(it.collect::<Vec<_>>(), [&4, &5]);
686682
#[inline]
687683
#[stable(feature = "rust1", since = "1.0.0")]
688684
fn position<P>(&mut self, mut predicate: P) -> Option<usize> where
@@ -708,11 +704,10 @@ pub trait Iterator {
708704
/// # Examples
709705
///
710706
/// ```
711-
/// # #![feature(core)]
712707
/// let a = [1, 2, 2, 4, 5];
713708
/// let mut it = a.iter();
714709
/// assert_eq!(it.rposition(|x| *x == 2).unwrap(), 2);
715-
/// assert_eq!(&it[..], [1, 2]);
710+
/// assert_eq!(it.collect::<Vec<_>>(), [&1, &2]);
716711
#[inline]
717712
#[stable(feature = "rust1", since = "1.0.0")]
718713
fn rposition<P>(&mut self, mut predicate: P) -> Option<usize> where

src/libcore/slice.rs

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -736,46 +736,6 @@ pub struct Iter<'a, T: 'a> {
736736
unsafe impl<'a, T: Sync> Sync for Iter<'a, T> {}
737737
unsafe impl<'a, T: Sync> Send for Iter<'a, T> {}
738738

739-
#[unstable(feature = "core")]
740-
impl<'a, T> ops::Index<ops::Range<usize>> for Iter<'a, T> {
741-
type Output = [T];
742-
743-
#[inline]
744-
fn index(&self, index: ops::Range<usize>) -> &[T] {
745-
self.as_slice().index(index)
746-
}
747-
}
748-
749-
#[unstable(feature = "core")]
750-
impl<'a, T> ops::Index<ops::RangeTo<usize>> for Iter<'a, T> {
751-
type Output = [T];
752-
753-
#[inline]
754-
fn index(&self, index: ops::RangeTo<usize>) -> &[T] {
755-
self.as_slice().index(index)
756-
}
757-
}
758-
759-
#[unstable(feature = "core")]
760-
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for Iter<'a, T> {
761-
type Output = [T];
762-
763-
#[inline]
764-
fn index(&self, index: ops::RangeFrom<usize>) -> &[T] {
765-
self.as_slice().index(index)
766-
}
767-
}
768-
769-
#[unstable(feature = "core")]
770-
impl<'a, T> ops::Index<RangeFull> for Iter<'a, T> {
771-
type Output = [T];
772-
773-
#[inline]
774-
fn index(&self, _index: RangeFull) -> &[T] {
775-
self.as_slice()
776-
}
777-
}
778-
779739
impl<'a, T> Iter<'a, T> {
780740
/// View the underlying data as a subslice of the original data.
781741
///
@@ -833,76 +793,6 @@ pub struct IterMut<'a, T: 'a> {
833793
unsafe impl<'a, T: Sync> Sync for IterMut<'a, T> {}
834794
unsafe impl<'a, T: Send> Send for IterMut<'a, T> {}
835795

836-
#[unstable(feature = "core")]
837-
impl<'a, T> ops::Index<ops::Range<usize>> for IterMut<'a, T> {
838-
type Output = [T];
839-
840-
#[inline]
841-
fn index(&self, index: ops::Range<usize>) -> &[T] {
842-
self.index(RangeFull).index(index)
843-
}
844-
}
845-
#[unstable(feature = "core")]
846-
impl<'a, T> ops::Index<ops::RangeTo<usize>> for IterMut<'a, T> {
847-
type Output = [T];
848-
849-
#[inline]
850-
fn index(&self, index: ops::RangeTo<usize>) -> &[T] {
851-
self.index(RangeFull).index(index)
852-
}
853-
}
854-
#[unstable(feature = "core")]
855-
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for IterMut<'a, T> {
856-
type Output = [T];
857-
858-
#[inline]
859-
fn index(&self, index: ops::RangeFrom<usize>) -> &[T] {
860-
self.index(RangeFull).index(index)
861-
}
862-
}
863-
#[unstable(feature = "core")]
864-
impl<'a, T> ops::Index<RangeFull> for IterMut<'a, T> {
865-
type Output = [T];
866-
867-
#[inline]
868-
fn index(&self, _index: RangeFull) -> &[T] {
869-
make_slice!(T => &[T]: self.ptr, self.end)
870-
}
871-
}
872-
873-
#[unstable(feature = "core")]
874-
impl<'a, T> ops::IndexMut<ops::Range<usize>> for IterMut<'a, T> {
875-
#[inline]
876-
fn index_mut(&mut self, index: ops::Range<usize>) -> &mut [T] {
877-
self.index_mut(RangeFull).index_mut(index)
878-
}
879-
}
880-
#[unstable(feature = "core")]
881-
impl<'a, T> ops::IndexMut<ops::RangeTo<usize>> for IterMut<'a, T> {
882-
883-
#[inline]
884-
fn index_mut(&mut self, index: ops::RangeTo<usize>) -> &mut [T] {
885-
self.index_mut(RangeFull).index_mut(index)
886-
}
887-
}
888-
#[unstable(feature = "core")]
889-
impl<'a, T> ops::IndexMut<ops::RangeFrom<usize>> for IterMut<'a, T> {
890-
891-
#[inline]
892-
fn index_mut(&mut self, index: ops::RangeFrom<usize>) -> &mut [T] {
893-
self.index_mut(RangeFull).index_mut(index)
894-
}
895-
}
896-
#[unstable(feature = "core")]
897-
impl<'a, T> ops::IndexMut<RangeFull> for IterMut<'a, T> {
898-
899-
#[inline]
900-
fn index_mut(&mut self, _index: RangeFull) -> &mut [T] {
901-
make_mut_slice!(T => &mut [T]: self.ptr, self.end)
902-
}
903-
}
904-
905-
906796
impl<'a, T> IterMut<'a, T> {
907797
/// View the underlying data as a subslice of the original data.
908798
///

src/libcoretest/slice.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,50 +35,4 @@ fn binary_search_not_found() {
3535
}
3636

3737
#[test]
38-
fn iterator_to_slice() {
39-
macro_rules! test {
40-
($data: expr) => {{
41-
let data: &mut [_] = &mut $data;
42-
let other_data: &mut [_] = &mut $data;
43-
44-
{
45-
let mut iter = data.iter();
46-
assert_eq!(&iter[..], &other_data[..]);
47-
48-
iter.next();
49-
assert_eq!(&iter[..], &other_data[1..]);
50-
51-
iter.next_back();
52-
assert_eq!(&iter[..], &other_data[1..2]);
53-
54-
let s = iter.as_slice();
55-
iter.next();
56-
assert_eq!(s, &other_data[1..2]);
57-
}
58-
{
59-
let mut iter = data.iter_mut();
60-
assert_eq!(&iter[..], &other_data[..]);
61-
// mutability:
62-
assert!(&mut iter[..] == other_data);
63-
64-
iter.next();
65-
assert_eq!(&iter[..], &other_data[1..]);
66-
assert!(&mut iter[..] == &mut other_data[1..]);
67-
68-
iter.next_back();
69-
70-
assert_eq!(&iter[..], &other_data[1..2]);
71-
assert!(&mut iter[..] == &mut other_data[1..2]);
72-
73-
let s = iter.into_slice();
74-
assert!(s == &mut other_data[1..2]);
75-
}
76-
}}
77-
}
78-
79-
// try types of a variety of sizes
80-
test!([(1u64, 1u64, 1u8), (2, 2, 2), (3, 3, 3)]);
81-
test!([1u64,2,3]);
82-
test!([1u8,2,3]);
83-
test!([(),(),()]);
8438
}

src/librustc_driver/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,10 @@ pub fn monitor<F:FnOnce()+Send+'static>(f: F) {
855855
pub fn diagnostics_registry() -> diagnostics::registry::Registry {
856856
use syntax::diagnostics::registry::Registry;
857857

858-
let all_errors = Vec::new() +
859-
&rustc::diagnostics::DIAGNOSTICS[..] +
860-
&rustc_typeck::diagnostics::DIAGNOSTICS[..] +
861-
&rustc_resolve::diagnostics::DIAGNOSTICS[..];
858+
let mut all_errors = Vec::new();
859+
all_errors.push_all(&rustc::DIAGNOSTICS);
860+
all_errors.push_all(&rustc_typeck::DIAGNOSTICS);
861+
all_errors.push_all(&rustc_resolve::DIAGNOSTICS);
862862

863863
Registry::new(&*all_errors)
864864
}

src/libstd/collections/hash/map.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,8 +1607,7 @@ impl HashState for RandomState {
16071607
}
16081608
}
16091609

1610-
#[unstable(feature = "std_misc",
1611-
reason = "hashing an hash maps may be altered")]
1610+
#[stable(feature = "rust1", since = "1.0.0")]
16121611
impl Default for RandomState {
16131612
#[inline]
16141613
fn default() -> RandomState {

src/libstd/io/buffered.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<R> fmt::Debug for BufReader<R> where R: fmt::Debug {
120120
}
121121
}
122122

123-
#[unstable(feature = "buf_seek", reason = "recently added")]
123+
#[stable(feature = "rust1", since = "1.0.0")]
124124
impl<R: Seek> Seek for BufReader<R> {
125125
/// Seek to an offset, in bytes, in the underlying reader.
126126
///
@@ -284,8 +284,8 @@ impl<W: Write> fmt::Debug for BufWriter<W> where W: fmt::Debug {
284284
}
285285
}
286286

287-
#[unstable(feature = "buf_seek", reason = "recently added")]
288-
impl<W: Write+Seek> Seek for BufWriter<W> {
287+
#[stable(feature = "rust1", since = "1.0.0")]
288+
impl<W: Write + Seek> Seek for BufWriter<W> {
289289
/// Seek to the offset, in bytes, in the underlying writer.
290290
///
291291
/// Seeking always writes out the internal buffer before seeking.

src/libstd/net/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'a> Parser<'a> {
291291
}
292292
}
293293

294-
#[unstable(feature = "ip_addr", reason = "recent addition")]
294+
#[stable(feature = "rust1", since = "1.0.0")]
295295
impl FromStr for IpAddr {
296296
type Err = AddrParseError;
297297
fn from_str(s: &str) -> Result<IpAddr, AddrParseError> {

0 commit comments

Comments
 (0)