Skip to content

Commit 2f3ea53

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
1 parent e962870 commit 2f3ea53

File tree

8 files changed

+26
-195
lines changed

8 files changed

+26
-195
lines changed

src/libcollections/string.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,7 @@ impl<'a> FromIterator<&'a str> for String {
740740
}
741741
}
742742

743-
#[unstable(feature = "collections",
744-
reason = "waiting on Extend stabilization")]
743+
#[stable(feature = "rust1", since = "1.0.0")]
745744
impl Extend<char> for String {
746745
fn extend<I: IntoIterator<Item=char>>(&mut self, iterable: I) {
747746
let iterator = iterable.into_iter();
@@ -753,8 +752,7 @@ impl Extend<char> for String {
753752
}
754753
}
755754

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

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

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

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

src/libcollections/vec.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use core::intrinsics::assume;
5959
use core::iter::{repeat, FromIterator};
6060
use core::marker::PhantomData;
6161
use core::mem;
62-
use core::ops::{Index, IndexMut, Deref, Add};
62+
use core::ops::{Index, IndexMut, Deref};
6363
use core::ops;
6464
use core::ptr;
6565
use core::ptr::Unique;
@@ -1299,7 +1299,7 @@ pub fn from_elem<T: Clone>(elem: T, n: usize) -> Vec<T> {
12991299
// Common trait implementations for Vec
13001300
////////////////////////////////////////////////////////////////////////////////
13011301

1302-
#[unstable(feature = "collections")]
1302+
#[stable(feature = "rust1", since = "1.0.0")]
13031303
impl<T:Clone> Clone for Vec<T> {
13041304
#[cfg(not(test))]
13051305
fn clone(&self) -> Vec<T> { <[T]>::to_vec(&**self) }
@@ -1554,7 +1554,7 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
15541554
}
15551555
}
15561556

1557-
#[unstable(feature = "collections", reason = "waiting on Extend stability")]
1557+
#[stable(feature = "rust1", since = "1.0.0")]
15581558
impl<T> Extend<T> for Vec<T> {
15591559
#[inline]
15601560
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
@@ -1614,18 +1614,6 @@ impl<T: Ord> Ord for Vec<T> {
16141614
}
16151615
}
16161616

1617-
#[unstable(feature = "collections",
1618-
reason = "recent addition, needs more experience")]
1619-
impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
1620-
type Output = Vec<T>;
1621-
1622-
#[inline]
1623-
fn add(mut self, rhs: &[T]) -> Vec<T> {
1624-
self.push_all(rhs);
1625-
self
1626-
}
1627-
}
1628-
16291617
#[stable(feature = "rust1", since = "1.0.0")]
16301618
impl<T> Drop for Vec<T> {
16311619
fn drop(&mut self) {
@@ -1694,7 +1682,7 @@ impl<'a> From<&'a str> for Vec<u8> {
16941682
// Clone-on-write
16951683
////////////////////////////////////////////////////////////////////////////////
16961684

1697-
#[unstable(feature = "collections")]
1685+
#[stable(feature = "rust1", since = "1.0.0")]
16981686
impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
16991687
fn from_iter<I: IntoIterator<Item=T>>(it: I) -> Cow<'a, [T]> {
17001688
Cow::Owned(FromIterator::from_iter(it))

src/libcore/slice.rs

-110
Original file line numberDiff line numberDiff line change
@@ -762,46 +762,6 @@ pub struct Iter<'a, T: 'a> {
762762
unsafe impl<'a, T: Sync> Sync for Iter<'a, T> {}
763763
unsafe impl<'a, T: Sync> Send for Iter<'a, T> {}
764764

765-
#[unstable(feature = "core")]
766-
impl<'a, T> ops::Index<ops::Range<usize>> for Iter<'a, T> {
767-
type Output = [T];
768-
769-
#[inline]
770-
fn index(&self, index: ops::Range<usize>) -> &[T] {
771-
self.as_slice().index(index)
772-
}
773-
}
774-
775-
#[unstable(feature = "core")]
776-
impl<'a, T> ops::Index<ops::RangeTo<usize>> for Iter<'a, T> {
777-
type Output = [T];
778-
779-
#[inline]
780-
fn index(&self, index: ops::RangeTo<usize>) -> &[T] {
781-
self.as_slice().index(index)
782-
}
783-
}
784-
785-
#[unstable(feature = "core")]
786-
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for Iter<'a, T> {
787-
type Output = [T];
788-
789-
#[inline]
790-
fn index(&self, index: ops::RangeFrom<usize>) -> &[T] {
791-
self.as_slice().index(index)
792-
}
793-
}
794-
795-
#[unstable(feature = "core")]
796-
impl<'a, T> ops::Index<RangeFull> for Iter<'a, T> {
797-
type Output = [T];
798-
799-
#[inline]
800-
fn index(&self, _index: RangeFull) -> &[T] {
801-
self.as_slice()
802-
}
803-
}
804-
805765
impl<'a, T> Iter<'a, T> {
806766
/// View the underlying data as a subslice of the original data.
807767
///
@@ -873,76 +833,6 @@ pub struct IterMut<'a, T: 'a> {
873833
unsafe impl<'a, T: Sync> Sync for IterMut<'a, T> {}
874834
unsafe impl<'a, T: Send> Send for IterMut<'a, T> {}
875835

876-
#[unstable(feature = "core")]
877-
impl<'a, T> ops::Index<ops::Range<usize>> for IterMut<'a, T> {
878-
type Output = [T];
879-
880-
#[inline]
881-
fn index(&self, index: ops::Range<usize>) -> &[T] {
882-
self.index(RangeFull).index(index)
883-
}
884-
}
885-
#[unstable(feature = "core")]
886-
impl<'a, T> ops::Index<ops::RangeTo<usize>> for IterMut<'a, T> {
887-
type Output = [T];
888-
889-
#[inline]
890-
fn index(&self, index: ops::RangeTo<usize>) -> &[T] {
891-
self.index(RangeFull).index(index)
892-
}
893-
}
894-
#[unstable(feature = "core")]
895-
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for IterMut<'a, T> {
896-
type Output = [T];
897-
898-
#[inline]
899-
fn index(&self, index: ops::RangeFrom<usize>) -> &[T] {
900-
self.index(RangeFull).index(index)
901-
}
902-
}
903-
#[unstable(feature = "core")]
904-
impl<'a, T> ops::Index<RangeFull> for IterMut<'a, T> {
905-
type Output = [T];
906-
907-
#[inline]
908-
fn index(&self, _index: RangeFull) -> &[T] {
909-
make_slice!(T => &[T]: self.ptr, self.end)
910-
}
911-
}
912-
913-
#[unstable(feature = "core")]
914-
impl<'a, T> ops::IndexMut<ops::Range<usize>> for IterMut<'a, T> {
915-
#[inline]
916-
fn index_mut(&mut self, index: ops::Range<usize>) -> &mut [T] {
917-
self.index_mut(RangeFull).index_mut(index)
918-
}
919-
}
920-
#[unstable(feature = "core")]
921-
impl<'a, T> ops::IndexMut<ops::RangeTo<usize>> for IterMut<'a, T> {
922-
923-
#[inline]
924-
fn index_mut(&mut self, index: ops::RangeTo<usize>) -> &mut [T] {
925-
self.index_mut(RangeFull).index_mut(index)
926-
}
927-
}
928-
#[unstable(feature = "core")]
929-
impl<'a, T> ops::IndexMut<ops::RangeFrom<usize>> for IterMut<'a, T> {
930-
931-
#[inline]
932-
fn index_mut(&mut self, index: ops::RangeFrom<usize>) -> &mut [T] {
933-
self.index_mut(RangeFull).index_mut(index)
934-
}
935-
}
936-
#[unstable(feature = "core")]
937-
impl<'a, T> ops::IndexMut<RangeFull> for IterMut<'a, T> {
938-
939-
#[inline]
940-
fn index_mut(&mut self, _index: RangeFull) -> &mut [T] {
941-
make_mut_slice!(T => &mut [T]: self.ptr, self.end)
942-
}
943-
}
944-
945-
946836
impl<'a, T> IterMut<'a, T> {
947837
/// View the underlying data as a subslice of the original data.
948838
///

src/libcoretest/slice.rs

-49
Original file line numberDiff line numberDiff line change
@@ -34,55 +34,6 @@ fn binary_search_not_found() {
3434
assert!(b.binary_search_by(|v| v.cmp(&9)) == Err(6));
3535
}
3636

37-
#[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!([(),(),()]);
84-
}
85-
8637
#[test]
8738
fn test_iterator_nth() {
8839
let v: &[_] = &[0, 1, 2, 3, 4];

src/librustc_driver/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,11 @@ pub fn monitor<F:FnOnce()+Send+'static>(f: F) {
852852
pub fn diagnostics_registry() -> diagnostics::registry::Registry {
853853
use syntax::diagnostics::registry::Registry;
854854

855-
let all_errors = Vec::new() +
856-
&rustc::DIAGNOSTICS[..] +
857-
&rustc_typeck::DIAGNOSTICS[..] +
858-
&rustc_borrowck::DIAGNOSTICS[..] +
859-
&rustc_resolve::DIAGNOSTICS[..];
855+
let mut all_errors = Vec::new();
856+
all_errors.push_all(&rustc::DIAGNOSTICS);
857+
all_errors.push_all(&rustc_typeck::DIAGNOSTICS);
858+
all_errors.push_all(&rustc_borrowck::DIAGNOSTICS);
859+
all_errors.push_all(&rustc_resolve::DIAGNOSTICS);
860860

861861
Registry::new(&*all_errors)
862862
}

src/libstd/collections/hash/map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1605,8 +1605,7 @@ impl HashState for RandomState {
16051605
}
16061606
}
16071607

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

src/libstd/io/buffered.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<R> fmt::Debug for BufReader<R> where R: fmt::Debug {
118118
}
119119
}
120120

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

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

src/libstd/net/parser.rs

+1-1
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)