Skip to content

nrc's array work with minor fixes #20576

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

Closed
wants to merge 13 commits into from
17 changes: 8 additions & 9 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,17 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
script_str.push_str("set print pretty off\n");

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

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

// Add line breakpoints
for line in breakpoint_lines.iter() {
script_str.push_str(format!("break '{}':{}\n",
testfile.filename_display(),
*line)[]);
script_str.push_str(&format!("break '{}':{}\n",
testfile.filename_display(),
*line)[]);
}

script_str.push_str(cmds.as_slice());
Expand Down Expand Up @@ -676,7 +675,7 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
.unwrap()
.to_string();

script_str.push_str(format!("command script import {}\n", rust_pp_module_abs_path[])[]);
script_str.push_str(&format!("command script import {}\n", &rust_pp_module_abs_path[])[]);
script_str.push_str("type summary add --no-value ");
script_str.push_str("--python-function lldb_rust_formatters.print_val ");
script_str.push_str("-x \".*\" --category Rust\n");
Expand Down Expand Up @@ -910,7 +909,7 @@ fn check_error_patterns(props: &TestProps,
if done { return; }

let missing_patterns =
props.error_patterns[next_err_idx..];
props.error_patterns.index(&(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 @@ -345,7 +345,7 @@ impl Bitv {

if extra_bytes > 0 {
let mut last_word = 0u32;
for (i, &byte) in bytes[complete_words*4..].iter().enumerate() {
for (i, &byte) in bytes.index(&((complete_words*4)..)).iter().enumerate() {
last_word |= (reverse_bits(byte) as u32) << (i * 8);
}
bitv.storage.push(last_word);
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl<T> RingBuf<T> {
/// *num = *num - 2;
/// }
/// let b: &[_] = &[&mut 3, &mut 1, &mut 2];
/// assert_eq!(buf.iter_mut().collect::<Vec<&mut int>>()[], b);
/// assert_eq!(&buf.iter_mut().collect::<Vec<&mut int>>()[], b);
/// ```
#[stable]
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
Expand Down Expand Up @@ -440,7 +440,7 @@ impl<T> RingBuf<T> {
let buf = self.buffer_as_slice();
if contiguous {
let (empty, buf) = buf.split_at(0);
(buf[self.tail..self.head], empty)
(buf.index(&(self.tail..self.head)), empty)
} else {
let (mid, right) = buf.split_at(self.tail);
let (left, _) = mid.split_at(self.head);
Expand Down
41 changes: 23 additions & 18 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[1..3];
//! let last_numbers = numbers.index(&(1..3));
//! // last_numbers is now &[1i, 2i]
//! }
//! ```
Expand Down Expand Up @@ -97,7 +97,7 @@ use core::iter::{range, range_step, MultiplicativeIterator};
use core::kinds::Sized;
use core::mem::size_of;
use core::mem;
use core::ops::{FnMut, SliceMut};
use core::ops::{FnMut, FullRange, Index, IndexMut};
use core::option::Option::{self, Some, None};
use core::ptr::PtrExt;
use core::ptr;
Expand Down Expand Up @@ -1063,12 +1063,12 @@ impl ElementSwaps {

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

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

#[unstable = "trait is unstable"]
Expand Down Expand Up @@ -1390,15 +1390,20 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order

#[cfg(test)]
mod tests {
use prelude::{Some, None, range, Vec, ToString, Clone, Greater, Less, Equal};
use prelude::{SliceExt, Iterator, IteratorExt};
use prelude::AsSlice;
use prelude::{RandomAccessIterator, Ord, SliceConcatExt};
use core::cmp::Ordering::{Greater, Less, Equal};
use core::prelude::{Some, None, range, Clone};
use core::prelude::{Iterator, IteratorExt};
use core::prelude::{AsSlice};
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;
use super::ElementSwaps;
use string::ToString;
use vec::Vec;
use super::{ElementSwaps, SliceConcatExt, SliceExt};

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

Expand Down Expand Up @@ -1603,15 +1608,15 @@ mod tests {

// Test on stack.
let vec_stack: &[_] = &[1i, 2, 3];
let v_b = vec_stack[1u..3u].to_vec();
let v_b = vec_stack.index(&(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[1u..6u].to_vec();
let v_d = vec_unique.index(&(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 @@ -1624,21 +1629,21 @@ mod tests {
#[test]
fn test_slice_from() {
let vec: &[int] = &[1, 2, 3, 4];
assert_eq!(vec[0..], vec);
assert_eq!(vec.index(&(0..)), vec);
let b: &[int] = &[3, 4];
assert_eq!(vec[2..], b);
assert_eq!(vec.index(&(2..)), b);
let b: &[int] = &[];
assert_eq!(vec[4..], b);
assert_eq!(vec.index(&(4..)), b);
}

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


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

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