Skip to content

Commit fbc9308

Browse files
committed
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]
1 parent 4f5b692 commit fbc9308

File tree

20 files changed

+50
-44
lines changed

20 files changed

+50
-44
lines changed

src/libcollections/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ use {Collection, MutableSeq};
9898
use vec::Vec;
9999

100100
pub use core::slice::{ref_slice, mut_ref_slice, Splits, Windows};
101-
pub use core::slice::{Chunks, Vector, ImmutableSlice, ImmutableEqSlice};
101+
pub use core::slice::{Chunks, Slice, ImmutableSlice, ImmutableEqSlice};
102102
pub use core::slice::{ImmutableOrdSlice, MutableSlice, Items, MutItems};
103103
pub use core::slice::{MutSplits, MutChunks};
104104
pub use core::slice::{bytes, MutableCloneableSlice};
@@ -116,7 +116,7 @@ pub trait VectorVector<T> {
116116
fn connect_vec(&self, sep: &T) -> Vec<T>;
117117
}
118118

119-
impl<'a, T: Clone, V: Vector<T>> VectorVector<T> for &'a [V] {
119+
impl<'a, T: Clone, V: Slice<T>> VectorVector<T> for &'a [V] {
120120
fn concat_vec(&self) -> Vec<T> {
121121
let size = self.iter().fold(0u, |acc, v| acc + v.as_slice().len());
122122
let mut result = Vec::with_capacity(size);

src/libcollections/string.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ use core::default::Default;
1818
use core::fmt;
1919
use core::mem;
2020
use core::ptr;
21-
use core::raw::Slice;
21+
// FIXME: ICE's abound if you import the `Slice` type while importing `Slice` trait
22+
use RawSlice = core::raw::Slice;
23+
use core::slice::Slice;
2224

2325
use {Collection, Mutable, MutableSeq};
2426
use hash;
2527
use str;
26-
use str::{CharRange, StrAllocating, MaybeOwned, Owned, Slice};
28+
use str::{CharRange, StrAllocating, MaybeOwned, Owned};
29+
use MaybeOwnedSlice = str::Slice; // So many `Slice`s...
2730
use vec::Vec;
2831

2932
/// A growable string stored as a UTF-8 encoded buffer.
@@ -130,7 +133,7 @@ impl String {
130133
/// ```
131134
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
132135
if str::is_utf8(v) {
133-
return Slice(unsafe { mem::transmute(v) })
136+
return MaybeOwnedSlice(unsafe { mem::transmute(v) })
134137
}
135138

136139
static TAG_CONT_U8: u8 = 128u8;
@@ -496,7 +499,7 @@ impl String {
496499
unsafe {
497500
// Attempt to not use an intermediate buffer by just pushing bytes
498501
// directly onto this string.
499-
let slice = Slice {
502+
let slice = RawSlice {
500503
data: self.vec.as_ptr().offset(cur_len as int),
501504
len: 4,
502505
};

src/libcollections/vec.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
use core::prelude::*;
1414

1515
use alloc::heap::{allocate, reallocate, deallocate};
16-
use core::raw::Slice;
16+
use RawSlice = core::raw::Slice;
17+
use core::slice::Slice;
1718
use core::cmp::max;
1819
use core::default::Default;
1920
use core::fmt;
@@ -506,7 +507,7 @@ impl<T: PartialOrd> PartialOrd for Vec<T> {
506507

507508
impl<T: Eq> Eq for Vec<T> {}
508509

509-
impl<T: PartialEq, V: Vector<T>> Equiv<V> for Vec<T> {
510+
impl<T: PartialEq, V: Slice<T>> Equiv<V> for Vec<T> {
510511
#[inline]
511512
fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() }
512513
}
@@ -720,7 +721,7 @@ impl<T> Vec<T> {
720721
#[inline]
721722
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
722723
unsafe {
723-
mem::transmute(Slice {
724+
mem::transmute(RawSlice {
724725
data: self.as_mut_ptr() as *const T,
725726
len: self.len,
726727
})
@@ -1502,7 +1503,7 @@ impl<T:PartialEq> Vec<T> {
15021503
}
15031504
}
15041505

1505-
impl<T> Vector<T> for Vec<T> {
1506+
impl<T> Slice<T> for Vec<T> {
15061507
/// Work with `self` as a slice.
15071508
///
15081509
/// # Example
@@ -1515,11 +1516,11 @@ impl<T> Vector<T> for Vec<T> {
15151516
/// ```
15161517
#[inline]
15171518
fn as_slice<'a>(&'a self) -> &'a [T] {
1518-
unsafe { mem::transmute(Slice { data: self.as_ptr(), len: self.len }) }
1519+
unsafe { mem::transmute(RawSlice { data: self.as_ptr(), len: self.len }) }
15191520
}
15201521
}
15211522

1522-
impl<T: Clone, V: Vector<T>> Add<V, Vec<T>> for Vec<T> {
1523+
impl<T: Clone, V: Slice<T>> Add<V, Vec<T>> for Vec<T> {
15231524
#[inline]
15241525
fn add(&self, rhs: &V) -> Vec<T> {
15251526
let mut res = Vec::with_capacity(self.len() + rhs.as_slice().len());

src/libcore/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use option::{Option, Some, None};
2424
use ops::Deref;
2525
use result::{Ok, Err};
2626
use result;
27-
use slice::{Vector, ImmutableSlice};
27+
use slice::{Slice, ImmutableSlice};
2828
use slice;
2929
use str::StrSlice;
3030
use str;

src/libcore/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
144144
use cmp::{PartialEq, Eq, Ord};
145145
use default::Default;
146-
use slice::Vector;
146+
use slice::Slice;
147147
use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize};
148148
use mem;
149149
use slice;
@@ -518,7 +518,7 @@ impl<T: Default> Option<T> {
518518
// Trait implementations
519519
/////////////////////////////////////////////////////////////////////////////
520520

521-
impl<T> Vector<T> for Option<T> {
521+
impl<T> Slice<T> for Option<T> {
522522
/// Convert from `Option<T>` to `&[T]` (without copying)
523523
#[inline]
524524
fn as_slice<'a>(&'a self) -> &'a [T] {

src/libcore/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
6363
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
6464
pub use slice::{ImmutableEqSlice, ImmutableOrdSlice};
6565
pub use slice::{MutableSlice};
66-
pub use slice::{Vector, ImmutableSlice};
66+
pub use slice::{Slice, ImmutableSlice};

src/libcore/slice.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ use ptr::RawPtr;
4747
use mem;
4848
use mem::size_of;
4949
use kinds::marker;
50-
use raw::{Repr, Slice};
50+
use raw::{Repr};
51+
// Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module.
52+
use RawSlice = raw::Slice;
5153

5254
//
5355
// Extension traits
@@ -240,7 +242,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
240242
assert!(start <= end);
241243
assert!(end <= self.len());
242244
unsafe {
243-
transmute(Slice {
245+
transmute(RawSlice {
244246
data: self.as_ptr().offset(start as int),
245247
len: (end - start)
246248
})
@@ -380,7 +382,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
380382

381383
fn shift_ref(&mut self) -> Option<&'a T> {
382384
unsafe {
383-
let s: &mut Slice<T> = transmute(self);
385+
let s: &mut RawSlice<T> = transmute(self);
384386
match raw::shift_ptr(s) {
385387
Some(p) => Some(&*p),
386388
None => None
@@ -390,7 +392,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
390392

391393
fn pop_ref(&mut self) -> Option<&'a T> {
392394
unsafe {
393-
let s: &mut Slice<T> = transmute(self);
395+
let s: &mut RawSlice<T> = transmute(self);
394396
match raw::pop_ptr(s) {
395397
Some(p) => Some(&*p),
396398
None => None
@@ -620,7 +622,7 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] {
620622
assert!(start <= end);
621623
assert!(end <= self.len());
622624
unsafe {
623-
transmute(Slice {
625+
transmute(RawSlice {
624626
data: self.as_mut_ptr().offset(start as int) as *const T,
625627
len: (end - start)
626628
})
@@ -685,7 +687,7 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] {
685687

686688
fn mut_shift_ref(&mut self) -> Option<&'a mut T> {
687689
unsafe {
688-
let s: &mut Slice<T> = transmute(self);
690+
let s: &mut RawSlice<T> = transmute(self);
689691
match raw::shift_ptr(s) {
690692
// FIXME #13933: this `&` -> `&mut` cast is a little
691693
// dubious
@@ -697,7 +699,7 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] {
697699

698700
fn mut_pop_ref(&mut self) -> Option<&'a mut T> {
699701
unsafe {
700-
let s: &mut Slice<T> = transmute(self);
702+
let s: &mut RawSlice<T> = transmute(self);
701703
match raw::pop_ptr(s) {
702704
// FIXME #13933: this `&` -> `&mut` cast is a little
703705
// dubious
@@ -859,12 +861,12 @@ impl<'a, T:Clone> MutableCloneableSlice<T> for &'a mut [T] {
859861
//
860862

861863
/// Any vector that can be represented as a slice.
862-
pub trait Vector<T> {
864+
pub trait Slice<T> {
863865
/// Work with `self` as a slice.
864866
fn as_slice<'a>(&'a self) -> &'a [T];
865867
}
866868

867-
impl<'a,T> Vector<T> for &'a [T] {
869+
impl<'a,T> Slice<T> for &'a [T] {
868870
#[inline(always)]
869871
fn as_slice<'a>(&'a self) -> &'a [T] { *self }
870872
}
@@ -1323,7 +1325,7 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> {
13231325
*/
13241326
pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
13251327
unsafe {
1326-
transmute(Slice { data: s, len: 1 })
1328+
transmute(RawSlice { data: s, len: 1 })
13271329
}
13281330
}
13291331

@@ -1333,7 +1335,7 @@ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
13331335
pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
13341336
unsafe {
13351337
let ptr: *const A = transmute(s);
1336-
transmute(Slice { data: ptr, len: 1 })
1338+
transmute(RawSlice { data: ptr, len: 1 })
13371339
}
13381340
}
13391341

@@ -1460,7 +1462,7 @@ impl<'a,T:PartialEq> PartialEq for &'a [T] {
14601462

14611463
impl<'a,T:Eq> Eq for &'a [T] {}
14621464

1463-
impl<'a,T:PartialEq, V: Vector<T>> Equiv<V> for &'a [T] {
1465+
impl<'a,T:PartialEq, V: Slice<T>> Equiv<V> for &'a [T] {
14641466
#[inline]
14651467
fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() }
14661468
}

src/libgraphviz/maybe_owned_vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a, T: Ord> Ord for MaybeOwnedVector<'a, T> {
8484
}
8585
}
8686

87-
impl<'a, T: PartialEq, V: Vector<T>> Equiv<V> for MaybeOwnedVector<'a, T> {
87+
impl<'a, T: PartialEq, V: Slice<T>> Equiv<V> for MaybeOwnedVector<'a, T> {
8888
fn equiv(&self, other: &V) -> bool {
8989
self.as_slice() == other.as_slice()
9090
}
@@ -99,7 +99,7 @@ impl<'a, T: PartialEq, V: Vector<T>> Equiv<V> for MaybeOwnedVector<'a, T> {
9999
// In any case, with `Vector` in place, the client can just use
100100
// `as_slice` if they prefer that over `match`.
101101

102-
impl<'b,T> slice::Vector<T> for MaybeOwnedVector<'b,T> {
102+
impl<'b,T> Slice<T> for MaybeOwnedVector<'b,T> {
103103
fn as_slice<'a>(&'a self) -> &'a [T] {
104104
match self {
105105
&Growable(ref v) => v.as_slice(),

src/librustc/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ fn mk_test_module(cx: &TestCtxt, reexport_test_harness_main: &Option<InternedStr
379379
let mainfn = (quote_item!(&cx.ext_cx,
380380
pub fn main() {
381381
#![main]
382-
use std::slice::Vector;
382+
use std::slice::Slice;
383383
test::test_main_static(::std::os::args().as_slice(), TESTS);
384384
}
385385
)).unwrap();

src/libstd/ascii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use fmt;
1919
use iter::Iterator;
2020
use mem;
2121
use option::{Option, Some, None};
22-
use slice::{ImmutableSlice, MutableSlice, Vector};
22+
use slice::{ImmutableSlice, MutableSlice, Slice};
2323
use str::{Str, StrSlice};
2424
use str;
2525
use string::String;

src/libstd/c_vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use option::{Option, Some, None};
4343
use ptr::RawPtr;
4444
use ptr;
4545
use raw;
46-
use slice::Vector;
46+
use slice::Slice;
4747

4848
/// The type representing a foreign chunk of memory
4949
pub struct CVec<T> {
@@ -145,7 +145,7 @@ impl<T> CVec<T> {
145145
}
146146
}
147147

148-
impl<T> Vector<T> for CVec<T> {
148+
impl<T> Slice<T> for CVec<T> {
149149
/// View the stored data as a slice.
150150
fn as_slice<'a>(&'a self) -> &'a [T] {
151151
unsafe {

src/libstd/dynamic_lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use option::*;
2929
use os;
3030
use path::{Path,GenericPath};
3131
use result::*;
32-
use slice::{Vector,ImmutableSlice};
32+
use slice::{Slice,ImmutableSlice};
3333
use str;
3434
use string::String;
3535
use vec::Vec;

src/libstd/io/extensions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use option::{Option, Some, None};
2121
use result::{Ok, Err};
2222
use io;
2323
use io::{IoError, IoResult, Reader};
24-
use slice::{ImmutableSlice, Vector};
24+
use slice::{ImmutableSlice, Slice};
2525
use ptr::RawPtr;
2626

2727
/// An iterator that reads a single byte on each iteration,

src/libstd/io/mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use result::{Err, Ok};
1919
use io;
2020
use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult};
2121
use slice;
22-
use slice::{Vector, ImmutableSlice, MutableSlice};
22+
use slice::{Slice, ImmutableSlice, MutableSlice};
2323
use vec::Vec;
2424

2525
static BUF_CAPACITY: uint = 128;

src/libstd/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ use os;
235235
use boxed::Box;
236236
use result::{Ok, Err, Result};
237237
use rt::rtio;
238-
use slice::{Vector, MutableSlice, ImmutableSlice};
238+
use slice::{Slice, MutableSlice, ImmutableSlice};
239239
use str::{Str, StrSlice};
240240
use str;
241241
use string::String;

src/libstd/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use path::{Path, GenericPath, BytesContainer};
4545
use ptr::RawPtr;
4646
use ptr;
4747
use result::{Err, Ok, Result};
48-
use slice::{Vector, ImmutableSlice, MutableSlice, ImmutableEqSlice};
48+
use slice::{Slice, ImmutableSlice, MutableSlice, ImmutableEqSlice};
4949
use str::{Str, StrSlice, StrAllocating};
5050
use string::String;
5151
use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};

src/libstd/path/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use option::{Option, None, Some};
7474
use str;
7575
use str::{MaybeOwned, Str, StrSlice};
7676
use string::String;
77-
use slice::Vector;
77+
use slice::Slice;
7878
use slice::{ImmutableEqSlice, ImmutableSlice};
7979
use vec::Vec;
8080

src/libstd/path/posix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use iter::{DoubleEndedIterator, AdditiveIterator, Extendable, Iterator, Map};
2121
use option::{Option, None, Some};
2222
use str::Str;
2323
use str;
24-
use slice::{CloneableVector, Splits, Vector, VectorVector,
24+
use slice::{CloneableVector, Splits, Slice, VectorVector,
2525
ImmutableEqSlice, ImmutableSlice};
2626
use vec::Vec;
2727

@@ -367,7 +367,7 @@ impl Path {
367367

368368
/// Returns a normalized byte vector representation of a path, by removing all empty
369369
/// components, and unnecessary . and .. components.
370-
fn normalize<V: Vector<u8>+CloneableVector<u8>>(v: V) -> Vec<u8> {
370+
fn normalize<V: Slice<u8>+CloneableVector<u8>>(v: V) -> Vec<u8> {
371371
// borrowck is being very picky
372372
let val = {
373373
let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == SEP_BYTE;

src/libstd/path/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use io::Writer;
2323
use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Iterator, Map};
2424
use mem;
2525
use option::{Option, Some, None};
26-
use slice::{Vector, ImmutableSlice};
26+
use slice::{Slice, ImmutableSlice};
2727
use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice};
2828
use string::String;
2929
use unicode::char::UnicodeChar;

src/libstd/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#[doc(no_inline)] pub use slice::{MutableCloneableSlice, MutableOrdSlice};
8787
#[doc(no_inline)] pub use slice::{ImmutableSlice, MutableSlice};
8888
#[doc(no_inline)] pub use slice::{ImmutableEqSlice, ImmutableOrdSlice};
89-
#[doc(no_inline)] pub use slice::{Vector, VectorVector};
89+
#[doc(no_inline)] pub use slice::{Slice, VectorVector};
9090
#[doc(no_inline)] pub use slice::MutableSliceAllocating;
9191
#[doc(no_inline)] pub use string::String;
9292
#[doc(no_inline)] pub use vec::Vec;

0 commit comments

Comments
 (0)