Skip to content

Commit 2f365ff

Browse files
committed
Revert "Review and rebasing changes"
This reverts commit 6e0611a.
1 parent b2d4eb1 commit 2f365ff

File tree

8 files changed

+42
-103
lines changed

8 files changed

+42
-103
lines changed

src/libcollections/slice.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
//!
4545
//! A number of traits add methods that allow you to accomplish tasks with slices.
4646
//! These traits include `ImmutableSlice`, which is defined for `&[T]` types,
47-
//! `MutableSlice`, defined for `&mut [T]` types, and `Slice` and `SliceMut`
48-
//! which are defined for `[T]`.
47+
//! and `MutableSlice`, defined for `&mut [T]` types.
4948
//!
5049
//! An example is the `slice` method which enables slicing syntax `[a..b]` that
5150
//! returns an immutable "view" into a `Vec` or another slice from the index

src/libcollections/string.rs

-29
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,6 @@ impl<S: Str> Add<S, String> for String {
927927
}
928928
}
929929

930-
#[cfg(stage0)]
931930
impl ops::Slice<uint, str> for String {
932931
#[inline]
933932
fn as_slice_<'a>(&'a self) -> &'a str {
@@ -950,34 +949,6 @@ impl ops::Slice<uint, str> for String {
950949
}
951950
}
952951

953-
#[cfg(not(stage0))]
954-
#[inline]
955-
fn str_to_slice<'a, U: Str>(this: &'a U) -> &'a str {
956-
this.as_slice()
957-
}
958-
#[cfg(not(stage0))]
959-
impl ops::Slice<uint, str> for String {
960-
#[inline]
961-
fn as_slice<'a>(&'a self) -> &'a str {
962-
str_to_slice(self)
963-
}
964-
965-
#[inline]
966-
fn slice_from<'a>(&'a self, from: &uint) -> &'a str {
967-
self[][*from..]
968-
}
969-
970-
#[inline]
971-
fn slice_to<'a>(&'a self, to: &uint) -> &'a str {
972-
self[][..*to]
973-
}
974-
975-
#[inline]
976-
fn slice<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
977-
self[][*from..*to]
978-
}
979-
}
980-
981952
/// Unsafe operations
982953
#[unstable = "waiting on raw module conventions"]
983954
pub mod raw {

src/libcollections/vec.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ impl<T> Index<uint,T> for Vec<T> {
463463

464464
// Annoying helper function because there are two Slice::as_slice functions in
465465
// scope.
466-
#[cfg(not(stage0))]
467466
#[inline]
468467
fn slice_to_slice<'a, T, U: Slice<T>>(this: &'a U) -> &'a [T] {
469468
this.as_slice()
@@ -985,6 +984,7 @@ impl<T> Vec<T> {
985984
/// assert!(vec[0..2] == [1, 2]);
986985
/// ```
987986
#[inline]
987+
#[deprecated = "use slicing syntax"]
988988
pub fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
989989
self[start..end]
990990
}
@@ -1020,7 +1020,7 @@ impl<T> Vec<T> {
10201020
/// assert!(vec.tailn(2) == [3, 4]);
10211021
/// ```
10221022
#[inline]
1023-
#[deprecated = "use slice_from"]
1023+
#[deprecated = "use slicing syntax"]
10241024
pub fn tailn<'a>(&'a self, n: uint) -> &'a [T] {
10251025
self[n..]
10261026
}
@@ -1230,7 +1230,7 @@ impl<T> Vec<T> {
12301230
}
12311231

12321232
/// Deprecated: use `slice_mut`.
1233-
#[deprecated = "use slice_from"]
1233+
#[deprecated = "use slicing syntax"]
12341234
pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint)
12351235
-> &'a mut [T] {
12361236
self[mut start..end]
@@ -1250,13 +1250,14 @@ impl<T> Vec<T> {
12501250
/// assert!(vec[mut 0..2] == [1, 2]);
12511251
/// ```
12521252
#[inline]
1253+
#[deprecated = "use slicing syntax"]
12531254
pub fn slice_mut<'a>(&'a mut self, start: uint, end: uint)
12541255
-> &'a mut [T] {
12551256
self[mut start..end]
12561257
}
12571258

12581259
/// Deprecated: use "slice_from_mut".
1259-
#[deprecated = "use slice_from_mut"]
1260+
#[deprecated = "use slicing syntax"]
12601261
pub fn mut_slice_from<'a>(&'a mut self, start: uint) -> &'a mut [T] {
12611262
self[mut start..]
12621263
}
@@ -1274,12 +1275,13 @@ impl<T> Vec<T> {
12741275
/// assert!(vec[mut 2..] == [3, 4]);
12751276
/// ```
12761277
#[inline]
1278+
#[deprecated = "use slicing syntax"]
12771279
pub fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] {
12781280
self[mut start..]
12791281
}
12801282

12811283
/// Deprecated: use `slice_to_mut`.
1282-
#[deprecated = "use slice_to_mut"]
1284+
#[deprecated = "use slicing syntax"]
12831285
pub fn mut_slice_to<'a>(&'a mut self, end: uint) -> &'a mut [T] {
12841286
self[mut ..end]
12851287
}
@@ -1297,6 +1299,7 @@ impl<T> Vec<T> {
12971299
/// assert!(vec[mut ..2] == [1, 2]);
12981300
/// ```
12991301
#[inline]
1302+
#[deprecated = "use slicing syntax"]
13001303
pub fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] {
13011304
self[mut ..end]
13021305
}
@@ -1373,6 +1376,7 @@ impl<T> Vec<T> {
13731376
/// assert!(vec[1..] == [2, 3]);
13741377
/// ```
13751378
#[inline]
1379+
#[deprecated = "use slicing syntax"]
13761380
pub fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
13771381
self[start..]
13781382
}
@@ -1390,6 +1394,7 @@ impl<T> Vec<T> {
13901394
/// assert!(vec[..2] == [1, 2]);
13911395
/// ```
13921396
#[inline]
1397+
#[deprecated = "use slicing syntax"]
13931398
pub fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
13941399
self[..end]
13951400
}

src/libcore/slice.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub trait ImmutableSlice<'a, T> {
152152
fn tail(&self) -> &'a [T];
153153

154154
/// Returns all but the first `n' elements of a slice.
155-
#[deprecated = "use slice_from"]
155+
#[deprecated = "use slicing syntax"]
156156
fn tailn(&self, n: uint) -> &'a [T];
157157

158158
/// Returns all but the last element of a slice.
@@ -161,6 +161,7 @@ pub trait ImmutableSlice<'a, T> {
161161

162162
/// Returns all but the last `n' elements of a slice.
163163
#[deprecated = "use slice_to but note the arguments are different"]
164+
#[deprecated = "use slicing syntax, but note the arguments are different"]
164165
fn initn(&self, n: uint) -> &'a [T];
165166

166167
/// Returns the last element of a slice, or `None` if it is empty.
@@ -320,7 +321,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
320321
fn tail(&self) -> &'a [T] { (*self)[1..] }
321322

322323
#[inline]
323-
#[deprecated = "use slice_from"]
324+
#[deprecated = "use slicing syntax"]
324325
fn tailn(&self, n: uint) -> &'a [T] { (*self)[n..] }
325326

326327
#[inline]
@@ -329,7 +330,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
329330
}
330331

331332
#[inline]
332-
#[deprecated = "use slice_to but note the arguments are different"]
333+
#[deprecated = "use slicing syntax but note the arguments are different"]
333334
fn initn(&self, n: uint) -> &'a [T] {
334335
(*self)[..self.len() - n]
335336
}
@@ -542,6 +543,7 @@ pub trait MutableSlice<'a, T> {
542543
fn get_mut(self, index: uint) -> Option<&'a mut T>;
543544
/// Work with `self` as a mut slice.
544545
/// Primarily intended for getting a &mut [T] from a [T, ..N].
546+
#[deprecated = "use slicing syntax"]
545547
fn as_mut_slice(self) -> &'a mut [T];
546548

547549
/// Deprecated: use `iter_mut`.

src/libcore/str.rs

+23-61
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,6 @@ pub mod traits {
11641164
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
11651165
}
11661166

1167-
#[cfg(stage0)]
11681167
impl ops::Slice<uint, str> for str {
11691168
#[inline]
11701169
fn as_slice_<'a>(&'a self) -> &'a str {
@@ -1173,39 +1172,17 @@ pub mod traits {
11731172

11741173
#[inline]
11751174
fn slice_from_<'a>(&'a self, from: &uint) -> &'a str {
1176-
super::slice_from_impl(&self, *from)
1175+
self.slice_from(*from)
11771176
}
11781177

11791178
#[inline]
11801179
fn slice_to_<'a>(&'a self, to: &uint) -> &'a str {
1181-
super::slice_to_impl(&self, *to)
1180+
self.slice_to(*to)
11821181
}
11831182

11841183
#[inline]
11851184
fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
1186-
super::slice_impl(&self, *from, *to)
1187-
}
1188-
}
1189-
#[cfg(not(stage0))]
1190-
impl ops::Slice<uint, str> for str {
1191-
#[inline]
1192-
fn as_slice<'a>(&'a self) -> &'a str {
1193-
self
1194-
}
1195-
1196-
#[inline]
1197-
fn slice_from<'a>(&'a self, from: &uint) -> &'a str {
1198-
super::slice_from_impl(&self, *from)
1199-
}
1200-
1201-
#[inline]
1202-
fn slice_to<'a>(&'a self, to: &uint) -> &'a str {
1203-
super::slice_to_impl(&self, *to)
1204-
}
1205-
1206-
#[inline]
1207-
fn slice<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
1208-
super::slice_impl(&self, *from, *to)
1185+
self.slice(*from, *to)
12091186
}
12101187
}
12111188
}
@@ -1858,38 +1835,6 @@ fn slice_error_fail(s: &str, begin: uint, end: uint) -> ! {
18581835
begin, end, s);
18591836
}
18601837

1861-
#[inline]
1862-
fn slice_impl<'a>(this: &&'a str, begin: uint, end: uint) -> &'a str {
1863-
// is_char_boundary checks that the index is in [0, .len()]
1864-
if begin <= end &&
1865-
this.is_char_boundary(begin) &&
1866-
this.is_char_boundary(end) {
1867-
unsafe { raw::slice_unchecked(*this, begin, end) }
1868-
} else {
1869-
slice_error_fail(*this, begin, end)
1870-
}
1871-
}
1872-
1873-
#[inline]
1874-
fn slice_from_impl<'a>(this: &&'a str, begin: uint) -> &'a str {
1875-
// is_char_boundary checks that the index is in [0, .len()]
1876-
if this.is_char_boundary(begin) {
1877-
unsafe { raw::slice_unchecked(*this, begin, this.len()) }
1878-
} else {
1879-
slice_error_fail(*this, begin, this.len())
1880-
}
1881-
}
1882-
1883-
#[inline]
1884-
fn slice_to_impl<'a>(this: &&'a str, end: uint) -> &'a str {
1885-
// is_char_boundary checks that the index is in [0, .len()]
1886-
if this.is_char_boundary(end) {
1887-
unsafe { raw::slice_unchecked(*this, 0, end) }
1888-
} else {
1889-
slice_error_fail(*this, 0, end)
1890-
}
1891-
}
1892-
18931838
impl<'a> StrSlice<'a> for &'a str {
18941839
#[inline]
18951840
fn contains<'a>(&self, needle: &'a str) -> bool {
@@ -1993,17 +1938,34 @@ impl<'a> StrSlice<'a> for &'a str {
19931938

19941939
#[inline]
19951940
fn slice(&self, begin: uint, end: uint) -> &'a str {
1996-
slice_impl(self, begin, end)
1941+
// is_char_boundary checks that the index is in [0, .len()]
1942+
if begin <= end &&
1943+
self.is_char_boundary(begin) &&
1944+
self.is_char_boundary(end) {
1945+
unsafe { raw::slice_unchecked(*self, begin, end) }
1946+
} else {
1947+
slice_error_fail(*self, begin, end)
1948+
}
19971949
}
19981950

19991951
#[inline]
20001952
fn slice_from(&self, begin: uint) -> &'a str {
2001-
slice_from_impl(self, begin)
1953+
// is_char_boundary checks that the index is in [0, .len()]
1954+
if self.is_char_boundary(begin) {
1955+
unsafe { raw::slice_unchecked(*self, begin, self.len()) }
1956+
} else {
1957+
slice_error_fail(*self, begin, self.len())
1958+
}
20021959
}
20031960

20041961
#[inline]
20051962
fn slice_to(&self, end: uint) -> &'a str {
2006-
slice_to_impl(self, end)
1963+
// is_char_boundary checks that the index is in [0, .len()]
1964+
if self.is_char_boundary(end) {
1965+
unsafe { raw::slice_unchecked(*self, 0, end) }
1966+
} else {
1967+
slice_error_fail(*self, 0, end)
1968+
}
20071969
}
20081970

20091971
fn slice_chars(&self, begin: uint, end: uint) -> &'a str {

src/libnative/io/pipe_windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl rtio::RtioPipe for UnixStream {
448448
}
449449
let ret = unsafe {
450450
libc::WriteFile(self.handle(),
451-
buf[offset..].as_ptr() as libc::LPVOID,
451+
buf.slice_from(offset).as_ptr() as libc::LPVOID,
452452
(buf.len() - offset) as libc::DWORD,
453453
&mut bytes_written,
454454
&mut overlapped)

src/libstd/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub mod windows {
144144
use option::{None, Option};
145145
use option;
146146
use os::TMPBUF_SZ;
147-
use slice::MutableSlice;
147+
use slice::{MutableSlice, ImmutableSlice};
148148
use string::String;
149149
use str::StrSlice;
150150
use vec::Vec;

src/libstd/rt/backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ mod imp {
999999
let bytes = cstr.as_bytes();
10001000
match cstr.as_str() {
10011001
Some(s) => try!(super::demangle(w, s)),
1002-
None => try!(w.write(bytes[..bytes.len()-1])),
1002+
None => try!(w.write(bytes.slice_to(bytes.len() - 1))),
10031003
}
10041004
}
10051005
try!(w.write(['\n' as u8]));

0 commit comments

Comments
 (0)