Skip to content

Commit 886c6f3

Browse files
committed
rollup merge of #21258: aturon/stab-3-index
Conflicts: src/libcore/ops.rs src/librustc_typeck/astconv.rs src/libstd/io/mem.rs src/libsyntax/parse/lexer/mod.rs
2 parents 036d8c4 + 537889a commit 886c6f3

File tree

59 files changed

+353
-430
lines changed

Some content is hidden

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

59 files changed

+353
-430
lines changed

src/compiletest/header.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ pub fn parse_name_value_directive(line: &str, directive: &str)
332332
let keycolon = format!("{}:", directive);
333333
match line.find_str(keycolon.as_slice()) {
334334
Some(colon) => {
335-
let value = line.slice(colon + keycolon.len(),
336-
line.len()).to_string();
335+
let value = line[(colon + keycolon.len()) .. line.len()].to_string();
337336
debug!("{}: {}", directive, value);
338337
Some(value)
339338
}

src/compiletest/runtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
863863
break;
864864
}
865865
Some(i) => {
866-
rest = rest.slice_from(i + frag.len());
866+
rest = &rest[(i + frag.len())..];
867867
}
868868
}
869869
first = false;
@@ -1046,7 +1046,7 @@ fn scan_until_char(haystack: &str, needle: char, idx: &mut uint) -> bool {
10461046
if *idx >= haystack.len() {
10471047
return false;
10481048
}
1049-
let opt = haystack.slice_from(*idx).find(needle);
1049+
let opt = haystack[(*idx)..].find(needle);
10501050
if opt.is_none() {
10511051
return false;
10521052
}

src/doc/intro.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,12 @@ use std::sync::{Arc,Mutex};
480480
fn main() {
481481
let numbers = Arc::new(Mutex::new(vec![1is, 2, 3]));
482482
483-
for i in 0..3 {
483+
for i in 0us..3 {
484484
let number = numbers.clone();
485485
Thread::spawn(move || {
486486
let mut array = number.lock().unwrap();
487-
488-
(*array)[i] += 1;
489-
490-
println!("numbers[{}] is {}", i, (*array)[i]);
487+
array[i] += 1;
488+
println!("numbers[{}] is {}", i, array[i]);
491489
});
492490
}
493491
}

src/doc/trpl/looping.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ We now loop forever with `loop` and use `break` to break out early.
123123
iteration. This will only print the odd numbers:
124124

125125
```{rust}
126-
for x in 0..10 {
126+
for x in 0u32..10 {
127127
if x % 2 == 0 { continue; }
128128
129129
println!("{}", x);

src/doc/trpl/threads.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ for init_val in 0 .. 3 {
179179
}
180180

181181
let result = rx.recv().unwrap() + rx.recv().unwrap() + rx.recv().unwrap();
182-
# fn some_expensive_computation(_i: u32) -> u32 { 42 }
182+
# fn some_expensive_computation(_i: i32) -> i32 { 42 }
183183
```
184184

185185
Cloning a `Sender` produces a new handle to the same channel, allowing multiple
@@ -207,7 +207,7 @@ let rxs = (0 .. 3).map(|&:init_val| {
207207

208208
// Wait on each port, accumulating the results
209209
let result = rxs.iter().fold(0, |&:accum, rx| accum + rx.recv().unwrap() );
210-
# fn some_expensive_computation(_i: u32) -> u32 { 42 }
210+
# fn some_expensive_computation(_i: i32) -> i32 { 42 }
211211
```
212212

213213
## Backgrounding computations: Futures

src/libcollections/btree/node.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::prelude::*;
2121
use core::borrow::BorrowFrom;
2222
use core::cmp::Ordering::{Greater, Less, Equal};
2323
use core::iter::Zip;
24-
use core::ops::{Deref, DerefMut};
24+
use core::ops::{Deref, DerefMut, Index, IndexMut};
2525
use core::ptr::Unique;
2626
use core::{slice, mem, ptr, cmp, num, raw};
2727
use alloc::heap;
@@ -1487,7 +1487,7 @@ impl<K, V, E, Impl> AbsTraversal<Impl>
14871487

14881488
macro_rules! node_slice_impl {
14891489
($NodeSlice:ident, $Traversal:ident,
1490-
$as_slices_internal:ident, $slice_from:ident, $slice_to:ident, $iter:ident) => {
1490+
$as_slices_internal:ident, $index:ident, $iter:ident) => {
14911491
impl<'a, K: Ord + 'a, V: 'a> $NodeSlice<'a, K, V> {
14921492
/// Performs linear search in a slice. Returns a tuple of (index, is_exact_match).
14931493
fn search_linear<Q: ?Sized>(&self, key: &Q) -> (uint, bool)
@@ -1521,10 +1521,10 @@ macro_rules! node_slice_impl {
15211521
edges: if !self.has_edges {
15221522
self.edges
15231523
} else {
1524-
self.edges.$slice_from(pos)
1524+
self.edges.$index(&(pos ..))
15251525
},
1526-
keys: self.keys.slice_from(pos),
1527-
vals: self.vals.$slice_from(pos),
1526+
keys: &self.keys[pos ..],
1527+
vals: self.vals.$index(&(pos ..)),
15281528
head_is_edge: !pos_is_kv,
15291529
tail_is_edge: self.tail_is_edge,
15301530
}
@@ -1550,10 +1550,10 @@ macro_rules! node_slice_impl {
15501550
edges: if !self.has_edges {
15511551
self.edges
15521552
} else {
1553-
self.edges.$slice_to(pos + 1)
1553+
self.edges.$index(&(.. (pos + 1)))
15541554
},
1555-
keys: self.keys.slice_to(pos),
1556-
vals: self.vals.$slice_to(pos),
1555+
keys: &self.keys[..pos],
1556+
vals: self.vals.$index(&(.. pos)),
15571557
head_is_edge: self.head_is_edge,
15581558
tail_is_edge: !pos_is_kv,
15591559
}
@@ -1583,6 +1583,5 @@ macro_rules! node_slice_impl {
15831583
}
15841584
}
15851585

1586-
node_slice_impl!(NodeSlice, Traversal, as_slices_internal, slice_from, slice_to, iter);
1587-
node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, slice_from_mut,
1588-
slice_to_mut, iter_mut);
1586+
node_slice_impl!(NodeSlice, Traversal, as_slices_internal, index, iter);
1587+
node_slice_impl!(MutNodeSlice, MutTraversal, as_slices_internal_mut, index_mut, iter_mut);

src/libcollections/ring_buf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ impl<T> RingBuf<T> {
578578

579579
if contiguous {
580580
let (empty, buf) = buf.split_at_mut(0);
581-
(buf.slice_mut(tail, head), empty)
581+
(&mut buf[tail .. head], empty)
582582
} else {
583583
let (mid, right) = buf.split_at_mut(tail);
584584
let (left, _) = mid.split_at_mut(head);

src/libcollections/slice.rs

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -169,29 +169,16 @@ pub trait SliceExt {
169169
#[unstable = "uncertain about this API approach"]
170170
fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint;
171171

172-
/// Returns a subslice spanning the interval [`start`, `end`).
173-
///
174-
/// Panics when the end of the new slice lies beyond the end of the
175-
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
176-
///
177-
/// Slicing with `start` equal to `end` yields an empty slice.
178-
#[unstable = "will be replaced by slice syntax"]
172+
/// Deprecated: use `&s[start .. end]` notation instead.
173+
#[deprecated = "use &s[start .. end] instead"]
179174
fn slice(&self, start: uint, end: uint) -> &[Self::Item];
180175

181-
/// Returns a subslice from `start` to the end of the slice.
182-
///
183-
/// Panics when `start` is strictly greater than the length of the original slice.
184-
///
185-
/// Slicing from `self.len()` yields an empty slice.
186-
#[unstable = "will be replaced by slice syntax"]
176+
/// Deprecated: use `&s[start..]` notation instead.
177+
#[deprecated = "use &s[start..] isntead"]
187178
fn slice_from(&self, start: uint) -> &[Self::Item];
188179

189-
/// Returns a subslice from the start of the slice to `end`.
190-
///
191-
/// Panics when `end` is strictly greater than the length of the original slice.
192-
///
193-
/// Slicing to `0` yields an empty slice.
194-
#[unstable = "will be replaced by slice syntax"]
180+
/// Deprecated: use `&s[..end]` notation instead.
181+
#[deprecated = "use &s[..end] instead"]
195182
fn slice_to(&self, end: uint) -> &[Self::Item];
196183

197184
/// Divides one slice into two at an index.
@@ -378,29 +365,16 @@ pub trait SliceExt {
378365
#[stable]
379366
fn as_mut_slice(&mut self) -> &mut [Self::Item];
380367

381-
/// Returns a mutable subslice spanning the interval [`start`, `end`).
382-
///
383-
/// Panics when the end of the new slice lies beyond the end of the
384-
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
385-
///
386-
/// Slicing with `start` equal to `end` yields an empty slice.
387-
#[unstable = "will be replaced by slice syntax"]
368+
/// Deprecated: use `&mut s[start .. end]` instead.
369+
#[deprecated = "use &mut s[start .. end] instead"]
388370
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item];
389371

390-
/// Returns a mutable subslice from `start` to the end of the slice.
391-
///
392-
/// Panics when `start` is strictly greater than the length of the original slice.
393-
///
394-
/// Slicing from `self.len()` yields an empty slice.
395-
#[unstable = "will be replaced by slice syntax"]
372+
/// Deprecated: use `&mut s[start ..]` instead.
373+
#[deprecated = "use &mut s[start ..] instead"]
396374
fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item];
397375

398-
/// Returns a mutable subslice from the start of the slice to `end`.
399-
///
400-
/// Panics when `end` is strictly greater than the length of the original slice.
401-
///
402-
/// Slicing to `0` yields an empty slice.
403-
#[unstable = "will be replaced by slice syntax"]
376+
/// Deprecated: use `&mut s[.. end]` instead.
377+
#[deprecated = "use &mut s[.. end] instead"]
404378
fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item];
405379

406380
/// Returns an iterator that allows modifying each value
@@ -712,25 +686,25 @@ impl<T> SliceExt for [T] {
712686

713687
#[inline]
714688
fn move_from(&mut self, mut src: Vec<T>, start: uint, end: uint) -> uint {
715-
for (a, b) in self.iter_mut().zip(src.slice_mut(start, end).iter_mut()) {
689+
for (a, b) in self.iter_mut().zip(src[start .. end].iter_mut()) {
716690
mem::swap(a, b);
717691
}
718692
cmp::min(self.len(), end-start)
719693
}
720694

721695
#[inline]
722696
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
723-
core_slice::SliceExt::slice(self, start, end)
697+
&self[start .. end]
724698
}
725699

726700
#[inline]
727701
fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
728-
core_slice::SliceExt::slice_from(self, start)
702+
&self[start ..]
729703
}
730704

731705
#[inline]
732706
fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
733-
core_slice::SliceExt::slice_to(self, end)
707+
&self[.. end]
734708
}
735709

736710
#[inline]
@@ -834,17 +808,17 @@ impl<T> SliceExt for [T] {
834808

835809
#[inline]
836810
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] {
837-
core_slice::SliceExt::slice_mut(self, start, end)
811+
&mut self[start .. end]
838812
}
839813

840814
#[inline]
841815
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] {
842-
core_slice::SliceExt::slice_from_mut(self, start)
816+
&mut self[start ..]
843817
}
844818

845819
#[inline]
846820
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] {
847-
core_slice::SliceExt::slice_to_mut(self, end)
821+
&mut self[.. end]
848822
}
849823

850824
#[inline]

src/libcollections/str.rs

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -750,67 +750,17 @@ pub trait StrExt: Index<FullRange, Output = str> {
750750
core_str::StrExt::lines_any(&self[])
751751
}
752752

753-
/// Returns a slice of the given string from the byte range
754-
/// [`begin`..`end`).
755-
///
756-
/// This operation is `O(1)`.
757-
///
758-
/// Panics when `begin` and `end` do not point to valid characters
759-
/// or point beyond the last character of the string.
760-
///
761-
/// See also `slice_to` and `slice_from` for slicing prefixes and
762-
/// suffixes of strings, and `slice_chars` for slicing based on
763-
/// code point counts.
764-
///
765-
/// # Example
766-
///
767-
/// ```rust
768-
/// let s = "Löwe 老虎 Léopard";
769-
/// assert_eq!(s.slice(0, 1), "L");
770-
///
771-
/// assert_eq!(s.slice(1, 9), "öwe 老");
772-
///
773-
/// // these will panic:
774-
/// // byte 2 lies within `ö`:
775-
/// // s.slice(2, 3);
776-
///
777-
/// // byte 8 lies within `老`
778-
/// // s.slice(1, 8);
779-
///
780-
/// // byte 100 is outside the string
781-
/// // s.slice(3, 100);
782-
/// ```
783-
#[unstable = "use slice notation [a..b] instead"]
784-
fn slice(&self, begin: uint, end: uint) -> &str {
785-
core_str::StrExt::slice(&self[], begin, end)
786-
}
753+
/// Deprecated: use `s[a .. b]` instead.
754+
#[deprecated = "use slice notation [a..b] instead"]
755+
fn slice(&self, begin: uint, end: uint) -> &str;
787756

788-
/// Returns a slice of the string from `begin` to its end.
789-
///
790-
/// Equivalent to `self.slice(begin, self.len())`.
791-
///
792-
/// Panics when `begin` does not point to a valid character, or is
793-
/// out of bounds.
794-
///
795-
/// See also `slice`, `slice_to` and `slice_chars`.
796-
#[unstable = "use slice notation [a..] instead"]
797-
fn slice_from(&self, begin: uint) -> &str {
798-
core_str::StrExt::slice_from(&self[], begin)
799-
}
757+
/// Deprecated: use `s[a..]` instead.
758+
#[deprecated = "use slice notation [a..] instead"]
759+
fn slice_from(&self, begin: uint) -> &str;
800760

801-
/// Returns a slice of the string from the beginning to byte
802-
/// `end`.
803-
///
804-
/// Equivalent to `self.slice(0, end)`.
805-
///
806-
/// Panics when `end` does not point to a valid character, or is
807-
/// out of bounds.
808-
///
809-
/// See also `slice`, `slice_from` and `slice_chars`.
810-
#[unstable = "use slice notation [..a] instead"]
811-
fn slice_to(&self, end: uint) -> &str {
812-
core_str::StrExt::slice_to(&self[], end)
813-
}
761+
/// Deprecated: use `s[..a]` instead.
762+
#[deprecated = "use slice notation [..a] instead"]
763+
fn slice_to(&self, end: uint) -> &str;
814764

815765
/// Returns a slice of the string from the character range
816766
/// [`begin`..`end`).
@@ -1348,7 +1298,19 @@ pub trait StrExt: Index<FullRange, Output = str> {
13481298
}
13491299

13501300
#[stable]
1351-
impl StrExt for str {}
1301+
impl StrExt for str {
1302+
fn slice(&self, begin: uint, end: uint) -> &str {
1303+
&self[begin..end]
1304+
}
1305+
1306+
fn slice_from(&self, begin: uint) -> &str {
1307+
&self[begin..]
1308+
}
1309+
1310+
fn slice_to(&self, end: uint) -> &str {
1311+
&self[..end]
1312+
}
1313+
}
13521314

13531315
#[cfg(test)]
13541316
mod tests {

src/libcollections/string.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,27 +849,31 @@ impl<'a> Add<&'a str> for String {
849849
}
850850
}
851851

852+
#[stable]
852853
impl ops::Index<ops::Range<uint>> for String {
853854
type Output = str;
854855
#[inline]
855856
fn index(&self, index: &ops::Range<uint>) -> &str {
856857
&self[][*index]
857858
}
858859
}
860+
#[stable]
859861
impl ops::Index<ops::RangeTo<uint>> for String {
860862
type Output = str;
861863
#[inline]
862864
fn index(&self, index: &ops::RangeTo<uint>) -> &str {
863865
&self[][*index]
864866
}
865867
}
868+
#[stable]
866869
impl ops::Index<ops::RangeFrom<uint>> for String {
867870
type Output = str;
868871
#[inline]
869872
fn index(&self, index: &ops::RangeFrom<uint>) -> &str {
870873
&self[][*index]
871874
}
872875
}
876+
#[stable]
873877
impl ops::Index<ops::FullRange> for String {
874878
type Output = str;
875879
#[inline]

0 commit comments

Comments
 (0)