Skip to content

Commit 0ce4336

Browse files
nrcnikomatsakis
authored andcommitted
fallout
1 parent 65f189a commit 0ce4336

Some content is hidden

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

41 files changed

+218
-209
lines changed

src/compiletest/runtest.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,18 +539,17 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
539539
script_str.push_str("set print pretty off\n");
540540

541541
// Add the pretty printer directory to GDB's source-file search path
542-
script_str.push_str(format!("directory {}\n", rust_pp_module_abs_path)[]);
542+
script_str.push_str(&format!("directory {}\n", rust_pp_module_abs_path)[]);
543543

544544
// Load the target executable
545-
script_str.push_str(format!("file {}\n",
546-
exe_file.as_str().unwrap().replace("\\", "\\\\"))
547-
.as_slice());
545+
script_str.push_str(&format!("file {}\n",
546+
exe_file.as_str().unwrap().replace("\\", "\\\\"))[]);
548547

549548
// Add line breakpoints
550549
for line in breakpoint_lines.iter() {
551-
script_str.push_str(format!("break '{}':{}\n",
552-
testfile.filename_display(),
553-
*line)[]);
550+
script_str.push_str(&format!("break '{}':{}\n",
551+
testfile.filename_display(),
552+
*line)[]);
554553
}
555554

556555
script_str.push_str(cmds.as_slice());
@@ -676,7 +675,7 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
676675
.unwrap()
677676
.to_string();
678677

679-
script_str.push_str(format!("command script import {}\n", rust_pp_module_abs_path.index(&FullRange))[]);
678+
script_str.push_str(&format!("command script import {}\n", &rust_pp_module_abs_path[])[]);
680679
script_str.push_str("type summary add --no-value ");
681680
script_str.push_str("--python-function lldb_rust_formatters.print_val ");
682681
script_str.push_str("-x \".*\" --category Rust\n");

src/libcollections/ring_buf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<T> RingBuf<T> {
409409
/// *num = *num - 2;
410410
/// }
411411
/// let b: &[_] = &[&mut 3, &mut 1, &mut 2];
412-
/// assert_eq!(buf.iter_mut().collect::<Vec<&mut int>>()[], b);
412+
/// assert_eq!(&buf.iter_mut().collect::<Vec<&mut int>>()[], b);
413413
/// ```
414414
#[stable]
415415
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {

src/libcollections/slice.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,15 +1390,19 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
13901390

13911391
#[cfg(test)]
13921392
mod tests {
1393-
use prelude::{Some, None, range, Vec, ToString, Clone, Greater, Less, Equal};
1394-
use prelude::{SliceExt, Iterator, IteratorExt};
1395-
use prelude::AsSlice;
1396-
use prelude::{RandomAccessIterator, Ord, SliceConcatExt};
1393+
use std::boxed::Box;
1394+
use core::prelude::{Some, None, range, Clone, Greater, Less, Equal};
1395+
use core::prelude::{Iterator, IteratorExt, DoubleEndedIteratorExt};
1396+
use core::prelude::{AsSlice, Index};
1397+
use core::prelude::{RandomAccessIterator, Ord, PartialOrd, PartialEq, Eq, FullRange};
1398+
use core::cell::Cell;
13971399
use core::default::Default;
13981400
use core::mem;
13991401
use std::rand::{Rng, thread_rng};
14001402
use std::rc::Rc;
1401-
use super::ElementSwaps;
1403+
use string::ToString;
1404+
use vec::Vec;
1405+
use super::{ElementSwaps, CloneSliceExt, SliceConcatExt, SliceExt};
14021406

14031407
fn square(n: uint) -> uint { n * n }
14041408

src/libcollections/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ mod tests {
21212121
let mut bytes = [0u8; 4];
21222122
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
21232123
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
2124-
let s = ::core::str::from_utf8(bytes.index(&(0..len))).unwrap();
2124+
let s = ::core::str::from_utf8(&bytes[..len]).unwrap();
21252125
if Some(c) != s.chars().next() {
21262126
panic!("character {:x}={} does not decode correctly", c as u32, c);
21272127
}
@@ -2133,7 +2133,7 @@ mod tests {
21332133
let mut bytes = [0u8; 4];
21342134
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
21352135
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
2136-
let s = ::core::str::from_utf8(bytes.index(&(0..len))).unwrap();
2136+
let s = ::core::str::from_utf8(&bytes[..len]).unwrap();
21372137
if Some(c) != s.chars().rev().next() {
21382138
panic!("character {:x}={} does not decode correctly", c as u32, c);
21392139
}

src/libcollections/string.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ mod tests {
973973
use str::Utf8Error;
974974
use core::iter::repeat;
975975
use super::{as_string, CowString};
976+
use core::ops::FullRange;
976977

977978
#[test]
978979
fn test_as_string() {
@@ -1272,10 +1273,10 @@ mod tests {
12721273
#[test]
12731274
fn test_slicing() {
12741275
let s = "foobar".to_string();
1275-
assert_eq!("foobar", s.index(&FullRange));
1276-
assert_eq!("foo", s.index(&(0..3)));
1277-
assert_eq!("bar", s.index(&(3..)));
1278-
assert_eq!("oob", s.index(&(1..4)));
1276+
assert_eq!("foobar", &s[]);
1277+
assert_eq!("foo", &s[..3]);
1278+
assert_eq!("bar", &s[3..]);
1279+
assert_eq!("oob", &s[1..4]);
12791280
}
12801281

12811282
#[test]

src/libcollections/vec.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,7 @@ mod tests {
18051805
use prelude::*;
18061806
use core::mem::size_of;
18071807
use core::iter::repeat;
1808+
use core::ops::FullRange;
18081809
use test::Bencher;
18091810
use super::as_vec;
18101811

@@ -1942,15 +1943,15 @@ mod tests {
19421943
let (left, right) = values.split_at_mut(2);
19431944
{
19441945
let left: &[_] = left;
1945-
assert!(left[0..left.len()] == [1, 2][]);
1946+
assert!(&left[..left.len()] == &[1, 2][]);
19461947
}
19471948
for p in left.iter_mut() {
19481949
*p += 1;
19491950
}
19501951

19511952
{
19521953
let right: &[_] = right;
1953-
assert!(right[0..right.len()] == [3, 4, 5][]);
1954+
assert!(&right[..right.len()] == &[3, 4, 5][]);
19541955
}
19551956
for p in right.iter_mut() {
19561957
*p += 2;
@@ -2121,35 +2122,35 @@ mod tests {
21212122
#[should_fail]
21222123
fn test_slice_out_of_bounds_1() {
21232124
let x: Vec<int> = vec![1, 2, 3, 4, 5];
2124-
x[-1..];
2125+
&x[(-1)..];
21252126
}
21262127

21272128
#[test]
21282129
#[should_fail]
21292130
fn test_slice_out_of_bounds_2() {
21302131
let x: Vec<int> = vec![1, 2, 3, 4, 5];
2131-
x.index(&(0..6));
2132+
&x[..6];
21322133
}
21332134

21342135
#[test]
21352136
#[should_fail]
21362137
fn test_slice_out_of_bounds_3() {
21372138
let x: Vec<int> = vec![1, 2, 3, 4, 5];
2138-
x[-1..4];
2139+
&x[(-1)..4];
21392140
}
21402141

21412142
#[test]
21422143
#[should_fail]
21432144
fn test_slice_out_of_bounds_4() {
21442145
let x: Vec<int> = vec![1, 2, 3, 4, 5];
2145-
x.index(&(1..6));
2146+
&x[1..6];
21462147
}
21472148

21482149
#[test]
21492150
#[should_fail]
21502151
fn test_slice_out_of_bounds_5() {
21512152
let x: Vec<int> = vec![1, 2, 3, 4, 5];
2152-
x.index(&(3..2));
2153+
&x[3..2];
21532154
}
21542155

21552156
#[test]
@@ -2395,7 +2396,7 @@ mod tests {
23952396
b.bytes = src_len as u64;
23962397

23972398
b.iter(|| {
2398-
let dst = src.clone().as_slice().to_vec();
2399+
let dst = src.clone()[].to_vec();
23992400
assert_eq!(dst.len(), src_len);
24002401
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
24012402
});

src/libcore/slice.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,25 @@ impl<T> ops::IndexMut<uint> for [T] {
572572
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
573573
}
574574
}
575+
impl<T> ops::Index<uint, T> for [T] {
576+
fn index(&self, &index: &uint) -> &T {
577+
assert!(index < self.len());
578+
579+
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
580+
}
581+
}
582+
583+
impl<T> ops::IndexMut<uint, T> for [T] {
584+
fn index_mut(&mut self, &index: &uint) -> &mut T {
585+
assert!(index < self.len());
586+
587+
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
588+
}
589+
}
575590

576591
impl<T> ops::Index<ops::Range<uint>, [T]> for [T] {
577592
#[inline]
578-
fn index(&self, &index: &ops::Range<uint>) -> &[T] {
593+
fn index(&self, index: &ops::Range<uint>) -> &[T] {
579594
assert!(index.start <= index.end);
580595
assert!(index.end <= self.len());
581596
unsafe {
@@ -589,28 +604,28 @@ impl<T> ops::Index<ops::Range<uint>, [T]> for [T] {
589604

590605
impl<T> ops::Index<ops::RangeTo<uint>, [T]> for [T] {
591606
#[inline]
592-
fn index(&self, &index: &ops::RangeTo<uint>) -> &[T] {
607+
fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
593608
self.index(&ops::Range{ start: 0, end: index.end })
594609
}
595610
}
596611

597612
impl<T> ops::Index<ops::RangeFrom<uint>, [T]> for [T] {
598613
#[inline]
599-
fn index(&self, &index: &ops::RangeFrom<uint>) -> &[T] {
614+
fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
600615
self.index(&ops::Range{ start: index.start, end: self.len() })
601616
}
602617
}
603618

604619
impl<T> ops::Index<ops::FullRange, [T]> for [T] {
605620
#[inline]
606-
fn index(&self, &index: &ops::FullRange) -> &[T] {
621+
fn index(&self, _index: &ops::FullRange) -> &[T] {
607622
self
608623
}
609624
}
610625

611626
impl<T> ops::IndexMut<ops::Range<uint>, [T]> for [T] {
612627
#[inline]
613-
fn index_mut(&mut self, &index: &ops::Range<uint>) -> &mut [T] {
628+
fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] {
614629
assert!(index.start <= index.end);
615630
assert!(index.end <= self.len());
616631
unsafe {
@@ -624,40 +639,26 @@ impl<T> ops::IndexMut<ops::Range<uint>, [T]> for [T] {
624639

625640
impl<T> ops::IndexMut<ops::RangeTo<uint>, [T]> for [T] {
626641
#[inline]
627-
fn index_mut(&mut self, &index: &ops::RangeTo<uint>) -> &mut [T] {
642+
fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] {
628643
self.index_mut(&ops::Range{ start: 0, end: index.end })
629644
}
630645
}
631646

632647
impl<T> ops::IndexMut<ops::RangeFrom<uint>, [T]> for [T] {
633648
#[inline]
634-
fn index_mut(&mut self, &index: &ops::RangeFrom<uint>) -> &mut [T] {
649+
fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] {
635650
let len = self.len();
636651
self.index_mut(&ops::Range{ start: index.start, end: len })
637652
}
638653
}
639654

640655
impl<T> ops::IndexMut<ops::FullRange, [T]> for [T] {
641656
#[inline]
642-
fn index_mut(&mut self, &index: &ops::FullRange) -> &mut [T] {
657+
fn index_mut(&mut self, _index: &ops::FullRange) -> &mut [T] {
643658
self
644659
}
645660
}
646661

647-
impl<T> ops::Index<ops::Range<uint>, [T]> for [T] {
648-
#[inline]
649-
fn index(&self, index: &ops::Range<uint>) -> &[T] {
650-
assert!(index.start <= index.end);
651-
assert!(index.end <= self.len());
652-
unsafe {
653-
transmute(RawSlice {
654-
data: self.as_ptr().offset(index.start as int),
655-
len: index.end - index.start
656-
})
657-
}
658-
}
659-
}
660-
661662

662663
////////////////////////////////////////////////////////////////////////////////
663664
// Common traits

src/libcoretest/iter.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use core::iter::MinMaxResult::*;
1414
use core::num::SignedInt;
1515
use core::uint;
1616
use core::cmp;
17-
use core::ops::Slice;
1817

1918
use test::Bencher;
2019

@@ -230,7 +229,7 @@ fn test_inspect() {
230229
.collect::<Vec<uint>>();
231230

232231
assert_eq!(n, xs.len());
233-
assert_eq!(xs.index(&FullRange), ys.index(&FullRange));
232+
assert_eq!(&xs[], &ys[]);
234233
}
235234

236235
#[test]
@@ -281,47 +280,47 @@ fn test_iterator_nth() {
281280
fn test_iterator_last() {
282281
let v: &[_] = &[0i, 1, 2, 3, 4];
283282
assert_eq!(v.iter().last().unwrap(), &4);
284-
assert_eq!(v.index(&(0..1)).iter().last().unwrap(), &0);
283+
assert_eq!(v[..1].iter().last().unwrap(), &0);
285284
}
286285

287286
#[test]
288287
fn test_iterator_len() {
289288
let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
290-
assert_eq!(v.index(&(0..4)).iter().count(), 4);
291-
assert_eq!(v.index(&(0..10)).iter().count(), 10);
292-
assert_eq!(v.index(&(0..0)).iter().count(), 0);
289+
assert_eq!(v[..4].iter().count(), 4);
290+
assert_eq!(v[..10].iter().count(), 10);
291+
assert_eq!(v[0..0].iter().count(), 0);
293292
}
294293

295294
#[test]
296295
fn test_iterator_sum() {
297296
let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
298-
assert_eq!(v.index(&(0..4)).iter().map(|&x| x).sum(), 6);
297+
assert_eq!(v[..4].iter().map(|&x| x).sum(), 6);
299298
assert_eq!(v.iter().map(|&x| x).sum(), 55);
300-
assert_eq!(v.index(&(0..0)).iter().map(|&x| x).sum(), 0);
299+
assert_eq!(v[0..0].iter().map(|&x| x).sum(), 0);
301300
}
302301

303302
#[test]
304303
fn test_iterator_product() {
305304
let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
306-
assert_eq!(v.index(&(0..4)).iter().map(|&x| x).product(), 0);
307-
assert_eq!(v.index(&(1..5)).iter().map(|&x| x).product(), 24);
308-
assert_eq!(v.index(&(0..0)).iter().map(|&x| x).product(), 1);
305+
assert_eq!(v[0..4].iter().map(|&x| x).product(), 0);
306+
assert_eq!(v[1..5].iter().map(|&x| x).product(), 24);
307+
assert_eq!(v[0..0].iter().map(|&x| x).product(), 1);
309308
}
310309

311310
#[test]
312311
fn test_iterator_max() {
313312
let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
314-
assert_eq!(v.index(&(0..4)).iter().map(|&x| x).max(), Some(3));
313+
assert_eq!(v[0..4].iter().map(|&x| x).max(), Some(3));
315314
assert_eq!(v.iter().map(|&x| x).max(), Some(10));
316-
assert_eq!(v.index(&(0..0)).iter().map(|&x| x).max(), None);
315+
assert_eq!(v[0..0].iter().map(|&x| x).max(), None);
317316
}
318317

319318
#[test]
320319
fn test_iterator_min() {
321320
let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
322-
assert_eq!(v.index(&(0..4)).iter().map(|&x| x).min(), Some(0));
321+
assert_eq!(v[0..4].iter().map(|&x| x).min(), Some(0));
323322
assert_eq!(v.iter().map(|&x| x).min(), Some(0));
324-
assert_eq!(v.index(&(0..0)).iter().map(|&x| x).min(), None);
323+
assert_eq!(v[0..0].iter().map(|&x| x).min(), None);
325324
}
326325

327326
#[test]
@@ -374,7 +373,7 @@ fn test_all() {
374373
assert!(v.iter().all(|&x| x < 10));
375374
assert!(!v.iter().all(|&x| x % 2 == 0));
376375
assert!(!v.iter().all(|&x| x > 100));
377-
assert!(v.slice_or_fail(&0, &0).iter().all(|_| panic!()));
376+
assert!(v[0..0].iter().all(|_| panic!()));
378377
}
379378

380379
#[test]
@@ -383,7 +382,7 @@ fn test_any() {
383382
assert!(v.iter().any(|&x| x < 10));
384383
assert!(v.iter().any(|&x| x % 2 == 0));
385384
assert!(!v.iter().any(|&x| x > 100));
386-
assert!(!v.slice_or_fail(&0, &0).iter().any(|_| panic!()));
385+
assert!(!v[0..0].iter().any(|_| panic!()));
387386
}
388387

389388
#[test]
@@ -586,7 +585,7 @@ fn check_randacc_iter<A, T>(a: T, len: uint) where
586585
fn test_double_ended_flat_map() {
587586
let u = [0u,1];
588587
let v = [5u,6,7,8];
589-
let mut it = u.iter().flat_map(|x| v[*x..v.len()].iter());
588+
let mut it = u.iter().flat_map(|x| v[(*x)..v.len()].iter());
590589
assert_eq!(it.next_back().unwrap(), &8);
591590
assert_eq!(it.next().unwrap(), &5);
592591
assert_eq!(it.next_back().unwrap(), &7);

0 commit comments

Comments
 (0)