From fbc93082ec92c3534c4b27fef35d78d97bd77fd2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 6 Aug 2014 20:03:55 -0700 Subject: [PATCH] std: Rename slice::Vector to Slice This required some contortions because importing both raw::Slice and slice::Slice makes rustc crash. Since `Slice` is in the prelude, this renaming is unlikely to casue breakage. [breaking-change] --- src/libcollections/slice.rs | 4 ++-- src/libcollections/string.rs | 11 +++++++---- src/libcollections/vec.rs | 13 +++++++------ src/libcore/fmt/mod.rs | 2 +- src/libcore/option.rs | 4 ++-- src/libcore/prelude.rs | 2 +- src/libcore/slice.rs | 26 ++++++++++++++------------ src/libgraphviz/maybe_owned_vec.rs | 4 ++-- src/librustc/front/test.rs | 2 +- src/libstd/ascii.rs | 2 +- src/libstd/c_vec.rs | 4 ++-- src/libstd/dynamic_lib.rs | 2 +- src/libstd/io/extensions.rs | 2 +- src/libstd/io/mem.rs | 2 +- src/libstd/io/mod.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/path/mod.rs | 2 +- src/libstd/path/posix.rs | 4 ++-- src/libstd/path/windows.rs | 2 +- src/libstd/prelude.rs | 2 +- 20 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index d73fa499848..9f4bdaf3da3 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -98,7 +98,7 @@ use vec::Vec; pub use core::slice::{ref_slice, mut_ref_slice, Splits, Windows}; -pub use core::slice::{Chunks, Vector, ImmutableSlice, ImmutableEqSlice}; +pub use core::slice::{Chunks, Slice, ImmutableSlice, ImmutableEqSlice}; pub use core::slice::{ImmutableOrdSlice, MutableSlice, Items, MutItems}; pub use core::slice::{MutSplits, MutChunks}; pub use core::slice::{bytes, MutableCloneableSlice}; @@ -116,7 +116,7 @@ pub trait VectorVector { fn connect_vec(&self, sep: &T) -> Vec; } -impl<'a, T: Clone, V: Vector> VectorVector for &'a [V] { +impl<'a, T: Clone, V: Slice> VectorVector for &'a [V] { fn concat_vec(&self) -> Vec { let size = self.iter().fold(0u, |acc, v| acc + v.as_slice().len()); let mut result = Vec::with_capacity(size); diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 952f28da2af..d8cc80fdf41 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -18,12 +18,15 @@ use core::fmt; use core::mem; use core::ptr; -use core::raw::Slice; +// FIXME: ICE's abound if you import the `Slice` type while importing `Slice` trait +use RawSlice = core::raw::Slice; +use core::slice::Slice; use {Collection, Mutable, MutableSeq}; use hash; use str; -use str::{CharRange, StrAllocating, MaybeOwned, Owned, Slice}; +use str::{CharRange, StrAllocating, MaybeOwned, Owned}; +use MaybeOwnedSlice = str::Slice; // So many `Slice`s... use vec::Vec; /// A growable string stored as a UTF-8 encoded buffer. @@ -130,7 +133,7 @@ pub fn from_utf8(vec: Vec) -> Result> { /// ``` pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> { if str::is_utf8(v) { - return Slice(unsafe { mem::transmute(v) }) + return MaybeOwnedSlice(unsafe { mem::transmute(v) }) } static TAG_CONT_U8: u8 = 128u8; @@ -496,7 +499,7 @@ pub fn push_char(&mut self, ch: char) { unsafe { // Attempt to not use an intermediate buffer by just pushing bytes // directly onto this string. - let slice = Slice { + let slice = RawSlice { data: self.vec.as_ptr().offset(cur_len as int), len: 4, }; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 4c1530d1bfb..78809e32fe9 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -13,7 +13,8 @@ use core::prelude::*; use alloc::heap::{allocate, reallocate, deallocate}; -use core::raw::Slice; +use RawSlice = core::raw::Slice; +use core::slice::Slice; use core::cmp::max; use core::default::Default; use core::fmt; @@ -506,7 +507,7 @@ fn partial_cmp(&self, other: &Vec) -> Option { impl Eq for Vec {} -impl> Equiv for Vec { +impl> Equiv for Vec { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } @@ -720,7 +721,7 @@ pub fn truncate(&mut self, len: uint) { #[inline] pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { unsafe { - mem::transmute(Slice { + mem::transmute(RawSlice { data: self.as_mut_ptr() as *const T, len: self.len, }) @@ -1502,7 +1503,7 @@ pub fn dedup(&mut self) { } } -impl Vector for Vec { +impl Slice for Vec { /// Work with `self` as a slice. /// /// # Example @@ -1515,11 +1516,11 @@ impl Vector for Vec { /// ``` #[inline] fn as_slice<'a>(&'a self) -> &'a [T] { - unsafe { mem::transmute(Slice { data: self.as_ptr(), len: self.len }) } + unsafe { mem::transmute(RawSlice { data: self.as_ptr(), len: self.len }) } } } -impl> Add> for Vec { +impl> Add> for Vec { #[inline] fn add(&self, rhs: &V) -> Vec { let mut res = Vec::with_capacity(self.len() + rhs.as_slice().len()); diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 61f0d09453f..942f7f8b710 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -24,7 +24,7 @@ use ops::Deref; use result::{Ok, Err}; use result; -use slice::{Vector, ImmutableSlice}; +use slice::{Slice, ImmutableSlice}; use slice; use str::StrSlice; use str; diff --git a/src/libcore/option.rs b/src/libcore/option.rs index f8293aeb03d..74d87712a02 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -143,7 +143,7 @@ use cmp::{PartialEq, Eq, Ord}; use default::Default; -use slice::Vector; +use slice::Slice; use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize}; use mem; use slice; @@ -518,7 +518,7 @@ pub fn unwrap_or_default(self) -> T { // Trait implementations ///////////////////////////////////////////////////////////////////////////// -impl Vector for Option { +impl Slice for Option { /// Convert from `Option` to `&[T]` (without copying) #[inline] fn as_slice<'a>(&'a self) -> &'a [T] { diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 08a431b0d1f..2d5c9c0e960 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -63,4 +63,4 @@ pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12}; pub use slice::{ImmutableEqSlice, ImmutableOrdSlice}; pub use slice::{MutableSlice}; -pub use slice::{Vector, ImmutableSlice}; +pub use slice::{Slice, ImmutableSlice}; diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 6c8bacaef48..3a619b45e53 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -47,7 +47,9 @@ use mem; use mem::size_of; use kinds::marker; -use raw::{Repr, Slice}; +use raw::{Repr}; +// Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module. +use RawSlice = raw::Slice; // // Extension traits @@ -240,7 +242,7 @@ fn slice(&self, start: uint, end: uint) -> &'a [T] { assert!(start <= end); assert!(end <= self.len()); unsafe { - transmute(Slice { + transmute(RawSlice { data: self.as_ptr().offset(start as int), len: (end - start) }) @@ -380,7 +382,7 @@ fn bsearch(&self, f: |&T| -> Ordering) -> Option { fn shift_ref(&mut self) -> Option<&'a T> { unsafe { - let s: &mut Slice = transmute(self); + let s: &mut RawSlice = transmute(self); match raw::shift_ptr(s) { Some(p) => Some(&*p), None => None @@ -390,7 +392,7 @@ fn shift_ref(&mut self) -> Option<&'a T> { fn pop_ref(&mut self) -> Option<&'a T> { unsafe { - let s: &mut Slice = transmute(self); + let s: &mut RawSlice = transmute(self); match raw::pop_ptr(s) { Some(p) => Some(&*p), None => None @@ -620,7 +622,7 @@ fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] { assert!(start <= end); assert!(end <= self.len()); unsafe { - transmute(Slice { + transmute(RawSlice { data: self.as_mut_ptr().offset(start as int) as *const T, len: (end - start) }) @@ -685,7 +687,7 @@ fn mut_chunks(self, chunk_size: uint) -> MutChunks<'a, T> { fn mut_shift_ref(&mut self) -> Option<&'a mut T> { unsafe { - let s: &mut Slice = transmute(self); + let s: &mut RawSlice = transmute(self); match raw::shift_ptr(s) { // FIXME #13933: this `&` -> `&mut` cast is a little // dubious @@ -697,7 +699,7 @@ fn mut_shift_ref(&mut self) -> Option<&'a mut T> { fn mut_pop_ref(&mut self) -> Option<&'a mut T> { unsafe { - let s: &mut Slice = transmute(self); + let s: &mut RawSlice = transmute(self); match raw::pop_ptr(s) { // FIXME #13933: this `&` -> `&mut` cast is a little // dubious @@ -859,12 +861,12 @@ fn copy_from(self, src: &[T]) -> uint { // /// Any vector that can be represented as a slice. -pub trait Vector { +pub trait Slice { /// Work with `self` as a slice. fn as_slice<'a>(&'a self) -> &'a [T]; } -impl<'a,T> Vector for &'a [T] { +impl<'a,T> Slice for &'a [T] { #[inline(always)] fn as_slice<'a>(&'a self) -> &'a [T] { *self } } @@ -1323,7 +1325,7 @@ fn next_back(&mut self) -> Option<&'a mut [T]> { */ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] { unsafe { - transmute(Slice { data: s, len: 1 }) + transmute(RawSlice { data: s, len: 1 }) } } @@ -1333,7 +1335,7 @@ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] { pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] { unsafe { let ptr: *const A = transmute(s); - transmute(Slice { data: ptr, len: 1 }) + transmute(RawSlice { data: ptr, len: 1 }) } } @@ -1460,7 +1462,7 @@ fn ne(&self, other: & &'a [T]) -> bool { impl<'a,T:Eq> Eq for &'a [T] {} -impl<'a,T:PartialEq, V: Vector> Equiv for &'a [T] { +impl<'a,T:PartialEq, V: Slice> Equiv for &'a [T] { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index 9e52af72138..987f214b153 100644 --- a/src/libgraphviz/maybe_owned_vec.rs +++ b/src/libgraphviz/maybe_owned_vec.rs @@ -84,7 +84,7 @@ fn cmp(&self, other: &MaybeOwnedVector) -> Ordering { } } -impl<'a, T: PartialEq, V: Vector> Equiv for MaybeOwnedVector<'a, T> { +impl<'a, T: PartialEq, V: Slice> Equiv for MaybeOwnedVector<'a, T> { fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } @@ -99,7 +99,7 @@ fn equiv(&self, other: &V) -> bool { // In any case, with `Vector` in place, the client can just use // `as_slice` if they prefer that over `match`. -impl<'b,T> slice::Vector for MaybeOwnedVector<'b,T> { +impl<'b,T> Slice for MaybeOwnedVector<'b,T> { fn as_slice<'a>(&'a self) -> &'a [T] { match self { &Growable(ref v) => v.as_slice(), diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 14cda7d62c3..ceb7dcc5456 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -379,7 +379,7 @@ fn mk_test_module(cx: &TestCtxt, reexport_test_harness_main: &Option { @@ -145,7 +145,7 @@ pub unsafe fn unwrap(mut self) -> *mut T { } } -impl Vector for CVec { +impl Slice for CVec { /// View the stored data as a slice. fn as_slice<'a>(&'a self) -> &'a [T] { unsafe { diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index f3bdd987122..766f92292b1 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -29,7 +29,7 @@ use os; use path::{Path,GenericPath}; use result::*; -use slice::{Vector,ImmutableSlice}; +use slice::{Slice,ImmutableSlice}; use str; use string::String; use vec::Vec; diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index c40ea749376..12caa715865 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -21,7 +21,7 @@ use result::{Ok, Err}; use io; use io::{IoError, IoResult, Reader}; -use slice::{ImmutableSlice, Vector}; +use slice::{ImmutableSlice, Slice}; use ptr::RawPtr; /// An iterator that reads a single byte on each iteration, diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index e6866f45948..ea9d08171e6 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -19,7 +19,7 @@ use io; use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult}; use slice; -use slice::{Vector, ImmutableSlice, MutableSlice}; +use slice::{Slice, ImmutableSlice, MutableSlice}; use vec::Vec; static BUF_CAPACITY: uint = 128; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index fa21c108ea3..c95dd8618ed 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -235,7 +235,7 @@ fn file_product(p: &Path) -> IoResult { use boxed::Box; use result::{Ok, Err, Result}; use rt::rtio; -use slice::{Vector, MutableSlice, ImmutableSlice}; +use slice::{Slice, MutableSlice, ImmutableSlice}; use str::{Str, StrSlice}; use str; use string::String; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 0d604aab8ac..6f148eea83c 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -45,7 +45,7 @@ use ptr::RawPtr; use ptr; use result::{Err, Ok, Result}; -use slice::{Vector, ImmutableSlice, MutableSlice, ImmutableEqSlice}; +use slice::{Slice, ImmutableSlice, MutableSlice, ImmutableEqSlice}; use str::{Str, StrSlice, StrAllocating}; use string::String; use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst}; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 087b3e4c53f..16236c01472 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -74,7 +74,7 @@ use str; use str::{MaybeOwned, Str, StrSlice}; use string::String; -use slice::Vector; +use slice::Slice; use slice::{ImmutableEqSlice, ImmutableSlice}; use vec::Vec; diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 81abf3e7669..321ec438c20 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -21,7 +21,7 @@ use option::{Option, None, Some}; use str::Str; use str; -use slice::{CloneableVector, Splits, Vector, VectorVector, +use slice::{CloneableVector, Splits, Slice, VectorVector, ImmutableEqSlice, ImmutableSlice}; use vec::Vec; @@ -367,7 +367,7 @@ pub fn new_opt(path: T) -> Option { /// Returns a normalized byte vector representation of a path, by removing all empty /// components, and unnecessary . and .. components. - fn normalize+CloneableVector>(v: V) -> Vec { + fn normalize+CloneableVector>(v: V) -> Vec { // borrowck is being very picky let val = { let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == SEP_BYTE; diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index ca8eae769bb..8402d751bf2 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -23,7 +23,7 @@ use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Iterator, Map}; use mem; use option::{Option, Some, None}; -use slice::{Vector, ImmutableSlice}; +use slice::{Slice, ImmutableSlice}; use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice}; use string::String; use unicode::char::UnicodeChar; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index d5d24d17d86..3d4ab66a94f 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -86,7 +86,7 @@ #[doc(no_inline)] pub use slice::{MutableCloneableSlice, MutableOrdSlice}; #[doc(no_inline)] pub use slice::{ImmutableSlice, MutableSlice}; #[doc(no_inline)] pub use slice::{ImmutableEqSlice, ImmutableOrdSlice}; -#[doc(no_inline)] pub use slice::{Vector, VectorVector}; +#[doc(no_inline)] pub use slice::{Slice, VectorVector}; #[doc(no_inline)] pub use slice::MutableSliceAllocating; #[doc(no_inline)] pub use string::String; #[doc(no_inline)] pub use vec::Vec; -- 2.44.0