Skip to content

Commit f6574c5

Browse files
committed
Auto merge of #25006 - alexcrichton:unstable-indexing, r=aturon
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 [breaking-change]
2 parents f3345cb + b1976f1 commit f6574c5

File tree

9 files changed

+30
-193
lines changed

9 files changed

+30
-193
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-5
Original file line numberDiff line numberDiff line change
@@ -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,8 +1614,7 @@ impl<T: Ord> Ord for Vec<T> {
16141614
}
16151615
}
16161616

1617-
#[unstable(feature = "collections",
1618-
reason = "recent addition, needs more experience")]
1617+
#[stable(feature = "rust1", since = "1.0.0")]
16191618
impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
16201619
type Output = Vec<T>;
16211620

@@ -1694,7 +1693,7 @@ impl<'a> From<&'a str> for Vec<u8> {
16941693
// Clone-on-write
16951694
////////////////////////////////////////////////////////////////////////////////
16961695

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

src/libcore/iter.rs

+4-9
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

-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
@@ -119,7 +119,7 @@ impl<R> fmt::Debug for BufReader<R> where R: fmt::Debug {
119119
}
120120
}
121121

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

286-
#[unstable(feature = "buf_seek", reason = "recently added")]
287-
impl<W: Write+Seek> Seek for BufWriter<W> {
286+
#[stable(feature = "rust1", since = "1.0.0")]
287+
impl<W: Write + Seek> Seek for BufWriter<W> {
288288
/// Seek to the offset, in bytes, in the underlying writer.
289289
///
290290
/// 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)