diff options
| author | Brian Anderson <banderson@mozilla.com> | 2015-01-24 09:15:42 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2015-01-25 01:20:55 -0800 |
| commit | 63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70 (patch) | |
| tree | c732033c0822f25f2aebcdf193de1b257bac1855 /src/libcollections | |
| parent | b44ee371b8beea77aa1364460acbba14a8516559 (diff) | |
| parent | 0430a43d635841db44978bb648e9cf7e7cfa1bba (diff) | |
| download | rust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.tar.gz rust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.zip | |
Merge remote-tracking branch 'rust-lang/master'
Conflicts: mk/tests.mk src/liballoc/arc.rs src/liballoc/boxed.rs src/liballoc/rc.rs src/libcollections/bit.rs src/libcollections/btree/map.rs src/libcollections/btree/set.rs src/libcollections/dlist.rs src/libcollections/ring_buf.rs src/libcollections/slice.rs src/libcollections/str.rs src/libcollections/string.rs src/libcollections/vec.rs src/libcollections/vec_map.rs src/libcore/any.rs src/libcore/array.rs src/libcore/borrow.rs src/libcore/error.rs src/libcore/fmt/mod.rs src/libcore/iter.rs src/libcore/marker.rs src/libcore/ops.rs src/libcore/result.rs src/libcore/slice.rs src/libcore/str/mod.rs src/libregex/lib.rs src/libregex/re.rs src/librustc/lint/builtin.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/mutex.rs src/libstd/sync/poison.rs src/libstd/sync/rwlock.rs src/libsyntax/feature_gate.rs src/libsyntax/test.rs
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/bit.rs | 8 | ||||
| -rw-r--r-- | src/libcollections/btree/map.rs | 4 | ||||
| -rw-r--r-- | src/libcollections/btree/node.rs | 21 | ||||
| -rw-r--r-- | src/libcollections/btree/set.rs | 9 | ||||
| -rw-r--r-- | src/libcollections/dlist.rs | 4 | ||||
| -rw-r--r-- | src/libcollections/enum_set.rs | 2 | ||||
| -rw-r--r-- | src/libcollections/macros.rs | 16 | ||||
| -rw-r--r-- | src/libcollections/ring_buf.rs | 10 | ||||
| -rw-r--r-- | src/libcollections/slice.rs | 100 | ||||
| -rw-r--r-- | src/libcollections/str.rs | 83 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 47 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 22 | ||||
| -rw-r--r-- | src/libcollections/vec_map.rs | 4 |
13 files changed, 155 insertions, 175 deletions
diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 5ce88fff53a..2c9a502a209 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -331,7 +331,7 @@ impl Bitv { if extra_bytes > 0 { let mut last_word = 0u32; - for (i, &byte) in bytes[(complete_words*4)..].iter().enumerate() { + for (i, &byte) in bytes[complete_words*4..].iter().enumerate() { last_word |= (reverse_bits(byte) as u32) << (i * 8); } bitv.storage.push(last_word); @@ -974,7 +974,7 @@ impl Ord for Bitv { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Show for Bitv { +impl fmt::Debug for Bitv { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { for bit in self.iter() { try!(write!(fmt, "{}", if bit { 1u32 } else { 0u32 })); @@ -1730,7 +1730,7 @@ impl BitvSet { } } -impl fmt::Show for BitvSet { +impl fmt::Debug for BitvSet { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "BitvSet {{")); let mut first = true; @@ -2625,7 +2625,7 @@ mod bitv_set_test { s.insert(10); s.insert(50); s.insert(2); - assert_eq!("BitvSet {1u, 2u, 10u, 50u}", format!("{:?}", s)); + assert_eq!("BitvSet {1, 2, 10, 50}", format!("{:?}", s)); } #[test] diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 8749c12abdb..17d26ed1a21 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -22,7 +22,7 @@ use core::prelude::*; use core::borrow::BorrowFrom; use core::cmp::Ordering; use core::default::Default; -use core::fmt::Show; +use core::fmt::Debug; use core::hash::{Hash, Hasher}; use core::iter::{Map, FromIterator}; use core::ops::{Index, IndexMut}; @@ -874,7 +874,7 @@ impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<K: Show, V: Show> Show for BTreeMap<K, V> { +impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "BTreeMap {{")); diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index 77dfac28935..95e424fb7a0 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -21,7 +21,7 @@ use core::prelude::*; use core::borrow::BorrowFrom; use core::cmp::Ordering::{Greater, Less, Equal}; use core::iter::Zip; -use core::ops::{Deref, DerefMut}; +use core::ops::{Deref, DerefMut, Index, IndexMut}; use core::ptr::Unique; use core::{slice, mem, ptr, cmp, num, raw}; use alloc::heap; @@ -1487,7 +1487,7 @@ impl<K, V, E, Impl> AbsTraversal<Impl> macro_rules! node_slice_impl { ($NodeSlice:ident, $Traversal:ident, - $as_slices_internal:ident, $slice_from:ident, $slice_to:ident, $iter:ident) => { + $as_slices_internal:ident, $index:ident, $iter:ident) => { impl<'a, K: Ord + 'a, V: 'a> $NodeSlice<'a, K, V> { /// Performs linear search in a slice. Returns a tuple of (index, is_exact_match). fn search_linear<Q: ?Sized>(&self, key: &Q) -> (uint, bool) @@ -1521,10 +1521,10 @@ macro_rules! node_slice_impl { edges: if !self.has_edges { self.edges } else { - self.edges.$slice_from(pos) + self.edges.$index(&(pos ..)) }, - keys: self.keys.slice_from(pos), - vals: self.vals.$slice_from(pos), + keys: &self.keys[pos ..], + vals: self.vals.$index(&(pos ..)), head_is_edge: !pos_is_kv, tail_is_edge: self.tail_is_edge, } @@ -1550,10 +1550,10 @@ macro_rules! node_slice_impl { edges: if !self.has_edges { self.edges } else { - self.edges.$slice_to(pos + 1) + self.edges.$index(&(.. (pos + 1))) }, - keys: self.keys.slice_to(pos), - vals: self.vals.$slice_to(pos), + keys: &self.keys[..pos], + vals: self.vals.$index(&(.. pos)), head_is_edge: self.head_is_edge, tail_is_edge: !pos_is_kv, } @@ -1583,6 +1583,5 @@ macro_rules! node_slice_impl { } } -node_slice_impl!(NodeSlice, Traversal, as_slices_internal, slice_from, slice_to, iter); -node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, slice_from_mut, - slice_to_mut, iter_mut); +node_slice_impl!(NodeSlice, Traversal, as_slices_internal, index, iter); +node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, index_mut, iter_mut); diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index ef48074be49..e95087fa846 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -16,11 +16,8 @@ use core::prelude::*; use core::borrow::BorrowFrom; use core::cmp::Ordering::{self, Less, Greater, Equal}; use core::default::Default; -use core::fmt::Show; +use core::fmt::Debug; use core::fmt; -// NOTE(stage0) remove import after a snapshot -#[cfg(stage0)] -use core::hash::Hash; use core::iter::{Peekable, Map, FromIterator}; use core::ops::{BitOr, BitAnd, BitXor, Sub}; @@ -594,7 +591,7 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Show> Show for BTreeSet<T> { +impl<T: Debug> Debug for BTreeSet<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "BTreeSet {{")); @@ -894,7 +891,7 @@ mod test { let set_str = format!("{:?}", set); - assert_eq!(set_str, "BTreeSet {1i, 2i}"); + assert_eq!(set_str, "BTreeSet {1, 2}"); assert_eq!(format!("{:?}", empty), "BTreeSet {}"); } } diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index b580dfbdbf9..08f7cea4e92 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -876,7 +876,7 @@ impl<A: Clone> Clone for DList<A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<A: fmt::Show> fmt::Show for DList<A> { +impl<A: fmt::Debug> fmt::Debug for DList<A> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "DList [")); @@ -1335,7 +1335,7 @@ mod tests { #[test] fn test_show() { let list: DList<int> = range(0i, 10).collect(); - assert_eq!(format!("{:?}", list), "DList [0i, 1i, 2i, 3i, 4i, 5i, 6i, 7i, 8i, 9i]"); + assert_eq!(format!("{:?}", list), "DList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); let list: DList<&str> = vec!["just", "one", "test", "more"].iter() .map(|&s| s) diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index fddea51c534..f36da6f82eb 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -31,7 +31,7 @@ pub struct EnumSet<E> { impl<E> Copy for EnumSet<E> {} -impl<E:CLike+fmt::Show> fmt::Show for EnumSet<E> { +impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "EnumSet {{")); let mut first = true; diff --git a/src/libcollections/macros.rs b/src/libcollections/macros.rs index 15ab7be7d90..15048998592 100644 --- a/src/libcollections/macros.rs +++ b/src/libcollections/macros.rs @@ -12,13 +12,13 @@ #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] macro_rules! vec { - ($x:expr; $y:expr) => ({ - let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$x; $y]); - $crate::slice::SliceExt::into_vec(xs) - }); - ($($x:expr),*) => ({ - let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$($x),*]); - $crate::slice::SliceExt::into_vec(xs) - }); + ($x:expr; $y:expr) => ( + <[_] as $crate::slice::SliceExt>::into_vec( + $crate::boxed::Box::new([$x; $y])) + ); + ($($x:expr),*) => ( + <[_] as $crate::slice::SliceExt>::into_vec( + $crate::boxed::Box::new([$($x),*])) + ); ($($x:expr,)*) => (vec![$($x),*]) } diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index ff20716a1ab..2e3f6198112 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -581,7 +581,7 @@ impl<T> RingBuf<T> { if contiguous { let (empty, buf) = buf.split_at_mut(0); - (buf.slice_mut(tail, head), empty) + (&mut buf[tail .. head], empty) } else { let (mid, right) = buf.split_at_mut(tail); let (left, _) = mid.split_at_mut(head); @@ -1619,7 +1619,7 @@ impl<A> Extend<A> for RingBuf<A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: fmt::Show> fmt::Show for RingBuf<T> { +impl<T: fmt::Debug> fmt::Debug for RingBuf<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "RingBuf [")); @@ -1638,7 +1638,7 @@ mod tests { use self::Taggypar::*; use prelude::*; use core::iter; - use std::fmt::Show; + use std::fmt::Debug; use std::hash::{self, SipHasher}; use test::Bencher; use test; @@ -1686,7 +1686,7 @@ mod tests { } #[cfg(test)] - fn test_parameterized<T:Clone + PartialEq + Show>(a: T, b: T, c: T, d: T) { + fn test_parameterized<T:Clone + PartialEq + Debug>(a: T, b: T, c: T, d: T) { let mut deq = RingBuf::new(); assert_eq!(deq.len(), 0); deq.push_front(a.clone()); @@ -2310,7 +2310,7 @@ mod tests { #[test] fn test_show() { let ringbuf: RingBuf<int> = range(0i, 10).collect(); - assert_eq!(format!("{:?}", ringbuf), "RingBuf [0i, 1i, 2i, 3i, 4i, 5i, 6i, 7i, 8i, 9i]"); + assert_eq!(format!("{:?}", ringbuf), "RingBuf [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter() .map(|&s| s) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index ae34c2de5d2..dff95711d49 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -170,32 +170,22 @@ pub trait SliceExt { reason = "uncertain about this API approach")] fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint; - /// Returns a subslice spanning the interval [`start`, `end`). - /// - /// Panics when the end of the new slice lies beyond the end of the - /// original slice (i.e. when `end > self.len()`) or when `start > end`. - /// - /// Slicing with `start` equal to `end` yields an empty slice. + /// Deprecated: use `&s[start .. end]` notation instead. #[unstable(feature = "collections", reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &s[start .. end] instead")] fn slice(&self, start: uint, end: uint) -> &[Self::Item]; - /// Returns a subslice from `start` to the end of the slice. - /// - /// Panics when `start` is strictly greater than the length of the original slice. - /// - /// Slicing from `self.len()` yields an empty slice. + /// Deprecated: use `&s[start..]` notation instead. #[unstable(feature = "collections", reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &s[start..] isntead")] fn slice_from(&self, start: uint) -> &[Self::Item]; - /// Returns a subslice from the start of the slice to `end`. - /// - /// Panics when `end` is strictly greater than the length of the original slice. - /// - /// Slicing to `0` yields an empty slice. + /// Deprecated: use `&s[..end]` notation instead. #[unstable(feature = "collections", reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &s[..end] instead")] fn slice_to(&self, end: uint) -> &[Self::Item]; /// Divides one slice into two at an index. @@ -382,32 +372,22 @@ pub trait SliceExt { #[stable(feature = "rust1", since = "1.0.0")] fn as_mut_slice(&mut self) -> &mut [Self::Item]; - /// Returns a mutable subslice spanning the interval [`start`, `end`). - /// - /// Panics when the end of the new slice lies beyond the end of the - /// original slice (i.e. when `end > self.len()`) or when `start > end`. - /// - /// Slicing with `start` equal to `end` yields an empty slice. + /// Deprecated: use `&mut s[start .. end]` instead. #[unstable(feature = "collections", reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &mut s[start .. end] instead")] fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item]; - /// Returns a mutable subslice from `start` to the end of the slice. - /// - /// Panics when `start` is strictly greater than the length of the original slice. - /// - /// Slicing from `self.len()` yields an empty slice. + /// Deprecated: use `&mut s[start ..]` instead. #[unstable(feature = "collections", reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &mut s[start ..] instead")] fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item]; - /// Returns a mutable subslice from the start of the slice to `end`. - /// - /// Panics when `end` is strictly greater than the length of the original slice. - /// - /// Slicing to `0` yields an empty slice. + /// Deprecated: use `&mut s[.. end]` instead. #[unstable(feature = "collections", reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &mut s[.. end] instead")] fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item]; /// Returns an iterator that allows modifying each value @@ -724,7 +704,7 @@ impl<T> SliceExt for [T] { #[inline] fn move_from(&mut self, mut src: Vec<T>, start: uint, end: uint) -> uint { - for (a, b) in self.iter_mut().zip(src.slice_mut(start, end).iter_mut()) { + for (a, b) in self.iter_mut().zip(src[start .. end].iter_mut()) { mem::swap(a, b); } cmp::min(self.len(), end-start) @@ -732,17 +712,17 @@ impl<T> SliceExt for [T] { #[inline] fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] { - core_slice::SliceExt::slice(self, start, end) + &self[start .. end] } #[inline] fn slice_from<'a>(&'a self, start: uint) -> &'a [T] { - core_slice::SliceExt::slice_from(self, start) + &self[start ..] } #[inline] fn slice_to<'a>(&'a self, end: uint) -> &'a [T] { - core_slice::SliceExt::slice_to(self, end) + &self[.. end] } #[inline] @@ -846,17 +826,17 @@ impl<T> SliceExt for [T] { #[inline] fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] { - core_slice::SliceExt::slice_mut(self, start, end) + &mut self[start .. end] } #[inline] fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] { - core_slice::SliceExt::slice_from_mut(self, start) + &mut self[start ..] } #[inline] fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] { - core_slice::SliceExt::slice_to_mut(self, end) + &mut self[.. end] } #[inline] @@ -1005,11 +985,30 @@ impl<T> SliceExt for [T] { /// An extension trait for concatenating slices pub trait SliceConcatExt<T: ?Sized, U> { /// Flattens a slice of `T` into a single value `U`. + /// + /// # Examples + /// + /// ``` + /// let v = vec!["hello", "world"]; + /// + /// let s: String = v.concat(); + /// + /// println!("{}", s); // prints "helloworld" + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn concat(&self) -> U; - /// Flattens a slice of `T` into a single value `U`, placing a - /// given separator between each. + /// Flattens a slice of `T` into a single value `U`, placing a given separator between each. + /// + /// # Examples + /// + /// ``` + /// let v = vec!["hello", "world"]; + /// + /// let s: String = v.connect(" "); + /// + /// println!("{}", s); // prints "hello world" + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn connect(&self, sep: &T) -> U; } @@ -2421,8 +2420,12 @@ mod tests { #[test] fn test_chunksator() { + use core::iter::ExactSizeIterator; + let v = &[1i,2,3,4,5]; + assert_eq!(v.chunks(2).len(), 3); + let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]]; assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks); let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]]; @@ -2488,19 +2491,19 @@ mod tests { } let empty: Vec<int> = vec![]; test_show_vec!(empty, "[]"); - test_show_vec!(vec![1i], "[1i]"); - test_show_vec!(vec![1i, 2, 3], "[1i, 2i, 3i]"); + test_show_vec!(vec![1i], "[1]"); + test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]"); test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]], - "[[], [1u], [1u, 1u]]"); + "[[], [1], [1, 1]]"); let empty_mut: &mut [int] = &mut[]; test_show_vec!(empty_mut, "[]"); let v: &mut[int] = &mut[1]; - test_show_vec!(v, "[1i]"); + test_show_vec!(v, "[1]"); let v: &mut[int] = &mut[1, 2, 3]; - test_show_vec!(v, "[1i, 2i, 3i]"); + test_show_vec!(v, "[1, 2, 3]"); let v: &mut [&mut[uint]] = &mut[&mut[], &mut[1u], &mut[1u, 1u]]; - test_show_vec!(v, "[[], [1u], [1u, 1u]]"); + test_show_vec!(v, "[[], [1], [1, 1]]"); } #[test] @@ -2687,7 +2690,10 @@ mod tests { #[test] fn test_mut_chunks() { + use core::iter::ExactSizeIterator; + let mut v = [0u8, 1, 2, 3, 4, 5, 6]; + assert_eq!(v.chunks_mut(2).len(), 4); for (i, chunk) in v.chunks_mut(3).enumerate() { for x in chunk.iter_mut() { *x = i as u8; diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 200637bb399..63ae743b421 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -759,70 +759,23 @@ pub trait StrExt: Index<FullRange, Output = str> { core_str::StrExt::lines_any(&self[]) } - /// Returns a slice of the given string from the byte range - /// [`begin`..`end`). - /// - /// This operation is `O(1)`. - /// - /// Panics when `begin` and `end` do not point to valid characters - /// or point beyond the last character of the string. - /// - /// See also `slice_to` and `slice_from` for slicing prefixes and - /// suffixes of strings, and `slice_chars` for slicing based on - /// code point counts. - /// - /// # Example - /// - /// ```rust - /// let s = "Löwe 老虎 Léopard"; - /// assert_eq!(s.slice(0, 1), "L"); - /// - /// assert_eq!(s.slice(1, 9), "öwe 老"); - /// - /// // these will panic: - /// // byte 2 lies within `ö`: - /// // s.slice(2, 3); - /// - /// // byte 8 lies within `老` - /// // s.slice(1, 8); - /// - /// // byte 100 is outside the string - /// // s.slice(3, 100); - /// ``` + /// Deprecated: use `s[a .. b]` instead. #[unstable(feature = "collections", reason = "use slice notation [a..b] instead")] - fn slice(&self, begin: uint, end: uint) -> &str { - core_str::StrExt::slice(&self[], begin, end) - } + #[deprecated(since = "1.0.0", reason = "use slice notation [a..b] instead")] + fn slice(&self, begin: uint, end: uint) -> &str; - /// Returns a slice of the string from `begin` to its end. - /// - /// Equivalent to `self.slice(begin, self.len())`. - /// - /// Panics when `begin` does not point to a valid character, or is - /// out of bounds. - /// - /// See also `slice`, `slice_to` and `slice_chars`. + /// Deprecated: use `s[a..]` instead. #[unstable(feature = "collections", - reason = "use slice notation [a..] instead")] - fn slice_from(&self, begin: uint) -> &str { - core_str::StrExt::slice_from(&self[], begin) - } + reason = "use slice notation [a..b] instead")] + #[deprecated(since = "1.0.0", reason = "use slice notation [a..] instead")] + fn slice_from(&self, begin: uint) -> &str; - /// Returns a slice of the string from the beginning to byte - /// `end`. - /// - /// Equivalent to `self.slice(0, end)`. - /// - /// Panics when `end` does not point to a valid character, or is - /// out of bounds. - /// - /// See also `slice`, `slice_from` and `slice_chars`. + /// Deprecated: use `s[..a]` instead. #[unstable(feature = "collections", - reason = "use slice notation [..a] instead")] - fn slice_to(&self, end: uint) -> &str { - core_str::StrExt::slice_to(&self[], end) - } + reason = "use slice notation [a..b] instead")] + #[deprecated(since = "1.0.0", reason = "use slice notation [..a] instead")] + fn slice_to(&self, end: uint) -> &str; /// Returns a slice of the string from the character range /// [`begin`..`end`). @@ -1374,7 +1327,19 @@ pub trait StrExt: Index<FullRange, Output = str> { } #[stable(feature = "rust1", since = "1.0.0")] -impl StrExt for str {} +impl StrExt for str { + fn slice(&self, begin: uint, end: uint) -> &str { + &self[begin..end] + } + + fn slice_from(&self, begin: uint) -> &str { + &self[begin..] + } + + fn slice_to(&self, end: uint) -> &str { + &self[..end] + } +} #[cfg(test)] mod tests { diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 00abe734d40..cdceca7176d 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -18,6 +18,7 @@ use core::prelude::*; use core::borrow::{Cow, IntoCow}; use core::default::Default; +use core::error::Error; use core::fmt; use core::hash; use core::iter::FromIterator; @@ -40,6 +41,7 @@ pub struct String { /// A possible error value from the `String::from_utf8` function. #[stable(feature = "rust1", since = "1.0.0")] +#[derive(Show)] pub struct FromUtf8Error { bytes: Vec<u8>, error: Utf8Error, @@ -48,6 +50,7 @@ pub struct FromUtf8Error { /// A possible error value from the `String::from_utf16` function. #[stable(feature = "rust1", since = "1.0.0")] #[allow(missing_copy_implementations)] +#[derive(Show)] pub struct FromUtf16Error(()); impl String { @@ -681,30 +684,28 @@ impl FromUtf8Error { pub fn utf8_error(&self) -> Utf8Error { self.error } } -impl fmt::Show for FromUtf8Error { +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Display for FromUtf8Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::String::fmt(self, f) + fmt::Display::fmt(&self.error, f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::String for FromUtf8Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::String::fmt(&self.error, f) - } +impl Error for FromUtf8Error { + fn description(&self) -> &str { "invalid utf-8" } } -impl fmt::Show for FromUtf16Error { +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Display for FromUtf16Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::String::fmt(self, f) + fmt::Display::fmt("invalid utf-16: lone surrogate found", f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::String for FromUtf16Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::String::fmt("invalid utf-16: lone surrogate found", f) - } +impl Error for FromUtf16Error { + fn description(&self) -> &str { "invalid utf-16" } } #[stable(feature = "rust1", since = "1.0.0")] @@ -817,18 +818,18 @@ impl Default for String { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::String for String { +impl fmt::Display for String { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::String::fmt(&**self, f) + fmt::Display::fmt(&**self, f) } } -#[unstable(feature = "collections", reason = "waiting on fmt stabilization")] -impl fmt::Show for String { +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for String { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Show::fmt(&**self, f) + fmt::Debug::fmt(&**self, f) } } @@ -852,6 +853,7 @@ impl<'a> Add<&'a str> for String { } } +#[stable(feature = "rust1", since = "1.0.0")] impl ops::Index<ops::Range<uint>> for String { type Output = str; #[inline] @@ -859,6 +861,7 @@ impl ops::Index<ops::Range<uint>> for String { &self[][*index] } } +#[stable(feature = "rust1", since = "1.0.0")] impl ops::Index<ops::RangeTo<uint>> for String { type Output = str; #[inline] @@ -866,6 +869,7 @@ impl ops::Index<ops::RangeTo<uint>> for String { &self[][*index] } } +#[stable(feature = "rust1", since = "1.0.0")] impl ops::Index<ops::RangeFrom<uint>> for String { type Output = str; #[inline] @@ -873,6 +877,7 @@ impl ops::Index<ops::RangeFrom<uint>> for String { &self[][*index] } } +#[stable(feature = "rust1", since = "1.0.0")] impl ops::Index<ops::FullRange> for String { type Output = str; #[inline] @@ -938,7 +943,7 @@ pub trait ToString { fn to_string(&self) -> String; } -impl<T: fmt::String + ?Sized> ToString for T { +impl<T: fmt::Display + ?Sized> ToString for T { #[inline] fn to_string(&self) -> String { use core::fmt::Writer; @@ -1299,10 +1304,10 @@ mod tests { fn test_vectors() { let x: Vec<int> = vec![]; assert_eq!(format!("{:?}", x), "[]"); - assert_eq!(format!("{:?}", vec![1i]), "[1i]"); - assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1i, 2i, 3i]"); + assert_eq!(format!("{:?}", vec![1i]), "[1]"); + assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1, 2, 3]"); assert!(format!("{:?}", vec![vec![], vec![1i], vec![1i, 1]]) == - "[[], [1i], [1i, 1i]]"); + "[[], [1], [1, 1]]"); } #[test] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 567157e7d8f..53f75a3e778 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1235,7 +1235,7 @@ impl<S: hash::Writer + hash::Hasher, T: Hash<S>> Hash<S> for Vec<T> { } } -#[unstable(feature = "collections", reason = "waiting on Index stability")] +#[stable(feature = "rust1", since = "1.0.0")] impl<T> Index<uint> for Vec<T> { type Output = T; @@ -1245,6 +1245,7 @@ impl<T> Index<uint> for Vec<T> { } } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> IndexMut<uint> for Vec<T> { type Output = T; @@ -1255,6 +1256,7 @@ impl<T> IndexMut<uint> for Vec<T> { } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::Index<ops::Range<uint>> for Vec<T> { type Output = [T]; #[inline] @@ -1262,6 +1264,7 @@ impl<T> ops::Index<ops::Range<uint>> for Vec<T> { self.as_slice().index(index) } } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> { type Output = [T]; #[inline] @@ -1269,6 +1272,7 @@ impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> { self.as_slice().index(index) } } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> { type Output = [T]; #[inline] @@ -1276,6 +1280,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> { self.as_slice().index(index) } } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::Index<ops::FullRange> for Vec<T> { type Output = [T]; #[inline] @@ -1284,6 +1289,7 @@ impl<T> ops::Index<ops::FullRange> for Vec<T> { } } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> { type Output = [T]; #[inline] @@ -1291,6 +1297,7 @@ impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> { self.as_mut_slice().index_mut(index) } } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> { type Output = [T]; #[inline] @@ -1298,6 +1305,7 @@ impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> { self.as_mut_slice().index_mut(index) } } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> { type Output = [T]; #[inline] @@ -1305,6 +1313,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> { self.as_mut_slice().index_mut(index) } } +#[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::IndexMut<ops::FullRange> for Vec<T> { type Output = [T]; #[inline] @@ -1313,7 +1322,6 @@ impl<T> ops::IndexMut<ops::FullRange> for Vec<T> { } } - #[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::Deref for Vec<T> { type Target = [T]; @@ -1494,10 +1502,10 @@ impl<T> Default for Vec<T> { } } -#[unstable(feature = "collections", reason = "waiting on Show stability")] -impl<T: fmt::Show> fmt::Show for Vec<T> { +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: fmt::Debug> fmt::Debug for Vec<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Show::fmt(self.as_slice(), f) + fmt::Debug::fmt(self.as_slice(), f) } } @@ -2168,7 +2176,7 @@ mod tests { #[should_fail] fn test_slice_out_of_bounds_1() { let x: Vec<int> = vec![1, 2, 3, 4, 5]; - &x[(-1)..]; + &x[-1..]; } #[test] @@ -2182,7 +2190,7 @@ mod tests { #[should_fail] fn test_slice_out_of_bounds_3() { let x: Vec<int> = vec![1, 2, 3, 4, 5]; - &x[(-1)..4]; + &x[-1..4]; } #[test] diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index f257d9a53e4..3d28284c9bf 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -514,7 +514,7 @@ impl<V: Ord> Ord for VecMap<V> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<V: fmt::Show> fmt::Show for VecMap<V> { +impl<V: fmt::Debug> fmt::Debug for VecMap<V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "VecMap {{")); @@ -991,7 +991,7 @@ mod test_map { map.insert(3, 4i); let map_str = format!("{:?}", map); - assert!(map_str == "VecMap {1: 2i, 3: 4i}" || map_str == "{3: 4i, 1: 2i}"); + assert!(map_str == "VecMap {1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); assert_eq!(format!("{:?}", empty), "VecMap {}"); } |
