Skip to content

Register new snapshot, use slicing syntax everywhere #20721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,7 @@ fn check_error_patterns(props: &TestProps,
}
if done { return; }

let missing_patterns =
props.error_patterns.index(&(next_err_idx..));
let missing_patterns = &props.error_patterns[next_err_idx..];
if missing_patterns.len() == 1u {
fatal_proc_rec(format!("error pattern '{}' not found!",
missing_patterns[0]).as_slice(),
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl Bitv {

if extra_bytes > 0 {
let mut last_word = 0u32;
for (i, &byte) in bytes.index(&((complete_words*4)..)).iter().enumerate() {
for (i, &byte) in bytes[(complete_words*4)..].iter().enumerate() {
last_word |= (reverse_bits(byte) as u32) << (i * 8);
}
bitv.storage.push(last_word);
Expand Down
2 changes: 0 additions & 2 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ mod std {
pub use core::option; // necessary for panic!()
pub use core::clone; // deriving(Clone)
pub use core::cmp; // deriving(Eq, Ord, etc.)
#[cfg(stage0)]
pub use core::marker as kinds;
pub use core::marker; // deriving(Copy)
pub use core::hash; // deriving(Hash)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ impl<T> RingBuf<T> {
let buf = self.buffer_as_slice();
if contiguous {
let (empty, buf) = buf.split_at(0);
(buf.index(&(self.tail..self.head)), empty)
(&buf[self.tail..self.head], empty)
} else {
let (mid, right) = buf.split_at(self.tail);
let (left, _) = mid.split_at(self.head);
Expand Down
27 changes: 13 additions & 14 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
//! #![feature(slicing_syntax)]
//! fn main() {
//! let numbers = [0i, 1i, 2i];
//! let last_numbers = numbers.index(&(1..3));
//! let last_numbers = &numbers[1..3];
//! // last_numbers is now &[1i, 2i]
//! }
//! ```
Expand Down Expand Up @@ -98,7 +98,7 @@ use core::iter::{range, range_step, MultiplicativeIterator};
use core::marker::Sized;
use core::mem::size_of;
use core::mem;
use core::ops::{FnMut, FullRange, Index, IndexMut};
use core::ops::{FnMut, FullRange};
use core::option::Option::{self, Some, None};
use core::ptr::PtrExt;
use core::ptr;
Expand Down Expand Up @@ -1065,12 +1065,12 @@ impl ElementSwaps {

#[unstable = "trait is unstable"]
impl<T> BorrowFrom<Vec<T>> for [T] {
fn borrow_from(owned: &Vec<T>) -> &[T] { owned.index(&FullRange) }
fn borrow_from(owned: &Vec<T>) -> &[T] { &owned[] }
}

#[unstable = "trait is unstable"]
impl<T> BorrowFromMut<Vec<T>> for [T] {
fn borrow_from_mut(owned: &mut Vec<T>) -> &mut [T] { owned.index_mut(&FullRange) }
fn borrow_from_mut(owned: &mut Vec<T>) -> &mut [T] { &mut owned[] }
}

#[unstable = "trait is unstable"]
Expand Down Expand Up @@ -1400,7 +1400,6 @@ mod tests {
use core::prelude::{Ord, FullRange};
use core::default::Default;
use core::mem;
use core::ops::Index;
use std::iter::RandomAccessIterator;
use std::rand::{Rng, thread_rng};
use std::rc::Rc;
Expand Down Expand Up @@ -1611,15 +1610,15 @@ mod tests {

// Test on stack.
let vec_stack: &[_] = &[1i, 2, 3];
let v_b = vec_stack.index(&(1u..3u)).to_vec();
let v_b = vec_stack[1u..3u].to_vec();
assert_eq!(v_b.len(), 2u);
let v_b = v_b.as_slice();
assert_eq!(v_b[0], 2);
assert_eq!(v_b[1], 3);

// Test `Box<[T]>`
let vec_unique = vec![1i, 2, 3, 4, 5, 6];
let v_d = vec_unique.index(&(1u..6u)).to_vec();
let v_d = vec_unique[1u..6u].to_vec();
assert_eq!(v_d.len(), 5u);
let v_d = v_d.as_slice();
assert_eq!(v_d[0], 2);
Expand All @@ -1632,21 +1631,21 @@ mod tests {
#[test]
fn test_slice_from() {
let vec: &[int] = &[1, 2, 3, 4];
assert_eq!(vec.index(&(0..)), vec);
assert_eq!(&vec[0..], vec);
let b: &[int] = &[3, 4];
assert_eq!(vec.index(&(2..)), b);
assert_eq!(&vec[2..], b);
let b: &[int] = &[];
assert_eq!(vec.index(&(4..)), b);
assert_eq!(&vec[4..], b);
}

#[test]
fn test_slice_to() {
let vec: &[int] = &[1, 2, 3, 4];
assert_eq!(vec.index(&(0..4)), vec);
assert_eq!(&vec[0..4], vec);
let b: &[int] = &[1, 2];
assert_eq!(vec.index(&(0..2)), b);
assert_eq!(&vec[0..2], b);
let b: &[int] = &[];
assert_eq!(vec.index(&(0..0)), b);
assert_eq!(&vec[0..0], b);
}


Expand Down Expand Up @@ -2572,7 +2571,7 @@ mod tests {
}
assert_eq!(cnt, 3);

for f in v.index(&(1..3)).iter() {
for f in v[1..3].iter() {
assert!(*f == Foo);
cnt += 1;
}
Expand Down
Loading