Skip to content

Commit

Permalink
fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Jan 6, 2015
1 parent 791f545 commit 0c7f7a5
Show file tree
Hide file tree
Showing 89 changed files with 498 additions and 423 deletions.
15 changes: 7 additions & 8 deletions src/compiletest/runtest.rs
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.index(&FullRange))[]);
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
2 changes: 1 addition & 1 deletion src/libcollections/ring_buf.rs
Expand Up @@ -525,7 +525,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
15 changes: 10 additions & 5 deletions src/libcollections/slice.rs
Expand Up @@ -1393,15 +1393,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
14 changes: 4 additions & 10 deletions src/libcollections/str.rs
Expand Up @@ -60,7 +60,7 @@ use core::char::CharExt;
use core::clone::Clone;
use core::iter::AdditiveIterator;
use core::iter::{range, Iterator, IteratorExt};
use core::ops::{self, llRange, Index};
use core::ops::{FullRange, Index};
use core::option::Option::{self, Some, None};
use core::slice::AsSlice;
use core::str as core_str;
Expand Down Expand Up @@ -408,7 +408,7 @@ Section: Trait implementations

/// Any string that can be represented as a slice.
#[stable]
pub trait StrExt: Index<FullRange, str> {
pub trait StrExt: Index<FullRange, Output = str> {
/// Escapes each char in `s` with `char::escape_default`.
#[unstable = "return type may change to be an iterator"]
fn escape_default(&self) -> String {
Expand Down Expand Up @@ -1339,12 +1339,6 @@ pub trait StrExt: Index<FullRange, str> {
fn trim_left(&self) -> &str {
UnicodeStr::trim_left(self.index(&FullRange))
}

/// Returns a string with trailing whitespace removed.
#[stable]
fn trim_right(&self) -> &str {
UnicodeStr::trim_right(self.index(&FullRange))
}
}

#[stable]
Expand Down Expand Up @@ -2133,7 +2127,7 @@ mod tests {
let mut bytes = [0u8; 4];
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
let s = ::core::str::from_utf8(bytes.index(&(0..len))).unwrap();
let s = ::core::str::from_utf8(&bytes[..len]).unwrap();
if Some(c) != s.chars().next() {
panic!("character {:x}={} does not decode correctly", c as u32, c);
}
Expand All @@ -2145,7 +2139,7 @@ mod tests {
let mut bytes = [0u8; 4];
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
let s = ::core::str::from_utf8(bytes.index(&(0..len))).unwrap();
let s = ::core::str::from_utf8(&bytes[..len]).unwrap();
if Some(c) != s.chars().rev().next() {
panic!("character {:x}={} does not decode correctly", c as u32, c);
}
Expand Down
26 changes: 14 additions & 12 deletions src/libcollections/string.rs
Expand Up @@ -22,7 +22,7 @@ use core::fmt;
use core::hash;
use core::iter::FromIterator;
use core::mem;
use core::ops::{self, Deref, Add};
use core::ops::{self, Deref, Add, Index};
use core::ptr;
use core::raw::Slice as RawSlice;
use unicode::str as unicode_str;
Expand Down Expand Up @@ -818,28 +818,29 @@ impl<'a> Add<&'a str> for String {
}
}

impl ops::Index<ops::Range<uint>, str> for String {
impl ops::Index<ops::Range<uint>> for String {
type Output = str;
#[inline]
fn index(&self, index: &ops::Range<uint>) -> &str {
&self.index(&FullRange)[*index]
}
}

impl ops::Index<ops::RangeTo<uint>, str> for String {
impl ops::Index<ops::RangeTo<uint>> for String {
type Output = str;
#[inline]
fn index(&self, index: &ops::RangeTo<uint>) -> &str {
&self.index(&FullRange)[*index]
}
}

impl ops::Index<ops::RangeFrom<uint>, str> for String {
impl ops::Index<ops::RangeFrom<uint>> for String {
type Output = str;
#[inline]
fn index(&self, index: &ops::RangeFrom<uint>) -> &str {
&self.index(&FullRange)[*index]
}
}

impl ops::Index<ops::FullRange, str> for String {
impl ops::Index<ops::FullRange> for String {
type Output = str;
#[inline]
fn index(&self, _index: &ops::FullRange) -> &str {
unsafe { mem::transmute(self.vec.as_slice()) }
Expand Down Expand Up @@ -949,6 +950,7 @@ mod tests {
use str::Utf8Error;
use core::iter::repeat;
use super::{as_string, CowString};
use core::ops::FullRange;

#[test]
fn test_as_string() {
Expand Down Expand Up @@ -1230,10 +1232,10 @@ mod tests {
#[test]
fn test_slicing() {
let s = "foobar".to_string();
assert_eq!("foobar", s.index(&FullRange));
assert_eq!("foo", s.index(&(0..3)));
assert_eq!("bar", s.index(&(3..)));
assert_eq!("oob", s.index(&(1..4)));
assert_eq!("foobar", &s[]);
assert_eq!("foo", &s[..3]);
assert_eq!("bar", &s[3..]);
assert_eq!("oob", &s[1..4]);
}

#[test]
Expand Down
49 changes: 27 additions & 22 deletions src/libcollections/vec.rs
Expand Up @@ -1209,62 +1209,66 @@ impl<T> IndexMut<uint> for Vec<T> {
}
}

impl<T> ops::Index<ops::Range<uint>, [T]> for Vec<T> {

impl<T> ops::Index<ops::Range<uint>> for Vec<T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::Range<uint>) -> &[T] {
self.as_slice().index(index)
}
}

impl<T> ops::Index<ops::RangeTo<uint>, [T]> for Vec<T> {
impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
self.as_slice().index(index)
}
}

impl<T> ops::Index<ops::RangeFrom<uint>, [T]> for Vec<T> {
impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
type Output = [T];
#[inline]
fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
self.as_slice().index(index)
}
}

impl<T> ops::Index<ops::FullRange, [T]> for Vec<T> {
impl<T> ops::Index<ops::FullRange> for Vec<T> {
type Output = [T];
#[inline]
fn index(&self, _index: &ops::FullRange) -> &[T] {
self.as_slice()
}
}

impl<T> ops::IndexMut<ops::Range<uint>, [T]> for Vec<T> {
impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
type Output = [T];
#[inline]
fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] {
self.as_mut_slice().index_mut(index)
}
}

impl<T> ops::IndexMut<ops::RangeTo<uint>, [T]> for Vec<T> {
impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> {
type Output = [T];
#[inline]
fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] {
self.as_mut_slice().index_mut(index)
}
}

impl<T> ops::IndexMut<ops::RangeFrom<uint>, [T]> for Vec<T> {
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
type Output = [T];
#[inline]
fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] {
self.as_mut_slice().index_mut(index)
}
}

impl<T> ops::IndexMut<ops::FullRange, [T]> for Vec<T> {
impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
type Output = [T];
#[inline]
fn index_mut(&mut self, _index: &ops::FullRange) -> &mut [T] {
self.as_mut_slice()
}
}


#[stable]
impl<T> ops::Deref for Vec<T> {
type Target = [T];
Expand Down Expand Up @@ -1795,6 +1799,7 @@ mod tests {
use prelude::*;
use core::mem::size_of;
use core::iter::repeat;
use core::ops::FullRange;
use test::Bencher;
use super::as_vec;

Expand Down Expand Up @@ -1932,15 +1937,15 @@ mod tests {
let (left, right) = values.split_at_mut(2);
{
let left: &[_] = left;
assert!(left[0..left.len()] == [1, 2][]);
assert!(&left[..left.len()] == &[1, 2][]);
}
for p in left.iter_mut() {
*p += 1;
}

{
let right: &[_] = right;
assert!(right[0..right.len()] == [3, 4, 5][]);
assert!(&right[..right.len()] == &[3, 4, 5][]);
}
for p in right.iter_mut() {
*p += 2;
Expand Down Expand Up @@ -2111,35 +2116,35 @@ mod tests {
#[should_fail]
fn test_slice_out_of_bounds_1() {
let x: Vec<int> = vec![1, 2, 3, 4, 5];
x[-1..];
&x[(-1)..];
}

#[test]
#[should_fail]
fn test_slice_out_of_bounds_2() {
let x: Vec<int> = vec![1, 2, 3, 4, 5];
x.index(&(0..6));
&x[..6];
}

#[test]
#[should_fail]
fn test_slice_out_of_bounds_3() {
let x: Vec<int> = vec![1, 2, 3, 4, 5];
x[-1..4];
&x[(-1)..4];
}

#[test]
#[should_fail]
fn test_slice_out_of_bounds_4() {
let x: Vec<int> = vec![1, 2, 3, 4, 5];
x.index(&(1..6));
&x[1..6];
}

#[test]
#[should_fail]
fn test_slice_out_of_bounds_5() {
let x: Vec<int> = vec![1, 2, 3, 4, 5];
x.index(&(3..2));
&x[3..2];
}

#[test]
Expand Down Expand Up @@ -2385,7 +2390,7 @@ mod tests {
b.bytes = src_len as u64;

b.iter(|| {
let dst = src.clone().as_slice().to_vec();
let dst = src.clone()[].to_vec();
assert_eq!(dst.len(), src_len);
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
});
Expand Down
16 changes: 12 additions & 4 deletions src/libcore/array.rs
Expand Up @@ -57,9 +57,13 @@ macro_rules! array_impls {
Rhs: Deref<Target=[B]>,
{
#[inline(always)]
fn eq(&self, other: &Rhs) -> bool { PartialEq::eq(self.index(&FullRange), &**other) }
fn eq(&self, other: &Rhs) -> bool {
PartialEq::eq(self.index(&FullRange), &**other)
}
#[inline(always)]
fn ne(&self, other: &Rhs) -> bool { PartialEq::ne(self.index(&FullRange), &**other) }
fn ne(&self, other: &Rhs) -> bool {
PartialEq::ne(self.index(&FullRange), &**other)
}
}

#[stable]
Expand All @@ -68,9 +72,13 @@ macro_rules! array_impls {
Lhs: Deref<Target=[A]>
{
#[inline(always)]
fn eq(&self, other: &[B; $N]) -> bool { PartialEq::eq(&**self, other.index(&FullRange)) }
fn eq(&self, other: &[B; $N]) -> bool {
PartialEq::eq(&**self, other.index(&FullRange))
}
#[inline(always)]
fn ne(&self, other: &[B; $N]) -> bool { PartialEq::ne(&**self, other.index(&FullRange)) }
fn ne(&self, other: &[B; $N]) -> bool {
PartialEq::ne(&**self, other.index(&FullRange))
}
}

#[stable]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/mod.rs
Expand Up @@ -521,7 +521,7 @@ impl<'a> Formatter<'a> {

let mut fill = [0u8; 4];
let len = self.fill.encode_utf8(&mut fill).unwrap_or(0);
let fill = unsafe { str::from_utf8_unchecked(fill[..len]) };
let fill = unsafe { str::from_utf8_unchecked(fill.index(&(..len))) };

for _ in range(0, pre_pad) {
try!(self.buf.write_str(fill));
Expand Down

4 comments on commit 0c7f7a5

@bors
Copy link
Contributor

@bors bors commented on 0c7f7a5 Jan 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at nrc@0c7f7a5

@bors
Copy link
Contributor

@bors bors commented on 0c7f7a5 Jan 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/arrays-3 = 0c7f7a5 into auto

@bors
Copy link
Contributor

@bors bors commented on 0c7f7a5 Jan 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status: {"merge_sha": "18a1178d91466be71f3e07d6848d52f2018f2a5a"}

@bors
Copy link
Contributor

@bors bors commented on 0c7f7a5 Jan 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/arrays-3 = 0c7f7a5 merged ok, testing candidate = 18a1178

Please sign in to comment.