Skip to content

Commit b58f77e

Browse files
committed
rollup merge of rust-lang#17715 : aturon/revert-slice-ops-libs
2 parents b2d4eb1 + d2ea031 commit b58f77e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+495
-677
lines changed

src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
#![crate_type = "bin"]
12-
#![feature(phase, slicing_syntax)]
12+
#![feature(phase)]
1313

1414
#![deny(warnings)]
1515

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ fn check_error_patterns(props: &TestProps,
874874
if done { return; }
875875

876876
let missing_patterns =
877-
props.error_patterns[next_err_idx..];
877+
props.error_patterns.slice(next_err_idx, props.error_patterns.len());
878878
if missing_patterns.len() == 1u {
879879
fatal_proc_rec(format!("error pattern '{}' not found!",
880880
missing_patterns[0]).as_slice(),

src/doc/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3828,7 +3828,7 @@ type signature of `print`, and the cast expression in `main`.
38283828
Within the body of an item that has type parameter declarations, the names of
38293829
its type parameters are types:
38303830

3831-
```ignore
3831+
```
38323832
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
38333833
if xs.len() == 0 {
38343834
return vec![];

src/libcollections/bitv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl Bitv {
194194
if start > self.storage.len() {
195195
start = self.storage.len();
196196
}
197-
let mut iter = self.storage[start..].iter();
197+
let mut iter = self.storage.slice_from(start).iter();
198198
MaskWords {
199199
next_word: iter.next(),
200200
iter: iter,

src/libcollections/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
html_root_url = "http://doc.rust-lang.org/master/",
2020
html_playground_url = "http://play.rust-lang.org/")]
2121

22-
#![allow(unknown_features)]
2322
#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
24-
#![feature(unsafe_destructor, import_shadowing, slicing_syntax)]
23+
#![feature(unsafe_destructor, import_shadowing)]
2524
#![no_std]
2625

2726
#[phase(plugin, link)] extern crate core;

src/libcollections/ringbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<T> RingBuf<T> {
271271
/// *num = *num - 2;
272272
/// }
273273
/// let b: &[_] = &[&mut 3, &mut 1, &mut 2];
274-
/// assert_eq!(buf.iter_mut().collect::<Vec<&mut int>>()[], b);
274+
/// assert_eq!(buf.iter_mut().collect::<Vec<&mut int>>().as_slice(), b);
275275
/// ```
276276
pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
277277
let start_index = raw_index(self.lo, self.elts.len(), 0);
@@ -291,7 +291,7 @@ impl<T> RingBuf<T> {
291291
} else {
292292
// Items to iterate goes from start_index to end_index:
293293
let (empty, elts) = self.elts.split_at_mut(0);
294-
let remaining1 = elts[mut start_index..end_index];
294+
let remaining1 = elts.slice_mut(start_index, end_index);
295295
MutItems { remaining1: remaining1,
296296
remaining2: empty,
297297
nelts: self.nelts }

src/libcollections/slice.rs

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,15 @@
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
//!
50-
//! An example is the `slice` method which enables slicing syntax `[a..b]` that
51-
//! returns an immutable "view" into a `Vec` or another slice from the index
52-
//! interval `[a, b)`:
49+
//! An example is the method `.slice(a, b)` that returns an immutable "view" into
50+
//! a `Vec` or another slice from the index interval `[a, b)`:
5351
//!
5452
//! ```rust
55-
//! #![feature(slicing_syntax)]
56-
//! fn main() {
57-
//! let numbers = [0i, 1i, 2i];
58-
//! let last_numbers = numbers[1..3];
59-
//! // last_numbers is now &[1i, 2i]
60-
//! }
53+
//! let numbers = [0i, 1i, 2i];
54+
//! let last_numbers = numbers.slice(1, 3);
55+
//! // last_numbers is now &[1i, 2i]
6156
//! ```
6257
//!
6358
//! ## Implementations of other traits
@@ -615,7 +610,7 @@ impl<'a,T> MutableSliceAllocating<'a, T> for &'a mut [T] {
615610

616611
#[inline]
617612
fn move_from(self, mut src: Vec<T>, start: uint, end: uint) -> uint {
618-
for (a, b) in self.iter_mut().zip(src[mut start..end].iter_mut()) {
613+
for (a, b) in self.iter_mut().zip(src.slice_mut(start, end).iter_mut()) {
619614
mem::swap(a, b);
620615
}
621616
cmp::min(self.len(), end-start)
@@ -707,7 +702,7 @@ impl<'a, T: Ord> MutableOrdSlice<T> for &'a mut [T] {
707702
self.swap(j, i-1);
708703

709704
// Step 4: Reverse the (previously) weakly decreasing part
710-
self[mut i..].reverse();
705+
self.slice_from_mut(i).reverse();
711706

712707
true
713708
}
@@ -728,7 +723,7 @@ impl<'a, T: Ord> MutableOrdSlice<T> for &'a mut [T] {
728723
}
729724

730725
// Step 2: Reverse the weakly increasing part
731-
self[mut i..].reverse();
726+
self.slice_from_mut(i).reverse();
732727

733728
// Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
734729
let mut j = self.len() - 1;
@@ -995,24 +990,24 @@ mod tests {
995990
fn test_slice() {
996991
// Test fixed length vector.
997992
let vec_fixed = [1i, 2, 3, 4];
998-
let v_a = vec_fixed[1u..vec_fixed.len()].to_vec();
993+
let v_a = vec_fixed.slice(1u, vec_fixed.len()).to_vec();
999994
assert_eq!(v_a.len(), 3u);
1000995
let v_a = v_a.as_slice();
1001996
assert_eq!(v_a[0], 2);
1002997
assert_eq!(v_a[1], 3);
1003998
assert_eq!(v_a[2], 4);
1004999

10051000
// Test on stack.
1006-
let vec_stack: &[_] = &[1i, 2, 3];
1007-
let v_b = vec_stack[1u..3u].to_vec();
1001+
let vec_stack = &[1i, 2, 3];
1002+
let v_b = vec_stack.slice(1u, 3u).to_vec();
10081003
assert_eq!(v_b.len(), 2u);
10091004
let v_b = v_b.as_slice();
10101005
assert_eq!(v_b[0], 2);
10111006
assert_eq!(v_b[1], 3);
10121007

10131008
// Test `Box<[T]>`
10141009
let vec_unique = vec![1i, 2, 3, 4, 5, 6];
1015-
let v_d = vec_unique[1u..6u].to_vec();
1010+
let v_d = vec_unique.slice(1u, 6u).to_vec();
10161011
assert_eq!(v_d.len(), 5u);
10171012
let v_d = v_d.as_slice();
10181013
assert_eq!(v_d[0], 2);
@@ -1025,21 +1020,21 @@ mod tests {
10251020
#[test]
10261021
fn test_slice_from() {
10271022
let vec: &[int] = &[1, 2, 3, 4];
1028-
assert_eq!(vec[0..], vec);
1023+
assert_eq!(vec.slice_from(0), vec);
10291024
let b: &[int] = &[3, 4];
1030-
assert_eq!(vec[2..], b);
1025+
assert_eq!(vec.slice_from(2), b);
10311026
let b: &[int] = &[];
1032-
assert_eq!(vec[4..], b);
1027+
assert_eq!(vec.slice_from(4), b);
10331028
}
10341029

10351030
#[test]
10361031
fn test_slice_to() {
10371032
let vec: &[int] = &[1, 2, 3, 4];
1038-
assert_eq!(vec[..4], vec);
1033+
assert_eq!(vec.slice_to(4), vec);
10391034
let b: &[int] = &[1, 2];
1040-
assert_eq!(vec[..2], b);
1035+
assert_eq!(vec.slice_to(2), b);
10411036
let b: &[int] = &[];
1042-
assert_eq!(vec[..0], b);
1037+
assert_eq!(vec.slice_to(0), b);
10431038
}
10441039

10451040

@@ -1980,7 +1975,7 @@ mod tests {
19801975
assert!(a == [7i,2,3,4]);
19811976
let mut a = [1i,2,3,4,5];
19821977
let b = vec![5i,6,7,8,9,0];
1983-
assert_eq!(a[mut 2..4].move_from(b,1,6), 2);
1978+
assert_eq!(a.slice_mut(2,4).move_from(b,1,6), 2);
19841979
assert!(a == [1i,2,6,7,5]);
19851980
}
19861981

@@ -2000,7 +1995,7 @@ mod tests {
20001995
#[test]
20011996
fn test_reverse_part() {
20021997
let mut values = [1i,2,3,4,5];
2003-
values[mut 1..4].reverse();
1998+
values.slice_mut(1, 4).reverse();
20041999
assert!(values == [1,4,3,2,5]);
20052000
}
20062001

@@ -2047,9 +2042,9 @@ mod tests {
20472042
fn test_bytes_set_memory() {
20482043
use slice::bytes::MutableByteVector;
20492044
let mut values = [1u8,2,3,4,5];
2050-
values[mut 0..5].set_memory(0xAB);
2045+
values.slice_mut(0,5).set_memory(0xAB);
20512046
assert!(values == [0xAB, 0xAB, 0xAB, 0xAB, 0xAB]);
2052-
values[mut 2..4].set_memory(0xFF);
2047+
values.slice_mut(2,4).set_memory(0xFF);
20532048
assert!(values == [0xAB, 0xAB, 0xFF, 0xFF, 0xAB]);
20542049
}
20552050

@@ -2075,18 +2070,12 @@ mod tests {
20752070
let mut values = [1u8,2,3,4,5];
20762071
{
20772072
let (left, right) = values.split_at_mut(2);
2078-
{
2079-
let left: &[_] = left;
2080-
assert!(left[0..left.len()] == [1, 2]);
2081-
}
2073+
assert!(left.slice(0, left.len()) == [1, 2]);
20822074
for p in left.iter_mut() {
20832075
*p += 1;
20842076
}
20852077

2086-
{
2087-
let right: &[_] = right;
2088-
assert!(right[0..right.len()] == [3, 4, 5]);
2089-
}
2078+
assert!(right.slice(0, right.len()) == [3, 4, 5]);
20902079
for p in right.iter_mut() {
20912080
*p += 2;
20922081
}
@@ -2110,7 +2099,7 @@ mod tests {
21102099
}
21112100
assert_eq!(cnt, 3);
21122101

2113-
for f in v[1..3].iter() {
2102+
for f in v.slice(1, 3).iter() {
21142103
assert!(*f == Foo);
21152104
cnt += 1;
21162105
}

src/libcollections/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ mod tests {
16801680
let mut bytes = [0u8, ..4];
16811681
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
16821682
let len = c.encode_utf8(bytes).unwrap_or(0);
1683-
let s = ::core::str::from_utf8(bytes[..len]).unwrap();
1683+
let s = ::core::str::from_utf8(bytes.slice_to(len)).unwrap();
16841684
if Some(c) != s.chars().next() {
16851685
fail!("character {:x}={} does not decode correctly", c as u32, c);
16861686
}
@@ -1692,7 +1692,7 @@ mod tests {
16921692
let mut bytes = [0u8, ..4];
16931693
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
16941694
let len = c.encode_utf8(bytes).unwrap_or(0);
1695-
let s = ::core::str::from_utf8(bytes[..len]).unwrap();
1695+
let s = ::core::str::from_utf8(bytes.slice_to(len)).unwrap();
16961696
if Some(c) != s.chars().rev().next() {
16971697
fail!("character {:x}={} does not decode correctly", c as u32, c);
16981698
}

src/libcollections/string.rs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl String {
160160

161161
if i > 0 {
162162
unsafe {
163-
res.as_mut_vec().push_all(v[..i])
163+
res.as_mut_vec().push_all(v.slice_to(i))
164164
};
165165
}
166166

@@ -177,7 +177,7 @@ impl String {
177177
macro_rules! error(() => ({
178178
unsafe {
179179
if subseqidx != i_ {
180-
res.as_mut_vec().push_all(v[subseqidx..i_]);
180+
res.as_mut_vec().push_all(v.slice(subseqidx, i_));
181181
}
182182
subseqidx = i;
183183
res.as_mut_vec().push_all(REPLACEMENT);
@@ -246,7 +246,7 @@ impl String {
246246
}
247247
if subseqidx < total {
248248
unsafe {
249-
res.as_mut_vec().push_all(v[subseqidx..total])
249+
res.as_mut_vec().push_all(v.slice(subseqidx, total))
250250
};
251251
}
252252
Owned(res.into_string())
@@ -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/trie.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use core::fmt;
2424
use core::fmt::Show;
2525
use core::mem::zeroed;
2626
use core::mem;
27-
use core::ops::{Slice,SliceMut};
2827
use core::uint;
2928
use core::iter;
3029
use std::hash::{Writer, Hash};
@@ -379,7 +378,7 @@ macro_rules! bound {
379378
}
380379
};
381380
// push to the stack.
382-
it.stack[it.length] = children.$slice_from(&slice_idx).$iter();
381+
it.stack[it.length] = children.$slice_from(slice_idx).$iter();
383382
it.length += 1;
384383
if ret { return it }
385384
})
@@ -389,15 +388,6 @@ macro_rules! bound {
389388

390389
impl<T> TrieMap<T> {
391390
// If `upper` is true then returns upper_bound else returns lower_bound.
392-
#[cfg(stage0)]
393-
#[inline]
394-
fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
395-
bound!(Entries, self = self,
396-
key = key, is_upper = upper,
397-
slice_from = slice_from_, iter = iter,
398-
mutability = )
399-
}
400-
#[cfg(not(stage0))]
401391
#[inline]
402392
fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
403393
bound!(Entries, self = self,
@@ -440,15 +430,6 @@ impl<T> TrieMap<T> {
440430
self.bound(key, true)
441431
}
442432
// If `upper` is true then returns upper_bound else returns lower_bound.
443-
#[cfg(stage0)]
444-
#[inline]
445-
fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
446-
bound!(MutEntries, self = self,
447-
key = key, is_upper = upper,
448-
slice_from = slice_from_mut_, iter = iter_mut,
449-
mutability = mut)
450-
}
451-
#[cfg(not(stage0))]
452433
#[inline]
453434
fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
454435
bound!(MutEntries, self = self,

0 commit comments

Comments
 (0)