1
Fork 0

auto merge of #19378 : japaric/rust/no-as-slice, r=alexcrichton

Now that we have an overloaded comparison (`==`) operator, and that `Vec`/`String` deref to `[T]`/`str` on method calls, many `as_slice()`/`as_mut_slice()`/`to_string()` calls have become redundant. This patch removes them. These were the most common patterns:

- `assert_eq(test_output.as_slice(), "ground truth")` -> `assert_eq(test_output, "ground truth")`
- `assert_eq(test_output, "ground truth".to_string())` -> `assert_eq(test_output, "ground truth")`
- `vec.as_mut_slice().sort()` -> `vec.sort()`
- `vec.as_slice().slice(from, to)` -> `vec.slice(from_to)`

---

Note that e.g. `a_string.push_str(b_string.as_slice())` has been left untouched in this PR, since we first need to settle down whether we want to favor the `&*b_string` or the `b_string[]` notation.

This is rebased on top of #19167

cc @alexcrichton @aturon
This commit is contained in:
bors 2014-12-08 02:32:31 +00:00
commit 83a44c7fa6
116 changed files with 954 additions and 988 deletions

View file

@ -523,7 +523,7 @@ mod tests {
#[test] #[test]
fn show_arc() { fn show_arc() {
let a = Arc::new(5u32); let a = Arc::new(5u32);
assert!(format!("{}", a).as_slice() == "5") assert!(format!("{}", a) == "5")
} }
// Make sure deriving works with Arc<T> // Make sure deriving works with Arc<T>

View file

@ -170,14 +170,14 @@ mod test {
let b = box Test as Box<Any>; let b = box Test as Box<Any>;
let a_str = a.to_str(); let a_str = a.to_str();
let b_str = b.to_str(); let b_str = b.to_str();
assert_eq!(a_str.as_slice(), "Box<Any>"); assert_eq!(a_str, "Box<Any>");
assert_eq!(b_str.as_slice(), "Box<Any>"); assert_eq!(b_str, "Box<Any>");
let a = &8u as &Any; let a = &8u as &Any;
let b = &Test as &Any; let b = &Test as &Any;
let s = format!("{}", a); let s = format!("{}", a);
assert_eq!(s.as_slice(), "&Any"); assert_eq!(s, "&Any");
let s = format!("{}", b); let s = format!("{}", b);
assert_eq!(s.as_slice(), "&Any"); assert_eq!(s, "&Any");
} }
} }

View file

@ -485,7 +485,7 @@ impl<T: Ord> BinaryHeap<T> {
let mut end = q.len(); let mut end = q.len();
while end > 1 { while end > 1 {
end -= 1; end -= 1;
q.data.as_mut_slice().swap(0, end); q.data.swap(0, end);
q.siftdown_range(0, end) q.siftdown_range(0, end)
} }
q.into_vec() q.into_vec()
@ -769,8 +769,8 @@ mod tests {
v.sort(); v.sort();
data.sort(); data.sort();
assert_eq!(v.as_slice(), data.as_slice()); assert_eq!(v, data);
assert_eq!(heap.into_sorted_vec().as_slice(), data.as_slice()); assert_eq!(heap.into_sorted_vec(), data);
} }
#[test] #[test]
@ -812,7 +812,7 @@ mod tests {
fn test_from_iter() { fn test_from_iter() {
let xs = vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1); let xs = vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1);
let mut q: BinaryHeap<uint> = xs.as_slice().iter().rev().map(|&x| x).collect(); let mut q: BinaryHeap<uint> = xs.iter().rev().map(|&x| x).collect();
for &x in xs.iter() { for &x in xs.iter() {
assert_eq!(q.pop().unwrap(), x); assert_eq!(q.pop().unwrap(), x);

View file

@ -1692,10 +1692,10 @@ mod tests {
#[test] #[test]
fn test_to_str() { fn test_to_str() {
let zerolen = Bitv::new(); let zerolen = Bitv::new();
assert_eq!(zerolen.to_string().as_slice(), ""); assert_eq!(zerolen.to_string(), "");
let eightbits = Bitv::with_capacity(8u, false); let eightbits = Bitv::with_capacity(8u, false);
assert_eq!(eightbits.to_string().as_slice(), "00000000") assert_eq!(eightbits.to_string(), "00000000")
} }
#[test] #[test]
@ -1718,7 +1718,7 @@ mod tests {
let mut b = bitv::Bitv::with_capacity(2, false); let mut b = bitv::Bitv::with_capacity(2, false);
b.set(0, true); b.set(0, true);
b.set(1, false); b.set(1, false);
assert_eq!(b.to_string().as_slice(), "10"); assert_eq!(b.to_string(), "10");
} }
#[test] #[test]
@ -2029,7 +2029,7 @@ mod tests {
fn test_from_bytes() { fn test_from_bytes() {
let bitv = from_bytes(&[0b10110110, 0b00000000, 0b11111111]); let bitv = from_bytes(&[0b10110110, 0b00000000, 0b11111111]);
let str = format!("{}{}{}", "10110110", "00000000", "11111111"); let str = format!("{}{}{}", "10110110", "00000000", "11111111");
assert_eq!(bitv.to_string().as_slice(), str.as_slice()); assert_eq!(bitv.to_string(), str);
} }
#[test] #[test]
@ -2048,7 +2048,7 @@ mod tests {
fn test_from_bools() { fn test_from_bools() {
let bools = vec![true, false, true, true]; let bools = vec![true, false, true, true];
let bitv: Bitv = bools.iter().map(|n| *n).collect(); let bitv: Bitv = bools.iter().map(|n| *n).collect();
assert_eq!(bitv.to_string().as_slice(), "1011"); assert_eq!(bitv.to_string(), "1011");
} }
#[test] #[test]
@ -2207,7 +2207,7 @@ mod tests {
let expected = [3, 5, 11, 77]; let expected = [3, 5, 11, 77];
let actual = a.intersection(&b).collect::<Vec<uint>>(); let actual = a.intersection(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice()); assert_eq!(actual, expected);
} }
#[test] #[test]
@ -2226,7 +2226,7 @@ mod tests {
let expected = [1, 5, 500]; let expected = [1, 5, 500];
let actual = a.difference(&b).collect::<Vec<uint>>(); let actual = a.difference(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice()); assert_eq!(actual, expected);
} }
#[test] #[test]
@ -2247,7 +2247,7 @@ mod tests {
let expected = [1, 5, 11, 14, 220]; let expected = [1, 5, 11, 14, 220];
let actual = a.symmetric_difference(&b).collect::<Vec<uint>>(); let actual = a.symmetric_difference(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice()); assert_eq!(actual, expected);
} }
#[test] #[test]
@ -2272,7 +2272,7 @@ mod tests {
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160, 200]; let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160, 200];
let actual = a.union(&b).collect::<Vec<uint>>(); let actual = a.union(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice()); assert_eq!(actual, expected);
} }
#[test] #[test]
@ -2660,7 +2660,7 @@ mod tests {
s.insert(10); s.insert(10);
s.insert(50); s.insert(50);
s.insert(2); s.insert(2);
assert_eq!("{1, 2, 10, 50}".to_string(), s.to_string()); assert_eq!("{1, 2, 10, 50}", s.to_string());
} }
fn rng() -> rand::IsaacRng { fn rng() -> rand::IsaacRng {

View file

@ -158,43 +158,43 @@ impl <K, V> Node<K, V> {
/// Swap the given key-value pair with the key-value pair stored in the node's index, /// Swap the given key-value pair with the key-value pair stored in the node's index,
/// without checking bounds. /// without checking bounds.
pub unsafe fn unsafe_swap(&mut self, index: uint, key: &mut K, val: &mut V) { pub unsafe fn unsafe_swap(&mut self, index: uint, key: &mut K, val: &mut V) {
mem::swap(self.keys.as_mut_slice().unsafe_mut(index), key); mem::swap(self.keys.unsafe_mut(index), key);
mem::swap(self.vals.as_mut_slice().unsafe_mut(index), val); mem::swap(self.vals.unsafe_mut(index), val);
} }
/// Get the node's key mutably without any bounds checks. /// Get the node's key mutably without any bounds checks.
pub unsafe fn unsafe_key_mut(&mut self, index: uint) -> &mut K { pub unsafe fn unsafe_key_mut(&mut self, index: uint) -> &mut K {
self.keys.as_mut_slice().unsafe_mut(index) self.keys.unsafe_mut(index)
} }
/// Get the node's value at the given index /// Get the node's value at the given index
pub fn val(&self, index: uint) -> Option<&V> { pub fn val(&self, index: uint) -> Option<&V> {
self.vals.as_slice().get(index) self.vals.get(index)
} }
/// Get the node's value at the given index /// Get the node's value at the given index
pub fn val_mut(&mut self, index: uint) -> Option<&mut V> { pub fn val_mut(&mut self, index: uint) -> Option<&mut V> {
self.vals.as_mut_slice().get_mut(index) self.vals.get_mut(index)
} }
/// Get the node's value mutably without any bounds checks. /// Get the node's value mutably without any bounds checks.
pub unsafe fn unsafe_val_mut(&mut self, index: uint) -> &mut V { pub unsafe fn unsafe_val_mut(&mut self, index: uint) -> &mut V {
self.vals.as_mut_slice().unsafe_mut(index) self.vals.unsafe_mut(index)
} }
/// Get the node's edge at the given index /// Get the node's edge at the given index
pub fn edge(&self, index: uint) -> Option<&Node<K,V>> { pub fn edge(&self, index: uint) -> Option<&Node<K,V>> {
self.edges.as_slice().get(index) self.edges.get(index)
} }
/// Get the node's edge mutably at the given index /// Get the node's edge mutably at the given index
pub fn edge_mut(&mut self, index: uint) -> Option<&mut Node<K,V>> { pub fn edge_mut(&mut self, index: uint) -> Option<&mut Node<K,V>> {
self.edges.as_mut_slice().get_mut(index) self.edges.get_mut(index)
} }
/// Get the node's edge mutably without any bounds checks. /// Get the node's edge mutably without any bounds checks.
pub unsafe fn unsafe_edge_mut(&mut self, index: uint) -> &mut Node<K,V> { pub unsafe fn unsafe_edge_mut(&mut self, index: uint) -> &mut Node<K,V> {
self.edges.as_mut_slice().unsafe_mut(index) self.edges.unsafe_mut(index)
} }
/// Pop an edge off the end of the node /// Pop an edge off the end of the node
@ -281,8 +281,8 @@ impl <K, V> Node<K, V> {
pub fn iter<'a>(&'a self) -> Traversal<'a, K, V> { pub fn iter<'a>(&'a self) -> Traversal<'a, K, V> {
let is_leaf = self.is_leaf(); let is_leaf = self.is_leaf();
Traversal { Traversal {
elems: self.keys.as_slice().iter().zip(self.vals.as_slice().iter()), elems: self.keys.iter().zip(self.vals.iter()),
edges: self.edges.as_slice().iter(), edges: self.edges.iter(),
head_is_edge: true, head_is_edge: true,
tail_is_edge: true, tail_is_edge: true,
has_edges: !is_leaf, has_edges: !is_leaf,
@ -292,8 +292,8 @@ impl <K, V> Node<K, V> {
pub fn iter_mut<'a>(&'a mut self) -> MutTraversal<'a, K, V> { pub fn iter_mut<'a>(&'a mut self) -> MutTraversal<'a, K, V> {
let is_leaf = self.is_leaf(); let is_leaf = self.is_leaf();
MutTraversal { MutTraversal {
elems: self.keys.as_slice().iter().zip(self.vals.as_mut_slice().iter_mut()), elems: self.keys.iter().zip(self.vals.iter_mut()),
edges: self.edges.as_mut_slice().iter_mut(), edges: self.edges.iter_mut(),
head_is_edge: true, head_is_edge: true,
tail_is_edge: true, tail_is_edge: true,
has_edges: !is_leaf, has_edges: !is_leaf,
@ -477,8 +477,8 @@ fn split<T>(left: &mut Vec<T>) -> Vec<T> {
let left_len = len - right_len; let left_len = len - right_len;
let mut right = Vec::with_capacity(left.capacity()); let mut right = Vec::with_capacity(left.capacity());
unsafe { unsafe {
let left_ptr = left.as_slice().unsafe_get(left_len) as *const _; let left_ptr = left.unsafe_get(left_len) as *const _;
let right_ptr = right.as_mut_slice().as_mut_ptr(); let right_ptr = right.as_mut_ptr();
ptr::copy_nonoverlapping_memory(right_ptr, left_ptr, right_len); ptr::copy_nonoverlapping_memory(right_ptr, left_ptr, right_len);
left.set_len(left_len); left.set_len(left_len);
right.set_len(right_len); right.set_len(right_len);

View file

@ -646,7 +646,7 @@ mod test {
let set_str = format!("{}", set); let set_str = format!("{}", set);
assert!(set_str == "{1, 2}".to_string()); assert!(set_str == "{1, 2}");
assert_eq!(format!("{}", empty), "{}".to_string()); assert_eq!(format!("{}", empty), "{}");
} }
} }

View file

@ -926,7 +926,7 @@ mod tests {
let mut m = list_from(v.as_slice()); let mut m = list_from(v.as_slice());
m.prepend(list_from(u.as_slice())); m.prepend(list_from(u.as_slice()));
check_links(&m); check_links(&m);
u.extend(v.as_slice().iter().map(|&b| b)); u.extend(v.iter().map(|&b| b));
assert_eq!(u.len(), m.len()); assert_eq!(u.len(), m.len());
for elt in u.into_iter() { for elt in u.into_iter() {
assert_eq!(m.pop_front(), Some(elt)) assert_eq!(m.pop_front(), Some(elt))
@ -1133,7 +1133,7 @@ mod tests {
spawn(proc() { spawn(proc() {
check_links(&n); check_links(&n);
let a: &[_] = &[&1,&2,&3]; let a: &[_] = &[&1,&2,&3];
assert_eq!(a, n.iter().collect::<Vec<&int>>().as_slice()); assert_eq!(a, n.iter().collect::<Vec<&int>>());
}); });
} }
@ -1224,12 +1224,12 @@ mod tests {
#[test] #[test]
fn test_show() { fn test_show() {
let list: DList<int> = range(0i, 10).collect(); let list: DList<int> = range(0i, 10).collect();
assert!(list.to_string().as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); assert!(list.to_string() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
let list: DList<&str> = vec!["just", "one", "test", "more"].iter() let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
.map(|&s| s) .map(|&s| s)
.collect(); .collect();
assert!(list.to_string().as_slice() == "[just, one, test, more]"); assert!(list.to_string() == "[just, one, test, more]");
} }
#[cfg(test)] #[cfg(test)]

View file

@ -288,11 +288,11 @@ mod test {
#[test] #[test]
fn test_show() { fn test_show() {
let mut e = EnumSet::new(); let mut e = EnumSet::new();
assert_eq!("{}", e.to_string().as_slice()); assert_eq!("{}", e.to_string());
e.insert(A); e.insert(A);
assert_eq!("{A}", e.to_string().as_slice()); assert_eq!("{A}", e.to_string());
e.insert(C); e.insert(C);
assert_eq!("{A, C}", e.to_string().as_slice()); assert_eq!("{A, C}", e.to_string());
} }
#[test] #[test]

View file

@ -1246,7 +1246,7 @@ mod tests {
} }
{ {
let b: &[_] = &[&0,&1,&2,&3,&4]; let b: &[_] = &[&0,&1,&2,&3,&4];
assert_eq!(d.iter().collect::<Vec<&int>>().as_slice(), b); assert_eq!(d.iter().collect::<Vec<&int>>(), b);
} }
for i in range(6i, 9) { for i in range(6i, 9) {
@ -1254,7 +1254,7 @@ mod tests {
} }
{ {
let b: &[_] = &[&8,&7,&6,&0,&1,&2,&3,&4]; let b: &[_] = &[&8,&7,&6,&0,&1,&2,&3,&4];
assert_eq!(d.iter().collect::<Vec<&int>>().as_slice(), b); assert_eq!(d.iter().collect::<Vec<&int>>(), b);
} }
let mut it = d.iter(); let mut it = d.iter();
@ -1277,14 +1277,14 @@ mod tests {
} }
{ {
let b: &[_] = &[&4,&3,&2,&1,&0]; let b: &[_] = &[&4,&3,&2,&1,&0];
assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), b); assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b);
} }
for i in range(6i, 9) { for i in range(6i, 9) {
d.push_front(i); d.push_front(i);
} }
let b: &[_] = &[&4,&3,&2,&1,&0,&6,&7,&8]; let b: &[_] = &[&4,&3,&2,&1,&0,&6,&7,&8];
assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), b); assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b);
} }
#[test] #[test]
@ -1495,12 +1495,12 @@ mod tests {
#[test] #[test]
fn test_show() { fn test_show() {
let ringbuf: RingBuf<int> = range(0i, 10).collect(); let ringbuf: RingBuf<int> = range(0i, 10).collect();
assert!(format!("{}", ringbuf).as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); assert!(format!("{}", ringbuf) == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter() let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter()
.map(|&s| s) .map(|&s| s)
.collect(); .collect();
assert!(format!("{}", ringbuf).as_slice() == "[just, one, test, more]"); assert!(format!("{}", ringbuf) == "[just, one, test, more]");
} }
#[test] #[test]

View file

@ -201,7 +201,7 @@ impl Iterator<(uint, uint)> for ElementSwaps {
match max { match max {
Some((i, sd)) => { Some((i, sd)) => {
let j = new_pos(i, sd.dir); let j = new_pos(i, sd.dir);
self.sdir.as_mut_slice().swap(i, j); self.sdir.swap(i, j);
// Swap the direction of each larger SizeDirection // Swap the direction of each larger SizeDirection
for x in self.sdir.iter_mut() { for x in self.sdir.iter_mut() {
@ -256,7 +256,7 @@ impl<T: Clone> Iterator<Vec<T>> for Permutations<T> {
Some((0,0)) => Some(self.v.clone()), Some((0,0)) => Some(self.v.clone()),
Some((a, b)) => { Some((a, b)) => {
let elt = self.v.clone(); let elt = self.v.clone();
self.v.as_mut_slice().swap(a, b); self.v.swap(a, b);
Some(elt) Some(elt)
} }
} }
@ -779,11 +779,11 @@ mod tests {
#[test] #[test]
fn test_head_mut() { fn test_head_mut() {
let mut a = vec![]; let mut a = vec![];
assert_eq!(a.as_mut_slice().head_mut(), None); assert_eq!(a.head_mut(), None);
a = vec![11i]; a = vec![11i];
assert_eq!(*a.as_mut_slice().head_mut().unwrap(), 11); assert_eq!(*a.head_mut().unwrap(), 11);
a = vec![11i, 12]; a = vec![11i, 12];
assert_eq!(*a.as_mut_slice().head_mut().unwrap(), 11); assert_eq!(*a.head_mut().unwrap(), 11);
} }
#[test] #[test]
@ -800,10 +800,10 @@ mod tests {
fn test_tail_mut() { fn test_tail_mut() {
let mut a = vec![11i]; let mut a = vec![11i];
let b: &mut [int] = &mut []; let b: &mut [int] = &mut [];
assert!(a.as_mut_slice().tail_mut() == b); assert!(a.tail_mut() == b);
a = vec![11i, 12]; a = vec![11i, 12];
let b: &mut [int] = &mut [12]; let b: &mut [int] = &mut [12];
assert!(a.as_mut_slice().tail_mut() == b); assert!(a.tail_mut() == b);
} }
#[test] #[test]
@ -817,7 +817,7 @@ mod tests {
#[should_fail] #[should_fail]
fn test_tail_mut_empty() { fn test_tail_mut_empty() {
let mut a: Vec<int> = vec![]; let mut a: Vec<int> = vec![];
a.as_mut_slice().tail_mut(); a.tail_mut();
} }
#[test] #[test]
@ -834,10 +834,10 @@ mod tests {
fn test_init_mut() { fn test_init_mut() {
let mut a = vec![11i]; let mut a = vec![11i];
let b: &mut [int] = &mut []; let b: &mut [int] = &mut [];
assert!(a.as_mut_slice().init_mut() == b); assert!(a.init_mut() == b);
a = vec![11i, 12]; a = vec![11i, 12];
let b: &mut [int] = &mut [11]; let b: &mut [int] = &mut [11];
assert!(a.as_mut_slice().init_mut() == b); assert!(a.init_mut() == b);
} }
#[test] #[test]
@ -851,7 +851,7 @@ mod tests {
#[should_fail] #[should_fail]
fn test_init_mut_empty() { fn test_init_mut_empty() {
let mut a: Vec<int> = vec![]; let mut a: Vec<int> = vec![];
a.as_mut_slice().init_mut(); a.init_mut();
} }
#[test] #[test]
@ -867,11 +867,11 @@ mod tests {
#[test] #[test]
fn test_last_mut() { fn test_last_mut() {
let mut a = vec![]; let mut a = vec![];
assert_eq!(a.as_mut_slice().last_mut(), None); assert_eq!(a.last_mut(), None);
a = vec![11i]; a = vec![11i];
assert_eq!(*a.as_mut_slice().last_mut().unwrap(), 11); assert_eq!(*a.last_mut().unwrap(), 11);
a = vec![11i, 12]; a = vec![11i, 12];
assert_eq!(*a.as_mut_slice().last_mut().unwrap(), 12); assert_eq!(*a.last_mut().unwrap(), 12);
} }
#[test] #[test]
@ -1299,13 +1299,13 @@ mod tests {
.collect::<Vec<uint>>(); .collect::<Vec<uint>>();
let mut v1 = v.clone(); let mut v1 = v.clone();
v.as_mut_slice().sort(); v.sort();
assert!(v.as_slice().windows(2).all(|w| w[0] <= w[1])); assert!(v.as_slice().windows(2).all(|w| w[0] <= w[1]));
v1.as_mut_slice().sort_by(|a, b| a.cmp(b)); v1.sort_by(|a, b| a.cmp(b));
assert!(v1.as_slice().windows(2).all(|w| w[0] <= w[1])); assert!(v1.as_slice().windows(2).all(|w| w[0] <= w[1]));
v1.as_mut_slice().sort_by(|a, b| b.cmp(a)); v1.sort_by(|a, b| b.cmp(a));
assert!(v1.as_slice().windows(2).all(|w| w[0] >= w[1])); assert!(v1.as_slice().windows(2).all(|w| w[0] >= w[1]));
} }
} }
@ -1652,24 +1652,24 @@ mod tests {
let xs = &[1i,2,3,4,5]; let xs = &[1i,2,3,4,5];
let splits: &[&[int]] = &[&[1], &[3], &[5]]; let splits: &[&[int]] = &[&[1], &[3], &[5]];
assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[], &[2,3,4,5]]; let splits: &[&[int]] = &[&[], &[2,3,4,5]];
assert_eq!(xs.split(|x| *x == 1).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|x| *x == 1).collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[1,2,3,4], &[]]; let splits: &[&[int]] = &[&[1,2,3,4], &[]];
assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[1,2,3,4,5]]; let splits: &[&[int]] = &[&[1,2,3,4,5]];
assert_eq!(xs.split(|x| *x == 10).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|x| *x == 10).collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[], &[], &[], &[], &[], &[]]; let splits: &[&[int]] = &[&[], &[], &[], &[], &[], &[]];
assert_eq!(xs.split(|_| true).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|_| true).collect::<Vec<&[int]>>(),
splits); splits);
let xs: &[int] = &[]; let xs: &[int] = &[];
let splits: &[&[int]] = &[&[]]; let splits: &[&[int]] = &[&[]];
assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits); assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>(), splits);
} }
#[test] #[test]
@ -1677,18 +1677,18 @@ mod tests {
let xs = &[1i,2,3,4,5]; let xs = &[1i,2,3,4,5];
let splits: &[&[int]] = &[&[1,2,3,4,5]]; let splits: &[&[int]] = &[&[1,2,3,4,5]];
assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[1], &[3,4,5]]; let splits: &[&[int]] = &[&[1], &[3,4,5]];
assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[], &[], &[], &[4,5]]; let splits: &[&[int]] = &[&[], &[], &[], &[4,5]];
assert_eq!(xs.splitn(3, |_| true).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.splitn(3, |_| true).collect::<Vec<&[int]>>(),
splits); splits);
let xs: &[int] = &[]; let xs: &[int] = &[];
let splits: &[&[int]] = &[&[]]; let splits: &[&[int]] = &[&[]];
assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits); assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>(), splits);
} }
#[test] #[test]
@ -1696,18 +1696,18 @@ mod tests {
let xs = &mut [1i,2,3,4,5]; let xs = &mut [1i,2,3,4,5];
let splits: &[&mut [int]] = &[&mut [1,2,3,4,5]]; let splits: &[&mut [int]] = &[&mut [1,2,3,4,5]];
assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(), assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(),
splits); splits);
let splits: &[&mut [int]] = &[&mut [1], &mut [3,4,5]]; let splits: &[&mut [int]] = &[&mut [1], &mut [3,4,5]];
assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(), assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(),
splits); splits);
let splits: &[&mut [int]] = &[&mut [], &mut [], &mut [], &mut [4,5]]; let splits: &[&mut [int]] = &[&mut [], &mut [], &mut [], &mut [4,5]];
assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>().as_slice(), assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>(),
splits); splits);
let xs: &mut [int] = &mut []; let xs: &mut [int] = &mut [];
let splits: &[&mut [int]] = &[&mut []]; let splits: &[&mut [int]] = &[&mut []];
assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>().as_slice(), assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>(),
splits); splits);
} }
@ -1716,21 +1716,21 @@ mod tests {
let xs = &[1i,2,3,4,5]; let xs = &[1i,2,3,4,5];
let splits: &[&[int]] = &[&[5], &[3], &[1]]; let splits: &[&[int]] = &[&[5], &[3], &[1]];
assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[2,3,4,5], &[]]; let splits: &[&[int]] = &[&[2,3,4,5], &[]];
assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[], &[1,2,3,4]]; let splits: &[&[int]] = &[&[], &[1,2,3,4]];
assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[1,2,3,4,5]]; let splits: &[&[int]] = &[&[1,2,3,4,5]];
assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<&[int]>>(),
splits); splits);
let xs: &[int] = &[]; let xs: &[int] = &[];
let splits: &[&[int]] = &[&[]]; let splits: &[&[int]] = &[&[]];
assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>().as_slice(), splits); assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>(), splits);
} }
#[test] #[test]
@ -1738,18 +1738,18 @@ mod tests {
let xs = &[1,2,3,4,5]; let xs = &[1,2,3,4,5];
let splits: &[&[int]] = &[&[1,2,3,4,5]]; let splits: &[&[int]] = &[&[1,2,3,4,5]];
assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[5], &[1,2,3]]; let splits: &[&[int]] = &[&[5], &[1,2,3]];
assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
splits); splits);
let splits: &[&[int]] = &[&[], &[], &[], &[1,2]]; let splits: &[&[int]] = &[&[], &[], &[], &[1,2]];
assert_eq!(xs.rsplitn(3, |_| true).collect::<Vec<&[int]>>().as_slice(), assert_eq!(xs.rsplitn(3, |_| true).collect::<Vec<&[int]>>(),
splits); splits);
let xs: &[int] = &[]; let xs: &[int] = &[];
let splits: &[&[int]] = &[&[]]; let splits: &[&[int]] = &[&[]];
assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits); assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<Vec<&[int]>>(), splits);
} }
#[test] #[test]
@ -1757,9 +1757,9 @@ mod tests {
let v = &[1i,2,3,4]; let v = &[1i,2,3,4];
let wins: &[&[int]] = &[&[1,2], &[2,3], &[3,4]]; let wins: &[&[int]] = &[&[1,2], &[2,3], &[3,4]];
assert_eq!(v.windows(2).collect::<Vec<&[int]>>().as_slice(), wins); assert_eq!(v.windows(2).collect::<Vec<&[int]>>(), wins);
let wins: &[&[int]] = &[&[1i,2,3], &[2,3,4]]; let wins: &[&[int]] = &[&[1i,2,3], &[2,3,4]];
assert_eq!(v.windows(3).collect::<Vec<&[int]>>().as_slice(), wins); assert_eq!(v.windows(3).collect::<Vec<&[int]>>(), wins);
assert!(v.windows(6).next().is_none()); assert!(v.windows(6).next().is_none());
} }
@ -1775,14 +1775,14 @@ mod tests {
let v = &[1i,2,3,4,5]; let v = &[1i,2,3,4,5];
let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]]; let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]];
assert_eq!(v.chunks(2).collect::<Vec<&[int]>>().as_slice(), chunks); assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks);
let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]]; let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]];
assert_eq!(v.chunks(3).collect::<Vec<&[int]>>().as_slice(), chunks); assert_eq!(v.chunks(3).collect::<Vec<&[int]>>(), chunks);
let chunks: &[&[int]] = &[&[1i,2,3,4,5]]; let chunks: &[&[int]] = &[&[1i,2,3,4,5]];
assert_eq!(v.chunks(6).collect::<Vec<&[int]>>().as_slice(), chunks); assert_eq!(v.chunks(6).collect::<Vec<&[int]>>(), chunks);
let chunks: &[&[int]] = &[&[5i], &[3,4], &[1,2]]; let chunks: &[&[int]] = &[&[5i], &[3,4], &[1,2]];
assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>().as_slice(), chunks); assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>(), chunks);
let mut it = v.chunks(2); let mut it = v.chunks(2);
assert_eq!(it.indexable(), 3); assert_eq!(it.indexable(), 3);
let chunk: &[int] = &[1,2]; let chunk: &[int] = &[1,2];
@ -1838,20 +1838,20 @@ mod tests {
}) })
) )
let empty: Vec<int> = vec![]; let empty: Vec<int> = vec![];
test_show_vec!(empty, "[]".to_string()); test_show_vec!(empty, "[]");
test_show_vec!(vec![1i], "[1]".to_string()); test_show_vec!(vec![1i], "[1]");
test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]".to_string()); test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]");
test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]], test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]],
"[[], [1], [1, 1]]".to_string()); "[[], [1], [1, 1]]");
let empty_mut: &mut [int] = &mut[]; let empty_mut: &mut [int] = &mut[];
test_show_vec!(empty_mut, "[]".to_string()); test_show_vec!(empty_mut, "[]");
let v: &mut[int] = &mut[1]; let v: &mut[int] = &mut[1];
test_show_vec!(v, "[1]".to_string()); test_show_vec!(v, "[1]");
let v: &mut[int] = &mut[1, 2, 3]; let v: &mut[int] = &mut[1, 2, 3];
test_show_vec!(v, "[1, 2, 3]".to_string()); test_show_vec!(v, "[1, 2, 3]");
let v: &mut [&mut[uint]] = &mut[&mut[], &mut[1u], &mut[1u, 1u]]; let v: &mut [&mut[uint]] = &mut[&mut[], &mut[1u], &mut[1u, 1u]];
test_show_vec!(v, "[[], [1], [1, 1]]".to_string()); test_show_vec!(v, "[[], [1], [1, 1]]");
} }
#[test] #[test]
@ -2081,7 +2081,7 @@ mod tests {
fn test_to_vec() { fn test_to_vec() {
let xs = box [1u, 2, 3]; let xs = box [1u, 2, 3];
let ys = xs.to_vec(); let ys = xs.to_vec();
assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice()); assert_eq!(ys, [1u, 2, 3]);
} }
} }

View file

@ -215,7 +215,7 @@ pub struct Decompositions<'a> {
impl<'a> Iterator<char> for Decompositions<'a> { impl<'a> Iterator<char> for Decompositions<'a> {
#[inline] #[inline]
fn next(&mut self) -> Option<char> { fn next(&mut self) -> Option<char> {
match self.buffer.as_slice().head() { match self.buffer.head() {
Some(&(c, 0)) => { Some(&(c, 0)) => {
self.sorted = false; self.sorted = false;
self.buffer.remove(0); self.buffer.remove(0);
@ -915,10 +915,10 @@ mod tests {
#[test] #[test]
fn test_collect() { fn test_collect() {
let empty = String::from_str(""); let empty = String::from_str("");
let s: String = empty.as_slice().chars().collect(); let s: String = empty.chars().collect();
assert_eq!(empty, s); assert_eq!(empty, s);
let data = String::from_str("ประเทศไทย中"); let data = String::from_str("ประเทศไทย中");
let s: String = data.as_slice().chars().collect(); let s: String = data.chars().collect();
assert_eq!(data, s); assert_eq!(data, s);
} }
@ -926,7 +926,7 @@ mod tests {
fn test_into_bytes() { fn test_into_bytes() {
let data = String::from_str("asdf"); let data = String::from_str("asdf");
let buf = data.into_bytes(); let buf = data.into_bytes();
assert_eq!(b"asdf", buf.as_slice()); assert_eq!(b"asdf", buf);
} }
#[test] #[test]
@ -943,21 +943,21 @@ mod tests {
let string = "ประเทศไทย中华Việt Nam"; let string = "ประเทศไทย中华Việt Nam";
let mut data = String::from_str(string); let mut data = String::from_str(string);
data.push_str(string); data.push_str(string);
assert!(data.as_slice().find_str("ไท华").is_none()); assert!(data.find_str("ไท华").is_none());
assert_eq!(data.as_slice().slice(0u, 43u).find_str(""), Some(0u)); assert_eq!(data.slice(0u, 43u).find_str(""), Some(0u));
assert_eq!(data.as_slice().slice(6u, 43u).find_str(""), Some(6u - 6u)); assert_eq!(data.slice(6u, 43u).find_str(""), Some(6u - 6u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("ประ"), Some( 0u)); assert_eq!(data.slice(0u, 43u).find_str("ประ"), Some( 0u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("ทศไ"), Some(12u)); assert_eq!(data.slice(0u, 43u).find_str("ทศไ"), Some(12u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("ย中"), Some(24u)); assert_eq!(data.slice(0u, 43u).find_str("ย中"), Some(24u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("iệt"), Some(34u)); assert_eq!(data.slice(0u, 43u).find_str("iệt"), Some(34u));
assert_eq!(data.as_slice().slice(0u, 43u).find_str("Nam"), Some(40u)); assert_eq!(data.slice(0u, 43u).find_str("Nam"), Some(40u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("ประ"), Some(43u - 43u)); assert_eq!(data.slice(43u, 86u).find_str("ประ"), Some(43u - 43u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u)); assert_eq!(data.slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("ย中"), Some(67u - 43u)); assert_eq!(data.slice(43u, 86u).find_str("ย中"), Some(67u - 43u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("iệt"), Some(77u - 43u)); assert_eq!(data.slice(43u, 86u).find_str("iệt"), Some(77u - 43u));
assert_eq!(data.as_slice().slice(43u, 86u).find_str("Nam"), Some(83u - 43u)); assert_eq!(data.slice(43u, 86u).find_str("Nam"), Some(83u - 43u));
} }
#[test] #[test]
@ -989,7 +989,7 @@ mod tests {
($expected: expr, $string: expr) => { ($expected: expr, $string: expr) => {
{ {
let s = $string.concat(); let s = $string.concat();
assert_eq!($expected, s.as_slice()); assert_eq!($expected, s);
} }
} }
} }
@ -1027,7 +1027,7 @@ mod tests {
($expected: expr, $string: expr, $delim: expr) => { ($expected: expr, $string: expr, $delim: expr) => {
{ {
let s = $string.connect($delim); let s = $string.connect($delim);
assert_eq!($expected, s.as_slice()); assert_eq!($expected, s);
} }
} }
} }
@ -1148,7 +1148,7 @@ mod tests {
let a = "ประเ"; let a = "ประเ";
let a2 = "دولة الكويتทศไทย中华"; let a2 = "دولة الكويتทศไทย中华";
assert_eq!(data.replace(a, repl).as_slice(), a2); assert_eq!(data.replace(a, repl), a2);
} }
#[test] #[test]
@ -1158,7 +1158,7 @@ mod tests {
let b = "ะเ"; let b = "ะเ";
let b2 = "ปรدولة الكويتทศไทย中华"; let b2 = "ปรدولة الكويتทศไทย中华";
assert_eq!(data.replace(b, repl).as_slice(), b2); assert_eq!(data.replace(b, repl), b2);
} }
#[test] #[test]
@ -1168,7 +1168,7 @@ mod tests {
let c = "中华"; let c = "中华";
let c2 = "ประเทศไทยدولة الكويت"; let c2 = "ประเทศไทยدولة الكويت";
assert_eq!(data.replace(c, repl).as_slice(), c2); assert_eq!(data.replace(c, repl), c2);
} }
#[test] #[test]
@ -1177,7 +1177,7 @@ mod tests {
let repl = "دولة الكويت"; let repl = "دولة الكويت";
let d = "ไท华"; let d = "ไท华";
assert_eq!(data.replace(d, repl).as_slice(), data); assert_eq!(data.replace(d, repl), data);
} }
#[test] #[test]
@ -1213,7 +1213,7 @@ mod tests {
} }
let letters = a_million_letter_x(); let letters = a_million_letter_x();
assert!(half_a_million_letter_x() == assert!(half_a_million_letter_x() ==
String::from_str(letters.as_slice().slice(0u, 3u * 500000u))); String::from_str(letters.slice(0u, 3u * 500000u)));
} }
#[test] #[test]
@ -1452,7 +1452,7 @@ mod tests {
let b: &[u8] = &[]; let b: &[u8] = &[];
assert_eq!("".as_bytes(), b); assert_eq!("".as_bytes(), b);
assert_eq!("abc".as_bytes(), b"abc"); assert_eq!("abc".as_bytes(), b"abc");
assert_eq!("ศไทย中华Việt Nam".as_bytes(), v.as_slice()); assert_eq!("ศไทย中华Việt Nam".as_bytes(), v);
} }
#[test] #[test]
@ -1487,7 +1487,6 @@ mod tests {
let string = "a\nb\nc"; let string = "a\nb\nc";
let lines: Vec<&str> = string.lines().collect(); let lines: Vec<&str> = string.lines().collect();
let lines = lines.as_slice();
assert_eq!(string.subslice_offset(lines[0]), 0); assert_eq!(string.subslice_offset(lines[0]), 0);
assert_eq!(string.subslice_offset(lines[1]), 2); assert_eq!(string.subslice_offset(lines[1]), 2);
assert_eq!(string.subslice_offset(lines[2]), 4); assert_eq!(string.subslice_offset(lines[2]), 4);
@ -1834,7 +1833,7 @@ mod tests {
fn test_nfd_chars() { fn test_nfd_chars() {
macro_rules! t { macro_rules! t {
($input: expr, $expected: expr) => { ($input: expr, $expected: expr) => {
assert_eq!($input.nfd_chars().collect::<String>(), $expected.into_string()); assert_eq!($input.nfd_chars().collect::<String>(), $expected);
} }
} }
t!("abc", "abc"); t!("abc", "abc");
@ -1853,7 +1852,7 @@ mod tests {
fn test_nfkd_chars() { fn test_nfkd_chars() {
macro_rules! t { macro_rules! t {
($input: expr, $expected: expr) => { ($input: expr, $expected: expr) => {
assert_eq!($input.nfkd_chars().collect::<String>(), $expected.into_string()); assert_eq!($input.nfkd_chars().collect::<String>(), $expected);
} }
} }
t!("abc", "abc"); t!("abc", "abc");
@ -1872,7 +1871,7 @@ mod tests {
fn test_nfc_chars() { fn test_nfc_chars() {
macro_rules! t { macro_rules! t {
($input: expr, $expected: expr) => { ($input: expr, $expected: expr) => {
assert_eq!($input.nfc_chars().collect::<String>(), $expected.into_string()); assert_eq!($input.nfc_chars().collect::<String>(), $expected);
} }
} }
t!("abc", "abc"); t!("abc", "abc");
@ -1892,7 +1891,7 @@ mod tests {
fn test_nfkc_chars() { fn test_nfkc_chars() {
macro_rules! t { macro_rules! t {
($input: expr, $expected: expr) => { ($input: expr, $expected: expr) => {
assert_eq!($input.nfkc_chars().collect::<String>(), $expected.into_string()); assert_eq!($input.nfkc_chars().collect::<String>(), $expected);
} }
} }
t!("abc", "abc"); t!("abc", "abc");
@ -2183,10 +2182,10 @@ mod tests {
let s = "a̐éö̲\r\n"; let s = "a̐éö̲\r\n";
let gr_inds = s.grapheme_indices(true).collect::<Vec<(uint, &str)>>(); let gr_inds = s.grapheme_indices(true).collect::<Vec<(uint, &str)>>();
let b: &[_] = &[(0u, ""), (3, ""), (6, "ö̲"), (11, "\r\n")]; let b: &[_] = &[(0u, ""), (3, ""), (6, "ö̲"), (11, "\r\n")];
assert_eq!(gr_inds.as_slice(), b); assert_eq!(gr_inds, b);
let gr_inds = s.grapheme_indices(true).rev().collect::<Vec<(uint, &str)>>(); let gr_inds = s.grapheme_indices(true).rev().collect::<Vec<(uint, &str)>>();
let b: &[_] = &[(11, "\r\n"), (6, "ö̲"), (3, ""), (0u, "")]; let b: &[_] = &[(11, "\r\n"), (6, "ö̲"), (3, ""), (0u, "")];
assert_eq!(gr_inds.as_slice(), b); assert_eq!(gr_inds, b);
let mut gr_inds_iter = s.grapheme_indices(true); let mut gr_inds_iter = s.grapheme_indices(true);
{ {
let gr_inds = gr_inds_iter.by_ref(); let gr_inds = gr_inds_iter.by_ref();
@ -2202,14 +2201,14 @@ mod tests {
let s = "\n\r\n\r"; let s = "\n\r\n\r";
let gr = s.graphemes(true).rev().collect::<Vec<&str>>(); let gr = s.graphemes(true).rev().collect::<Vec<&str>>();
let b: &[_] = &["\r", "\r\n", "\n"]; let b: &[_] = &["\r", "\r\n", "\n"];
assert_eq!(gr.as_slice(), b); assert_eq!(gr, b);
} }
#[test] #[test]
fn test_split_strator() { fn test_split_strator() {
fn t(s: &str, sep: &str, u: &[&str]) { fn t(s: &str, sep: &str, u: &[&str]) {
let v: Vec<&str> = s.split_str(sep).collect(); let v: Vec<&str> = s.split_str(sep).collect();
assert_eq!(v.as_slice(), u.as_slice()); assert_eq!(v, u);
} }
t("--1233345--", "12345", &["--1233345--"]); t("--1233345--", "12345", &["--1233345--"]);
t("abc::hello::there", "::", &["abc", "hello", "there"]); t("abc::hello::there", "::", &["abc", "hello", "there"]);

View file

@ -559,7 +559,7 @@ impl String {
#[inline] #[inline]
#[unstable = "the panic conventions for strings are under development"] #[unstable = "the panic conventions for strings are under development"]
pub fn truncate(&mut self, new_len: uint) { pub fn truncate(&mut self, new_len: uint) {
assert!(self.as_slice().is_char_boundary(new_len)); assert!(self.is_char_boundary(new_len));
self.vec.truncate(new_len) self.vec.truncate(new_len)
} }
@ -583,7 +583,7 @@ impl String {
return None return None
} }
let CharRange {ch, next} = self.as_slice().char_range_at_reverse(len); let CharRange {ch, next} = self.char_range_at_reverse(len);
unsafe { unsafe {
self.vec.set_len(next); self.vec.set_len(next);
} }
@ -618,7 +618,7 @@ impl String {
let len = self.len(); let len = self.len();
if idx >= len { return None } if idx >= len { return None }
let CharRange { ch, next } = self.as_slice().char_range_at(idx); let CharRange { ch, next } = self.char_range_at(idx);
unsafe { unsafe {
ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as int), ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as int),
self.vec.as_ptr().offset(next as int), self.vec.as_ptr().offset(next as int),
@ -643,7 +643,7 @@ impl String {
pub fn insert(&mut self, idx: uint, ch: char) { pub fn insert(&mut self, idx: uint, ch: char) {
let len = self.len(); let len = self.len();
assert!(idx <= len); assert!(idx <= len);
assert!(self.as_slice().is_char_boundary(idx)); assert!(self.is_char_boundary(idx));
self.vec.reserve(4); self.vec.reserve(4);
let mut bits = [0, ..4]; let mut bits = [0, ..4];
let amt = ch.encode_utf8(&mut bits).unwrap(); let amt = ch.encode_utf8(&mut bits).unwrap();
@ -1092,7 +1092,7 @@ mod tests {
for p in pairs.iter() { for p in pairs.iter() {
let (s, u) = (*p).clone(); let (s, u) = (*p).clone();
let s_as_utf16 = s.as_slice().utf16_units().collect::<Vec<u16>>(); let s_as_utf16 = s.utf16_units().collect::<Vec<u16>>();
let u_as_string = String::from_utf16(u.as_slice()).unwrap(); let u_as_string = String::from_utf16(u.as_slice()).unwrap();
assert!(str::is_utf16(u.as_slice())); assert!(str::is_utf16(u.as_slice()));
@ -1102,7 +1102,7 @@ mod tests {
assert_eq!(String::from_utf16_lossy(u.as_slice()), s); assert_eq!(String::from_utf16_lossy(u.as_slice()), s);
assert_eq!(String::from_utf16(s_as_utf16.as_slice()).unwrap(), s); assert_eq!(String::from_utf16(s_as_utf16.as_slice()).unwrap(), s);
assert_eq!(u_as_string.as_slice().utf16_units().collect::<Vec<u16>>(), u); assert_eq!(u_as_string.utf16_units().collect::<Vec<u16>>(), u);
} }
} }
@ -1162,18 +1162,18 @@ mod tests {
let mv = s.as_mut_vec(); let mv = s.as_mut_vec();
mv.push_all(&[b'D']); mv.push_all(&[b'D']);
} }
assert_eq!(s.as_slice(), "ABCD"); assert_eq!(s, "ABCD");
} }
#[test] #[test]
fn test_push_str() { fn test_push_str() {
let mut s = String::new(); let mut s = String::new();
s.push_str(""); s.push_str("");
assert_eq!(s.as_slice().slice_from(0), ""); assert_eq!(s.slice_from(0), "");
s.push_str("abc"); s.push_str("abc");
assert_eq!(s.as_slice().slice_from(0), "abc"); assert_eq!(s.slice_from(0), "abc");
s.push_str("ประเทศไทย中华Việt Nam"); s.push_str("ประเทศไทย中华Việt Nam");
assert_eq!(s.as_slice().slice_from(0), "abcประเทศไทย中华Việt Nam"); assert_eq!(s.slice_from(0), "abcประเทศไทย中华Việt Nam");
} }
#[test] #[test]
@ -1184,7 +1184,7 @@ mod tests {
data.push('¢'); // 2 byte data.push('¢'); // 2 byte
data.push('€'); // 3 byte data.push('€'); // 3 byte
data.push('𤭢'); // 4 byte data.push('𤭢'); // 4 byte
assert_eq!(data.as_slice(), "ประเทศไทย中华b¢€𤭢"); assert_eq!(data, "ประเทศไทย中华b¢€𤭢");
} }
#[test] #[test]
@ -1195,24 +1195,24 @@ mod tests {
assert_eq!(data.pop().unwrap(), '¢'); // 2 bytes assert_eq!(data.pop().unwrap(), '¢'); // 2 bytes
assert_eq!(data.pop().unwrap(), 'b'); // 1 bytes assert_eq!(data.pop().unwrap(), 'b'); // 1 bytes
assert_eq!(data.pop().unwrap(), '华'); assert_eq!(data.pop().unwrap(), '华');
assert_eq!(data.as_slice(), "ประเทศไทย中"); assert_eq!(data, "ประเทศไทย中");
} }
#[test] #[test]
fn test_str_truncate() { fn test_str_truncate() {
let mut s = String::from_str("12345"); let mut s = String::from_str("12345");
s.truncate(5); s.truncate(5);
assert_eq!(s.as_slice(), "12345"); assert_eq!(s, "12345");
s.truncate(3); s.truncate(3);
assert_eq!(s.as_slice(), "123"); assert_eq!(s, "123");
s.truncate(0); s.truncate(0);
assert_eq!(s.as_slice(), ""); assert_eq!(s, "");
let mut s = String::from_str("12345"); let mut s = String::from_str("12345");
let p = s.as_slice().as_ptr(); let p = s.as_ptr();
s.truncate(3); s.truncate(3);
s.push_str("6"); s.push_str("6");
let p_ = s.as_slice().as_ptr(); let p_ = s.as_ptr();
assert_eq!(p_, p); assert_eq!(p_, p);
} }
@ -1235,7 +1235,7 @@ mod tests {
let mut s = String::from_str("12345"); let mut s = String::from_str("12345");
s.clear(); s.clear();
assert_eq!(s.len(), 0); assert_eq!(s.len(), 0);
assert_eq!(s.as_slice(), ""); assert_eq!(s, "");
} }
#[test] #[test]
@ -1244,7 +1244,7 @@ mod tests {
let b = a + "2"; let b = a + "2";
let b = b + String::from_str("2"); let b = b + String::from_str("2");
assert_eq!(b.len(), 7); assert_eq!(b.len(), 7);
assert_eq!(b.as_slice(), "1234522"); assert_eq!(b, "1234522");
} }
#[test] #[test]
@ -1252,11 +1252,11 @@ mod tests {
let mut s = "ศไทย中华Việt Nam; foobar".to_string();; let mut s = "ศไทย中华Việt Nam; foobar".to_string();;
assert_eq!(s.remove(0), Some('ศ')); assert_eq!(s.remove(0), Some('ศ'));
assert_eq!(s.len(), 33); assert_eq!(s.len(), 33);
assert_eq!(s.as_slice(), "ไทย中华Việt Nam; foobar"); assert_eq!(s, "ไทย中华Việt Nam; foobar");
assert_eq!(s.remove(33), None); assert_eq!(s.remove(33), None);
assert_eq!(s.remove(300), None); assert_eq!(s.remove(300), None);
assert_eq!(s.remove(17), Some('ệ')); assert_eq!(s.remove(17), Some('ệ'));
assert_eq!(s.as_slice(), "ไทย中华Vit Nam; foobar"); assert_eq!(s, "ไทย中华Vit Nam; foobar");
} }
#[test] #[should_fail] #[test] #[should_fail]
@ -1268,9 +1268,9 @@ mod tests {
fn insert() { fn insert() {
let mut s = "foobar".to_string(); let mut s = "foobar".to_string();
s.insert(0, 'ệ'); s.insert(0, 'ệ');
assert_eq!(s.as_slice(), "ệfoobar"); assert_eq!(s, "ệfoobar");
s.insert(6, 'ย'); s.insert(6, 'ย');
assert_eq!(s.as_slice(), "ệfooยbar"); assert_eq!(s, "ệfooยbar");
} }
#[test] #[should_fail] fn insert_bad1() { "".to_string().insert(1, 't'); } #[test] #[should_fail] fn insert_bad1() { "".to_string().insert(1, 't'); }
@ -1287,24 +1287,24 @@ mod tests {
#[test] #[test]
fn test_simple_types() { fn test_simple_types() {
assert_eq!(1i.to_string(), "1".to_string()); assert_eq!(1i.to_string(), "1");
assert_eq!((-1i).to_string(), "-1".to_string()); assert_eq!((-1i).to_string(), "-1");
assert_eq!(200u.to_string(), "200".to_string()); assert_eq!(200u.to_string(), "200");
assert_eq!(2u8.to_string(), "2".to_string()); assert_eq!(2u8.to_string(), "2");
assert_eq!(true.to_string(), "true".to_string()); assert_eq!(true.to_string(), "true");
assert_eq!(false.to_string(), "false".to_string()); assert_eq!(false.to_string(), "false");
assert_eq!(().to_string(), "()".to_string()); assert_eq!(().to_string(), "()");
assert_eq!(("hi".to_string()).to_string(), "hi".to_string()); assert_eq!(("hi".to_string()).to_string(), "hi");
} }
#[test] #[test]
fn test_vectors() { fn test_vectors() {
let x: Vec<int> = vec![]; let x: Vec<int> = vec![];
assert_eq!(x.to_string(), "[]".to_string()); assert_eq!(x.to_string(), "[]");
assert_eq!((vec![1i]).to_string(), "[1]".to_string()); assert_eq!((vec![1i]).to_string(), "[1]");
assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]".to_string()); assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]");
assert!((vec![vec![], vec![1i], vec![1i, 1]]).to_string() == assert!((vec![vec![], vec![1i], vec![1i, 1]]).to_string() ==
"[[], [1], [1, 1]]".to_string()); "[[], [1], [1, 1]]");
} }
#[bench] #[bench]

View file

@ -1735,8 +1735,8 @@ mod test_treemap {
let map_str = format!("{}", map); let map_str = format!("{}", map);
assert!(map_str == "{1: 2, 3: 4}".to_string()); assert!(map_str == "{1: 2, 3: 4}");
assert_eq!(format!("{}", empty), "{}".to_string()); assert_eq!(format!("{}", empty), "{}");
} }
#[test] #[test]

View file

@ -1103,7 +1103,7 @@ mod test {
let set_str = format!("{}", set); let set_str = format!("{}", set);
assert!(set_str == "{1, 2}".to_string()); assert!(set_str == "{1, 2}");
assert_eq!(format!("{}", empty), "{}".to_string()); assert_eq!(format!("{}", empty), "{}");
} }
} }

View file

@ -1605,8 +1605,8 @@ mod test {
let map_str = format!("{}", map); let map_str = format!("{}", map);
assert!(map_str == "{1: a, 2: b}".to_string()); assert!(map_str == "{1: a, 2: b}");
assert_eq!(format!("{}", empty), "{}".to_string()); assert_eq!(format!("{}", empty), "{}");
} }
#[test] #[test]

View file

@ -696,8 +696,8 @@ mod test {
let set_str = format!("{}", set); let set_str = format!("{}", set);
assert!(set_str == "{1, 2}".to_string()); assert!(set_str == "{1, 2}");
assert_eq!(format!("{}", empty), "{}".to_string()); assert_eq!(format!("{}", empty), "{}");
} }
#[test] #[test]

View file

@ -211,7 +211,7 @@ impl<T> Vec<T> {
let mut xs = Vec::with_capacity(length); let mut xs = Vec::with_capacity(length);
while xs.len < length { while xs.len < length {
let len = xs.len; let len = xs.len;
ptr::write(xs.as_mut_slice().unsafe_mut(len), op(len)); ptr::write(xs.unsafe_mut(len), op(len));
xs.len += 1; xs.len += 1;
} }
xs xs
@ -328,7 +328,7 @@ impl<T: Clone> Vec<T> {
let mut xs = Vec::with_capacity(length); let mut xs = Vec::with_capacity(length);
while xs.len < length { while xs.len < length {
let len = xs.len; let len = xs.len;
ptr::write(xs.as_mut_slice().unsafe_mut(len), ptr::write(xs.unsafe_mut(len),
value.clone()); value.clone());
xs.len += 1; xs.len += 1;
} }
@ -361,7 +361,7 @@ impl<T: Clone> Vec<T> {
// during the loop can prevent this optimisation. // during the loop can prevent this optimisation.
unsafe { unsafe {
ptr::write( ptr::write(
self.as_mut_slice().unsafe_mut(len), self.unsafe_mut(len),
other.unsafe_get(i).clone()); other.unsafe_get(i).clone());
self.set_len(len + 1); self.set_len(len + 1);
} }
@ -798,7 +798,7 @@ impl<T> Vec<T> {
// decrement len before the read(), so a panic on Drop doesn't // decrement len before the read(), so a panic on Drop doesn't
// re-drop the just-failed value. // re-drop the just-failed value.
self.len -= 1; self.len -= 1;
ptr::read(self.as_slice().unsafe_get(self.len)); ptr::read(self.unsafe_get(self.len));
} }
} }
} }
@ -896,7 +896,7 @@ impl<T> Vec<T> {
pub fn swap_remove(&mut self, index: uint) -> Option<T> { pub fn swap_remove(&mut self, index: uint) -> Option<T> {
let length = self.len(); let length = self.len();
if length > 0 && index < length - 1 { if length > 0 && index < length - 1 {
self.as_mut_slice().swap(index, length - 1); self.swap(index, length - 1);
} else if index >= length { } else if index >= length {
return None return None
} }
@ -1091,7 +1091,7 @@ impl<T> Vec<T> {
} else { } else {
unsafe { unsafe {
self.len -= 1; self.len -= 1;
Some(ptr::read(self.as_slice().unsafe_get(self.len()))) Some(ptr::read(self.unsafe_get(self.len())))
} }
} }
} }
@ -1231,7 +1231,7 @@ impl<T: PartialEq> Vec<T> {
if ln < 1 { return; } if ln < 1 { return; }
// Avoid bounds checks by using unsafe pointers. // Avoid bounds checks by using unsafe pointers.
let p = self.as_mut_slice().as_mut_ptr(); let p = self.as_mut_ptr();
let mut r = 1; let mut r = 1;
let mut w = 1; let mut w = 1;
@ -1293,7 +1293,7 @@ impl<T> Drop for Vec<T> {
// zeroed (when moving out, because of #[unsafe_no_drop_flag]). // zeroed (when moving out, because of #[unsafe_no_drop_flag]).
if self.cap != 0 { if self.cap != 0 {
unsafe { unsafe {
for x in self.as_mut_slice().iter() { for x in self.iter() {
ptr::read(x); ptr::read(x);
} }
dealloc(self.ptr, self.cap) dealloc(self.ptr, self.cap)
@ -1779,7 +1779,7 @@ mod tests {
#[test] #[test]
fn test_as_vec() { fn test_as_vec() {
let xs = [1u8, 2u8, 3u8]; let xs = [1u8, 2u8, 3u8];
assert_eq!(as_vec(&xs).as_slice(), xs.as_slice()); assert_eq!(as_vec(&xs).as_slice(), xs);
} }
#[test] #[test]
@ -1875,7 +1875,7 @@ mod tests {
} }
} }
assert!(values.as_slice() == [1, 2, 5, 6, 7]); assert!(values == [1, 2, 5, 6, 7]);
} }
#[test] #[test]
@ -1889,7 +1889,7 @@ mod tests {
} }
} }
assert!(values.as_slice() == [2, 3, 3, 4, 5]); assert!(values == [2, 3, 3, 4, 5]);
} }
#[test] #[test]
@ -2019,7 +2019,6 @@ mod tests {
let (left, right) = unzip(z1.iter().map(|&x| x)); let (left, right) = unzip(z1.iter().map(|&x| x));
let (left, right) = (left.as_slice(), right.as_slice());
assert_eq!((1, 4), (left[0], right[0])); assert_eq!((1, 4), (left[0], right[0]));
assert_eq!((2, 5), (left[1], right[1])); assert_eq!((2, 5), (left[1], right[1]));
assert_eq!((3, 6), (left[2], right[2])); assert_eq!((3, 6), (left[2], right[2]));
@ -2153,7 +2152,7 @@ mod tests {
#[test] #[test]
fn test_map_in_place() { fn test_map_in_place() {
let v = vec![0u, 1, 2]; let v = vec![0u, 1, 2];
assert_eq!(v.map_in_place(|i: uint| i as int - 1).as_slice(), [-1i, 0, 1].as_slice()); assert_eq!(v.map_in_place(|i: uint| i as int - 1), [-1i, 0, 1]);
} }
#[test] #[test]
@ -2161,7 +2160,7 @@ mod tests {
let v = vec![(), ()]; let v = vec![(), ()];
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct ZeroSized; struct ZeroSized;
assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice()); assert_eq!(v.map_in_place(|_| ZeroSized), [ZeroSized, ZeroSized]);
} }
#[test] #[test]
@ -2198,7 +2197,7 @@ mod tests {
fn test_into_boxed_slice() { fn test_into_boxed_slice() {
let xs = vec![1u, 2, 3]; let xs = vec![1u, 2, 3];
let ys = xs.into_boxed_slice(); let ys = xs.into_boxed_slice();
assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice()); assert_eq!(ys.as_slice(), [1u, 2, 3]);
} }
#[bench] #[bench]

View file

@ -870,9 +870,8 @@ mod test_map {
map.insert(3, 4i); map.insert(3, 4i);
let map_str = map.to_string(); let map_str = map.to_string();
let map_str = map_str.as_slice();
assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
assert_eq!(format!("{}", empty), "{}".to_string()); assert_eq!(format!("{}", empty), "{}");
} }
#[test] #[test]

View file

@ -29,10 +29,10 @@ fn smoketest_cell() {
#[test] #[test]
fn cell_has_sensible_show() { fn cell_has_sensible_show() {
let x = Cell::new("foo bar"); let x = Cell::new("foo bar");
assert!(format!("{}", x).as_slice().contains(x.get())); assert!(format!("{}", x).contains(x.get()));
x.set("baz qux"); x.set("baz qux");
assert!(format!("{}", x).as_slice().contains(x.get())); assert!(format!("{}", x).contains(x.get()));
} }
#[test] #[test]
@ -40,11 +40,11 @@ fn ref_and_refmut_have_sensible_show() {
let refcell = RefCell::new("foo"); let refcell = RefCell::new("foo");
let refcell_refmut = refcell.borrow_mut(); let refcell_refmut = refcell.borrow_mut();
assert!(format!("{}", refcell_refmut).as_slice().contains("foo")); assert!(format!("{}", refcell_refmut).contains("foo"));
drop(refcell_refmut); drop(refcell_refmut);
let refcell_ref = refcell.borrow(); let refcell_ref = refcell.borrow();
assert!(format!("{}", refcell_ref).as_slice().contains("foo")); assert!(format!("{}", refcell_ref).contains("foo"));
drop(refcell_ref); drop(refcell_ref);
} }

View file

@ -121,31 +121,31 @@ fn test_escape_default() {
return result; return result;
} }
let s = string('\n'); let s = string('\n');
assert_eq!(s.as_slice(), "\\n"); assert_eq!(s, "\\n");
let s = string('\r'); let s = string('\r');
assert_eq!(s.as_slice(), "\\r"); assert_eq!(s, "\\r");
let s = string('\''); let s = string('\'');
assert_eq!(s.as_slice(), "\\'"); assert_eq!(s, "\\'");
let s = string('"'); let s = string('"');
assert_eq!(s.as_slice(), "\\\""); assert_eq!(s, "\\\"");
let s = string(' '); let s = string(' ');
assert_eq!(s.as_slice(), " "); assert_eq!(s, " ");
let s = string('a'); let s = string('a');
assert_eq!(s.as_slice(), "a"); assert_eq!(s, "a");
let s = string('~'); let s = string('~');
assert_eq!(s.as_slice(), "~"); assert_eq!(s, "~");
let s = string('\x00'); let s = string('\x00');
assert_eq!(s.as_slice(), "\\x00"); assert_eq!(s, "\\x00");
let s = string('\x1f'); let s = string('\x1f');
assert_eq!(s.as_slice(), "\\x1f"); assert_eq!(s, "\\x1f");
let s = string('\x7f'); let s = string('\x7f');
assert_eq!(s.as_slice(), "\\x7f"); assert_eq!(s, "\\x7f");
let s = string('\u00ff'); let s = string('\u00ff');
assert_eq!(s.as_slice(), "\\u00ff"); assert_eq!(s, "\\u00ff");
let s = string('\u011b'); let s = string('\u011b');
assert_eq!(s.as_slice(), "\\u011b"); assert_eq!(s, "\\u011b");
let s = string('\U0001d4b6'); let s = string('\U0001d4b6');
assert_eq!(s.as_slice(), "\\U0001d4b6"); assert_eq!(s, "\\U0001d4b6");
} }
#[test] #[test]
@ -156,17 +156,17 @@ fn test_escape_unicode() {
return result; return result;
} }
let s = string('\x00'); let s = string('\x00');
assert_eq!(s.as_slice(), "\\x00"); assert_eq!(s, "\\x00");
let s = string('\n'); let s = string('\n');
assert_eq!(s.as_slice(), "\\x0a"); assert_eq!(s, "\\x0a");
let s = string(' '); let s = string(' ');
assert_eq!(s.as_slice(), "\\x20"); assert_eq!(s, "\\x20");
let s = string('a'); let s = string('a');
assert_eq!(s.as_slice(), "\\x61"); assert_eq!(s, "\\x61");
let s = string('\u011b'); let s = string('\u011b');
assert_eq!(s.as_slice(), "\\u011b"); assert_eq!(s, "\\u011b");
let s = string('\U0001d4b6'); let s = string('\U0001d4b6');
assert_eq!(s.as_slice(), "\\U0001d4b6"); assert_eq!(s, "\\U0001d4b6");
} }
#[test] #[test]

View file

@ -16,136 +16,136 @@ fn test_format_int() {
// Formatting integers should select the right implementation based off // Formatting integers should select the right implementation based off
// the type of the argument. Also, hex/octal/binary should be defined // the type of the argument. Also, hex/octal/binary should be defined
// for integers, but they shouldn't emit the negative sign. // for integers, but they shouldn't emit the negative sign.
assert!(format!("{}", 1i).as_slice() == "1"); assert!(format!("{}", 1i) == "1");
assert!(format!("{}", 1i8).as_slice() == "1"); assert!(format!("{}", 1i8) == "1");
assert!(format!("{}", 1i16).as_slice() == "1"); assert!(format!("{}", 1i16) == "1");
assert!(format!("{}", 1i32).as_slice() == "1"); assert!(format!("{}", 1i32) == "1");
assert!(format!("{}", 1i64).as_slice() == "1"); assert!(format!("{}", 1i64) == "1");
assert!(format!("{}", -1i).as_slice() == "-1"); assert!(format!("{}", -1i) == "-1");
assert!(format!("{}", -1i8).as_slice() == "-1"); assert!(format!("{}", -1i8) == "-1");
assert!(format!("{}", -1i16).as_slice() == "-1"); assert!(format!("{}", -1i16) == "-1");
assert!(format!("{}", -1i32).as_slice() == "-1"); assert!(format!("{}", -1i32) == "-1");
assert!(format!("{}", -1i64).as_slice() == "-1"); assert!(format!("{}", -1i64) == "-1");
assert!(format!("{:b}", 1i).as_slice() == "1"); assert!(format!("{:b}", 1i) == "1");
assert!(format!("{:b}", 1i8).as_slice() == "1"); assert!(format!("{:b}", 1i8) == "1");
assert!(format!("{:b}", 1i16).as_slice() == "1"); assert!(format!("{:b}", 1i16) == "1");
assert!(format!("{:b}", 1i32).as_slice() == "1"); assert!(format!("{:b}", 1i32) == "1");
assert!(format!("{:b}", 1i64).as_slice() == "1"); assert!(format!("{:b}", 1i64) == "1");
assert!(format!("{:x}", 1i).as_slice() == "1"); assert!(format!("{:x}", 1i) == "1");
assert!(format!("{:x}", 1i8).as_slice() == "1"); assert!(format!("{:x}", 1i8) == "1");
assert!(format!("{:x}", 1i16).as_slice() == "1"); assert!(format!("{:x}", 1i16) == "1");
assert!(format!("{:x}", 1i32).as_slice() == "1"); assert!(format!("{:x}", 1i32) == "1");
assert!(format!("{:x}", 1i64).as_slice() == "1"); assert!(format!("{:x}", 1i64) == "1");
assert!(format!("{:X}", 1i).as_slice() == "1"); assert!(format!("{:X}", 1i) == "1");
assert!(format!("{:X}", 1i8).as_slice() == "1"); assert!(format!("{:X}", 1i8) == "1");
assert!(format!("{:X}", 1i16).as_slice() == "1"); assert!(format!("{:X}", 1i16) == "1");
assert!(format!("{:X}", 1i32).as_slice() == "1"); assert!(format!("{:X}", 1i32) == "1");
assert!(format!("{:X}", 1i64).as_slice() == "1"); assert!(format!("{:X}", 1i64) == "1");
assert!(format!("{:o}", 1i).as_slice() == "1"); assert!(format!("{:o}", 1i) == "1");
assert!(format!("{:o}", 1i8).as_slice() == "1"); assert!(format!("{:o}", 1i8) == "1");
assert!(format!("{:o}", 1i16).as_slice() == "1"); assert!(format!("{:o}", 1i16) == "1");
assert!(format!("{:o}", 1i32).as_slice() == "1"); assert!(format!("{:o}", 1i32) == "1");
assert!(format!("{:o}", 1i64).as_slice() == "1"); assert!(format!("{:o}", 1i64) == "1");
assert!(format!("{}", 1u).as_slice() == "1"); assert!(format!("{}", 1u) == "1");
assert!(format!("{}", 1u8).as_slice() == "1"); assert!(format!("{}", 1u8) == "1");
assert!(format!("{}", 1u16).as_slice() == "1"); assert!(format!("{}", 1u16) == "1");
assert!(format!("{}", 1u32).as_slice() == "1"); assert!(format!("{}", 1u32) == "1");
assert!(format!("{}", 1u64).as_slice() == "1"); assert!(format!("{}", 1u64) == "1");
assert!(format!("{:b}", 1u).as_slice() == "1"); assert!(format!("{:b}", 1u) == "1");
assert!(format!("{:b}", 1u8).as_slice() == "1"); assert!(format!("{:b}", 1u8) == "1");
assert!(format!("{:b}", 1u16).as_slice() == "1"); assert!(format!("{:b}", 1u16) == "1");
assert!(format!("{:b}", 1u32).as_slice() == "1"); assert!(format!("{:b}", 1u32) == "1");
assert!(format!("{:b}", 1u64).as_slice() == "1"); assert!(format!("{:b}", 1u64) == "1");
assert!(format!("{:x}", 1u).as_slice() == "1"); assert!(format!("{:x}", 1u) == "1");
assert!(format!("{:x}", 1u8).as_slice() == "1"); assert!(format!("{:x}", 1u8) == "1");
assert!(format!("{:x}", 1u16).as_slice() == "1"); assert!(format!("{:x}", 1u16) == "1");
assert!(format!("{:x}", 1u32).as_slice() == "1"); assert!(format!("{:x}", 1u32) == "1");
assert!(format!("{:x}", 1u64).as_slice() == "1"); assert!(format!("{:x}", 1u64) == "1");
assert!(format!("{:X}", 1u).as_slice() == "1"); assert!(format!("{:X}", 1u) == "1");
assert!(format!("{:X}", 1u8).as_slice() == "1"); assert!(format!("{:X}", 1u8) == "1");
assert!(format!("{:X}", 1u16).as_slice() == "1"); assert!(format!("{:X}", 1u16) == "1");
assert!(format!("{:X}", 1u32).as_slice() == "1"); assert!(format!("{:X}", 1u32) == "1");
assert!(format!("{:X}", 1u64).as_slice() == "1"); assert!(format!("{:X}", 1u64) == "1");
assert!(format!("{:o}", 1u).as_slice() == "1"); assert!(format!("{:o}", 1u) == "1");
assert!(format!("{:o}", 1u8).as_slice() == "1"); assert!(format!("{:o}", 1u8) == "1");
assert!(format!("{:o}", 1u16).as_slice() == "1"); assert!(format!("{:o}", 1u16) == "1");
assert!(format!("{:o}", 1u32).as_slice() == "1"); assert!(format!("{:o}", 1u32) == "1");
assert!(format!("{:o}", 1u64).as_slice() == "1"); assert!(format!("{:o}", 1u64) == "1");
// Test a larger number // Test a larger number
assert!(format!("{:b}", 55i).as_slice() == "110111"); assert!(format!("{:b}", 55i) == "110111");
assert!(format!("{:o}", 55i).as_slice() == "67"); assert!(format!("{:o}", 55i) == "67");
assert!(format!("{}", 55i).as_slice() == "55"); assert!(format!("{}", 55i) == "55");
assert!(format!("{:x}", 55i).as_slice() == "37"); assert!(format!("{:x}", 55i) == "37");
assert!(format!("{:X}", 55i).as_slice() == "37"); assert!(format!("{:X}", 55i) == "37");
} }
#[test] #[test]
fn test_format_int_zero() { fn test_format_int_zero() {
assert!(format!("{}", 0i).as_slice() == "0"); assert!(format!("{}", 0i) == "0");
assert!(format!("{:b}", 0i).as_slice() == "0"); assert!(format!("{:b}", 0i) == "0");
assert!(format!("{:o}", 0i).as_slice() == "0"); assert!(format!("{:o}", 0i) == "0");
assert!(format!("{:x}", 0i).as_slice() == "0"); assert!(format!("{:x}", 0i) == "0");
assert!(format!("{:X}", 0i).as_slice() == "0"); assert!(format!("{:X}", 0i) == "0");
assert!(format!("{}", 0u).as_slice() == "0"); assert!(format!("{}", 0u) == "0");
assert!(format!("{:b}", 0u).as_slice() == "0"); assert!(format!("{:b}", 0u) == "0");
assert!(format!("{:o}", 0u).as_slice() == "0"); assert!(format!("{:o}", 0u) == "0");
assert!(format!("{:x}", 0u).as_slice() == "0"); assert!(format!("{:x}", 0u) == "0");
assert!(format!("{:X}", 0u).as_slice() == "0"); assert!(format!("{:X}", 0u) == "0");
} }
#[test] #[test]
fn test_format_int_flags() { fn test_format_int_flags() {
assert!(format!("{:3}", 1i).as_slice() == " 1"); assert!(format!("{:3}", 1i) == " 1");
assert!(format!("{:>3}", 1i).as_slice() == " 1"); assert!(format!("{:>3}", 1i) == " 1");
assert!(format!("{:>+3}", 1i).as_slice() == " +1"); assert!(format!("{:>+3}", 1i) == " +1");
assert!(format!("{:<3}", 1i).as_slice() == "1 "); assert!(format!("{:<3}", 1i) == "1 ");
assert!(format!("{:#}", 1i).as_slice() == "1"); assert!(format!("{:#}", 1i) == "1");
assert!(format!("{:#x}", 10i).as_slice() == "0xa"); assert!(format!("{:#x}", 10i) == "0xa");
assert!(format!("{:#X}", 10i).as_slice() == "0xA"); assert!(format!("{:#X}", 10i) == "0xA");
assert!(format!("{:#5x}", 10i).as_slice() == " 0xa"); assert!(format!("{:#5x}", 10i) == " 0xa");
assert!(format!("{:#o}", 10i).as_slice() == "0o12"); assert!(format!("{:#o}", 10i) == "0o12");
assert!(format!("{:08x}", 10i).as_slice() == "0000000a"); assert!(format!("{:08x}", 10i) == "0000000a");
assert!(format!("{:8x}", 10i).as_slice() == " a"); assert!(format!("{:8x}", 10i) == " a");
assert!(format!("{:<8x}", 10i).as_slice() == "a "); assert!(format!("{:<8x}", 10i) == "a ");
assert!(format!("{:>8x}", 10i).as_slice() == " a"); assert!(format!("{:>8x}", 10i) == " a");
assert!(format!("{:#08x}", 10i).as_slice() == "0x00000a"); assert!(format!("{:#08x}", 10i) == "0x00000a");
assert!(format!("{:08}", -10i).as_slice() == "-0000010"); assert!(format!("{:08}", -10i) == "-0000010");
assert!(format!("{:x}", -1u8).as_slice() == "ff"); assert!(format!("{:x}", -1u8) == "ff");
assert!(format!("{:X}", -1u8).as_slice() == "FF"); assert!(format!("{:X}", -1u8) == "FF");
assert!(format!("{:b}", -1u8).as_slice() == "11111111"); assert!(format!("{:b}", -1u8) == "11111111");
assert!(format!("{:o}", -1u8).as_slice() == "377"); assert!(format!("{:o}", -1u8) == "377");
assert!(format!("{:#x}", -1u8).as_slice() == "0xff"); assert!(format!("{:#x}", -1u8) == "0xff");
assert!(format!("{:#X}", -1u8).as_slice() == "0xFF"); assert!(format!("{:#X}", -1u8) == "0xFF");
assert!(format!("{:#b}", -1u8).as_slice() == "0b11111111"); assert!(format!("{:#b}", -1u8) == "0b11111111");
assert!(format!("{:#o}", -1u8).as_slice() == "0o377"); assert!(format!("{:#o}", -1u8) == "0o377");
} }
#[test] #[test]
fn test_format_int_sign_padding() { fn test_format_int_sign_padding() {
assert!(format!("{:+5}", 1i).as_slice() == " +1"); assert!(format!("{:+5}", 1i) == " +1");
assert!(format!("{:+5}", -1i).as_slice() == " -1"); assert!(format!("{:+5}", -1i) == " -1");
assert!(format!("{:05}", 1i).as_slice() == "00001"); assert!(format!("{:05}", 1i) == "00001");
assert!(format!("{:05}", -1i).as_slice() == "-0001"); assert!(format!("{:05}", -1i) == "-0001");
assert!(format!("{:+05}", 1i).as_slice() == "+0001"); assert!(format!("{:+05}", 1i) == "+0001");
assert!(format!("{:+05}", -1i).as_slice() == "-0001"); assert!(format!("{:+05}", -1i) == "-0001");
} }
#[test] #[test]
fn test_format_int_twos_complement() { fn test_format_int_twos_complement() {
use core::{i8, i16, i32, i64}; use core::{i8, i16, i32, i64};
assert!(format!("{}", i8::MIN).as_slice() == "-128"); assert!(format!("{}", i8::MIN) == "-128");
assert!(format!("{}", i16::MIN).as_slice() == "-32768"); assert!(format!("{}", i16::MIN) == "-32768");
assert!(format!("{}", i32::MIN).as_slice() == "-2147483648"); assert!(format!("{}", i32::MIN) == "-2147483648");
assert!(format!("{}", i64::MIN).as_slice() == "-9223372036854775808"); assert!(format!("{}", i64::MIN) == "-9223372036854775808");
} }
#[test] #[test]
fn test_format_radix() { fn test_format_radix() {
assert!(format!("{:04}", radix(3i, 2)).as_slice() == "0011"); assert!(format!("{:04}", radix(3i, 2)) == "0011");
assert!(format!("{}", radix(55i, 36)).as_slice() == "1j"); assert!(format!("{}", radix(55i, 36)) == "1j");
} }
#[test] #[test]

View file

@ -28,10 +28,10 @@ fn test_get_ptr() {
#[test] #[test]
fn test_get_str() { fn test_get_str() {
let x = "test".to_string(); let x = "test".to_string();
let addr_x = x.as_slice().as_ptr(); let addr_x = x.as_ptr();
let opt = Some(x); let opt = Some(x);
let y = opt.unwrap(); let y = opt.unwrap();
let addr_y = y.as_slice().as_ptr(); let addr_y = y.as_ptr();
assert_eq!(addr_x, addr_y); assert_eq!(addr_x, addr_y);
} }
@ -135,7 +135,7 @@ fn test_or_else() {
fn test_unwrap() { fn test_unwrap() {
assert_eq!(Some(1i).unwrap(), 1); assert_eq!(Some(1i).unwrap(), 1);
let s = Some("hello".to_string()).unwrap(); let s = Some("hello".to_string()).unwrap();
assert_eq!(s.as_slice(), "hello"); assert_eq!(s, "hello");
} }
#[test] #[test]

View file

@ -93,9 +93,9 @@ pub fn test_fmt_default() {
let err: Result<int, &'static str> = Err("Err"); let err: Result<int, &'static str> = Err("Err");
let s = format!("{}", ok); let s = format!("{}", ok);
assert_eq!(s.as_slice(), "Ok(100)"); assert_eq!(s, "Ok(100)");
let s = format!("{}", err); let s = format!("{}", err);
assert_eq!(s.as_slice(), "Err(Err)"); assert_eq!(s, "Err(Err)");
} }
#[test] #[test]

View file

@ -84,9 +84,9 @@ fn test_tuple_cmp() {
#[test] #[test]
fn test_show() { fn test_show() {
let s = format!("{}", (1i,)); let s = format!("{}", (1i,));
assert_eq!(s.as_slice(), "(1,)"); assert_eq!(s, "(1,)");
let s = format!("{}", (1i, true)); let s = format!("{}", (1i, true));
assert_eq!(s.as_slice(), "(1, true)"); assert_eq!(s, "(1, true)");
let s = format!("{}", (1i, "hi", true)); let s = format!("{}", (1i, "hi", true));
assert_eq!(s.as_slice(), "(1, hi, true)"); assert_eq!(s, "(1, hi, true)");
} }

View file

@ -128,7 +128,7 @@ mod tests {
debug!("{} bytes deflated to {} ({:.1}% size)", debug!("{} bytes deflated to {} ({:.1}% size)",
input.len(), cmp.len(), input.len(), cmp.len(),
100.0 * ((cmp.len() as f64) / (input.len() as f64))); 100.0 * ((cmp.len() as f64) / (input.len() as f64)));
assert_eq!(input.as_slice(), out.as_slice()); assert_eq!(input, out.as_slice());
} }
} }
@ -137,6 +137,6 @@ mod tests {
let bytes = vec!(1, 2, 3, 4, 5); let bytes = vec!(1, 2, 3, 4, 5);
let deflated = deflate_bytes(bytes.as_slice()).expect("deflation failed"); let deflated = deflate_bytes(bytes.as_slice()).expect("deflation failed");
let inflated = inflate_bytes(deflated.as_slice()).expect("inflation failed"); let inflated = inflate_bytes(deflated.as_slice()).expect("inflation failed");
assert_eq!(inflated.as_slice(), bytes.as_slice()); assert_eq!(inflated.as_slice(), bytes);
} }
} }

View file

@ -440,7 +440,7 @@ mod tests {
fn same(fmt: &'static str, p: &[Piece<'static>]) { fn same(fmt: &'static str, p: &[Piece<'static>]) {
let mut parser = Parser::new(fmt); let mut parser = Parser::new(fmt);
assert!(p == parser.collect::<Vec<Piece<'static>>>().as_slice()); assert!(p == parser.collect::<Vec<Piece<'static>>>());
} }
fn fmtdflt() -> FormatSpec<'static> { fn fmtdflt() -> FormatSpec<'static> {

View file

@ -244,7 +244,7 @@ impl OptGroup {
aliases: Vec::new() aliases: Vec::new()
}, },
(1,0) => Opt { (1,0) => Opt {
name: Short(short_name.as_slice().char_at(0)), name: Short(short_name.char_at(0)),
hasarg: hasarg, hasarg: hasarg,
occur: occur, occur: occur,
aliases: Vec::new() aliases: Vec::new()
@ -255,7 +255,7 @@ impl OptGroup {
occur: occur, occur: occur,
aliases: vec!( aliases: vec!(
Opt { Opt {
name: Short(short_name.as_slice().char_at(0)), name: Short(short_name.char_at(0)),
hasarg: hasarg, hasarg: hasarg,
occur: occur, occur: occur,
aliases: Vec::new() aliases: Vec::new()
@ -576,7 +576,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
let curlen = cur.len(); let curlen = cur.len();
if !is_arg(cur.as_slice()) { if !is_arg(cur.as_slice()) {
free.push(cur); free.push(cur);
} else if cur.as_slice() == "--" { } else if cur == "--" {
let mut j = i + 1; let mut j = i + 1;
while j < l { free.push(args[j].clone()); j += 1; } while j < l { free.push(args[j].clone()); j += 1; }
break; break;
@ -584,7 +584,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
let mut names; let mut names;
let mut i_arg = None; let mut i_arg = None;
if cur.as_bytes()[1] == b'-' { if cur.as_bytes()[1] == b'-' {
let tail = cur.as_slice().slice(2, curlen); let tail = cur.slice(2, curlen);
let tail_eq: Vec<&str> = tail.split('=').collect(); let tail_eq: Vec<&str> = tail.split('=').collect();
if tail_eq.len() <= 1 { if tail_eq.len() <= 1 {
names = vec!(Long(tail.to_string())); names = vec!(Long(tail.to_string()));
@ -597,7 +597,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
let mut j = 1; let mut j = 1;
names = Vec::new(); names = Vec::new();
while j < curlen { while j < curlen {
let range = cur.as_slice().char_range_at(j); let range = cur.char_range_at(j);
let opt = Short(range.ch); let opt = Short(range.ch);
/* In a series of potential options (eg. -aheJ), if we /* In a series of potential options (eg. -aheJ), if we
@ -620,8 +620,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
}; };
if arg_follows && range.next < curlen { if arg_follows && range.next < curlen {
i_arg = Some(cur.as_slice() i_arg = Some(cur.slice(range.next, curlen).to_string());
.slice(range.next, curlen).to_string());
break; break;
} }
@ -736,7 +735,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
// FIXME: #5516 should be graphemes not codepoints // FIXME: #5516 should be graphemes not codepoints
// here we just need to indent the start of the description // here we just need to indent the start of the description
let rowlen = row.as_slice().char_len(); let rowlen = row.char_len();
if rowlen < 24 { if rowlen < 24 {
for _ in range(0, 24 - rowlen) { for _ in range(0, 24 - rowlen) {
row.push(' '); row.push(' ');
@ -747,7 +746,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
// Normalize desc to contain words separated by one space character // Normalize desc to contain words separated by one space character
let mut desc_normalized_whitespace = String::new(); let mut desc_normalized_whitespace = String::new();
for word in desc.as_slice().words() { for word in desc.words() {
desc_normalized_whitespace.push_str(word); desc_normalized_whitespace.push_str(word);
desc_normalized_whitespace.push(' '); desc_normalized_whitespace.push(' ');
} }
@ -963,9 +962,9 @@ mod tests {
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!(m.opt_present("test")); assert!(m.opt_present("test"));
assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); assert_eq!(m.opt_str("test").unwrap(), "20");
assert!(m.opt_present("t")); assert!(m.opt_present("t"));
assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); assert_eq!(m.opt_str("t").unwrap(), "20");
} }
_ => { panic!("test_reqopt failed (long arg)"); } _ => { panic!("test_reqopt failed (long arg)"); }
} }
@ -973,9 +972,9 @@ mod tests {
match getopts(short_args.as_slice(), opts.as_slice()) { match getopts(short_args.as_slice(), opts.as_slice()) {
Ok(ref m) => { Ok(ref m) => {
assert!((m.opt_present("test"))); assert!((m.opt_present("test")));
assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); assert_eq!(m.opt_str("test").unwrap(), "20");
assert!((m.opt_present("t"))); assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); assert_eq!(m.opt_str("t").unwrap(), "20");
} }
_ => { panic!("test_reqopt failed (short arg)"); } _ => { panic!("test_reqopt failed (short arg)"); }
} }
@ -1028,9 +1027,9 @@ mod tests {
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!(m.opt_present("test")); assert!(m.opt_present("test"));
assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); assert_eq!(m.opt_str("test").unwrap(), "20");
assert!((m.opt_present("t"))); assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); assert_eq!(m.opt_str("t").unwrap(), "20");
} }
_ => panic!() _ => panic!()
} }
@ -1038,9 +1037,9 @@ mod tests {
match getopts(short_args.as_slice(), opts.as_slice()) { match getopts(short_args.as_slice(), opts.as_slice()) {
Ok(ref m) => { Ok(ref m) => {
assert!((m.opt_present("test"))); assert!((m.opt_present("test")));
assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); assert_eq!(m.opt_str("test").unwrap(), "20");
assert!((m.opt_present("t"))); assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); assert_eq!(m.opt_str("t").unwrap(), "20");
} }
_ => panic!() _ => panic!()
} }
@ -1155,7 +1154,7 @@ mod tests {
Ok(ref m) => { Ok(ref m) => {
// The next variable after the flag is just a free argument // The next variable after the flag is just a free argument
assert!(m.free[0] == "20".to_string()); assert!(m.free[0] == "20");
} }
_ => panic!() _ => panic!()
} }
@ -1251,9 +1250,9 @@ mod tests {
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!((m.opt_present("test"))); assert!((m.opt_present("test")));
assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); assert_eq!(m.opt_str("test").unwrap(), "20");
assert!((m.opt_present("t"))); assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); assert_eq!(m.opt_str("t").unwrap(), "20");
} }
_ => panic!() _ => panic!()
} }
@ -1261,9 +1260,9 @@ mod tests {
match getopts(short_args.as_slice(), opts.as_slice()) { match getopts(short_args.as_slice(), opts.as_slice()) {
Ok(ref m) => { Ok(ref m) => {
assert!((m.opt_present("test"))); assert!((m.opt_present("test")));
assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); assert_eq!(m.opt_str("test").unwrap(), "20");
assert!((m.opt_present("t"))); assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); assert_eq!(m.opt_str("t").unwrap(), "20");
} }
_ => panic!() _ => panic!()
} }
@ -1307,12 +1306,12 @@ mod tests {
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!(m.opt_present("test")); assert!(m.opt_present("test"));
assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); assert_eq!(m.opt_str("test").unwrap(), "20");
assert!(m.opt_present("t")); assert!(m.opt_present("t"));
assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); assert_eq!(m.opt_str("t").unwrap(), "20");
let pair = m.opt_strs("test"); let pair = m.opt_strs("test");
assert!(pair[0] == "20".to_string()); assert!(pair[0] == "20");
assert!(pair[1] == "30".to_string()); assert!(pair[1] == "30");
} }
_ => panic!() _ => panic!()
} }
@ -1364,19 +1363,19 @@ mod tests {
let rs = getopts(args.as_slice(), opts.as_slice()); let rs = getopts(args.as_slice(), opts.as_slice());
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!(m.free[0] == "prog".to_string()); assert!(m.free[0] == "prog");
assert!(m.free[1] == "free1".to_string()); assert!(m.free[1] == "free1");
assert_eq!(m.opt_str("s").unwrap(), "20".to_string()); assert_eq!(m.opt_str("s").unwrap(), "20");
assert!(m.free[2] == "free2".to_string()); assert!(m.free[2] == "free2");
assert!((m.opt_present("flag"))); assert!((m.opt_present("flag")));
assert_eq!(m.opt_str("long").unwrap(), "30".to_string()); assert_eq!(m.opt_str("long").unwrap(), "30");
assert!((m.opt_present("f"))); assert!((m.opt_present("f")));
let pair = m.opt_strs("m"); let pair = m.opt_strs("m");
assert!(pair[0] == "40".to_string()); assert!(pair[0] == "40");
assert!(pair[1] == "50".to_string()); assert!(pair[1] == "50");
let pair = m.opt_strs("n"); let pair = m.opt_strs("n");
assert!(pair[0] == "-A B".to_string()); assert!(pair[0] == "-A B");
assert!(pair[1] == "-60 70".to_string()); assert!(pair[1] == "-60 70");
assert!((!m.opt_present("notpresent"))); assert!((!m.opt_present("notpresent")));
} }
_ => panic!() _ => panic!()
@ -1402,11 +1401,11 @@ mod tests {
assert!(!matches_single.opts_present(&["thing".to_string()])); assert!(!matches_single.opts_present(&["thing".to_string()]));
assert!(!matches_single.opts_present(&[])); assert!(!matches_single.opts_present(&[]));
assert_eq!(matches_single.opts_str(&["e".to_string()]).unwrap(), "foo".to_string()); assert_eq!(matches_single.opts_str(&["e".to_string()]).unwrap(), "foo");
assert_eq!(matches_single.opts_str(&["e".to_string(), "encrypt".to_string()]).unwrap(), assert_eq!(matches_single.opts_str(&["e".to_string(), "encrypt".to_string()]).unwrap(),
"foo".to_string()); "foo");
assert_eq!(matches_single.opts_str(&["encrypt".to_string(), "e".to_string()]).unwrap(), assert_eq!(matches_single.opts_str(&["encrypt".to_string(), "e".to_string()]).unwrap(),
"foo".to_string()); "foo");
let args_both = vec!("-e".to_string(), "foo".to_string(), "--encrypt".to_string(), let args_both = vec!("-e".to_string(), "foo".to_string(), "--encrypt".to_string(),
"foo".to_string()); "foo".to_string());
@ -1423,12 +1422,12 @@ mod tests {
assert!(!matches_both.opts_present(&["thing".to_string()])); assert!(!matches_both.opts_present(&["thing".to_string()]));
assert!(!matches_both.opts_present(&[])); assert!(!matches_both.opts_present(&[]));
assert_eq!(matches_both.opts_str(&["e".to_string()]).unwrap(), "foo".to_string()); assert_eq!(matches_both.opts_str(&["e".to_string()]).unwrap(), "foo");
assert_eq!(matches_both.opts_str(&["encrypt".to_string()]).unwrap(), "foo".to_string()); assert_eq!(matches_both.opts_str(&["encrypt".to_string()]).unwrap(), "foo");
assert_eq!(matches_both.opts_str(&["e".to_string(), "encrypt".to_string()]).unwrap(), assert_eq!(matches_both.opts_str(&["e".to_string(), "encrypt".to_string()]).unwrap(),
"foo".to_string()); "foo");
assert_eq!(matches_both.opts_str(&["encrypt".to_string(), "e".to_string()]).unwrap(), assert_eq!(matches_both.opts_str(&["encrypt".to_string(), "e".to_string()]).unwrap(),
"foo".to_string()); "foo");
} }
#[test] #[test]
@ -1441,9 +1440,9 @@ mod tests {
result::Result::Err(_) => panic!() result::Result::Err(_) => panic!()
}; };
assert!(matches.opts_present(&["L".to_string()])); assert!(matches.opts_present(&["L".to_string()]));
assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "foo".to_string()); assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "foo");
assert!(matches.opts_present(&["M".to_string()])); assert!(matches.opts_present(&["M".to_string()]));
assert_eq!(matches.opts_str(&["M".to_string()]).unwrap(), ".".to_string()); assert_eq!(matches.opts_str(&["M".to_string()]).unwrap(), ".");
} }
@ -1457,7 +1456,7 @@ mod tests {
result::Result::Err(e) => panic!( "{}", e ) result::Result::Err(e) => panic!( "{}", e )
}; };
assert!(matches.opts_present(&["L".to_string()])); assert!(matches.opts_present(&["L".to_string()]));
assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "verbose".to_string()); assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "verbose");
assert!(matches.opts_present(&["v".to_string()])); assert!(matches.opts_present(&["v".to_string()]));
assert_eq!(3, matches.opt_count("v")); assert_eq!(3, matches.opt_count("v"));
} }
@ -1511,7 +1510,7 @@ Options:
-k --kiwi Desc -k --kiwi Desc
-p [VAL] Desc -p [VAL] Desc
-l VAL Desc -l VAL Desc
".to_string(); ";
let generated_usage = usage("Usage: fruits", optgroups.as_slice()); let generated_usage = usage("Usage: fruits", optgroups.as_slice());
@ -1538,7 +1537,7 @@ Options:
-k --kiwi This is a long description which won't be wrapped..+.. -k --kiwi This is a long description which won't be wrapped..+..
-a --apple This is a long description which _will_ be -a --apple This is a long description which _will_ be
wrapped..+.. wrapped..+..
".to_string(); ";
let usage = usage("Usage: fruits", optgroups.as_slice()); let usage = usage("Usage: fruits", optgroups.as_slice());
@ -1564,7 +1563,7 @@ Options:
-a --apple This description has some characters that could -a --apple This description has some characters that could
confuse the line wrapping; an apple costs 0.51 in confuse the line wrapping; an apple costs 0.51 in
some parts of Europe. some parts of Europe.
".to_string(); ";
let usage = usage("Usage: fruits", optgroups.as_slice()); let usage = usage("Usage: fruits", optgroups.as_slice());

View file

@ -439,7 +439,7 @@ impl<'a> LabelText<'a> {
/// Renders text as string suitable for a label in a .dot file. /// Renders text as string suitable for a label in a .dot file.
pub fn escape(&self) -> String { pub fn escape(&self) -> String {
match self { match self {
&LabelStr(ref s) => s.as_slice().escape_default(), &LabelStr(ref s) => s.escape_default(),
&EscStr(ref s) => LabelText::escape_str(s.as_slice()), &EscStr(ref s) => LabelText::escape_str(s.as_slice()),
} }
} }
@ -709,7 +709,7 @@ mod tests {
fn empty_graph() { fn empty_graph() {
let labels : Trivial = UnlabelledNodes(0); let labels : Trivial = UnlabelledNodes(0);
let r = test_input(LabelledGraph::new("empty_graph", labels, vec!())); let r = test_input(LabelledGraph::new("empty_graph", labels, vec!()));
assert_eq!(r.unwrap().as_slice(), assert_eq!(r.unwrap(),
r#"digraph empty_graph { r#"digraph empty_graph {
} }
"#); "#);
@ -719,7 +719,7 @@ r#"digraph empty_graph {
fn single_node() { fn single_node() {
let labels : Trivial = UnlabelledNodes(1); let labels : Trivial = UnlabelledNodes(1);
let r = test_input(LabelledGraph::new("single_node", labels, vec!())); let r = test_input(LabelledGraph::new("single_node", labels, vec!()));
assert_eq!(r.unwrap().as_slice(), assert_eq!(r.unwrap(),
r#"digraph single_node { r#"digraph single_node {
N0[label="N0"]; N0[label="N0"];
} }
@ -731,7 +731,7 @@ r#"digraph single_node {
let labels : Trivial = UnlabelledNodes(2); let labels : Trivial = UnlabelledNodes(2);
let result = test_input(LabelledGraph::new("single_edge", labels, let result = test_input(LabelledGraph::new("single_edge", labels,
vec!(edge(0, 1, "E")))); vec!(edge(0, 1, "E"))));
assert_eq!(result.unwrap().as_slice(), assert_eq!(result.unwrap(),
r#"digraph single_edge { r#"digraph single_edge {
N0[label="N0"]; N0[label="N0"];
N1[label="N1"]; N1[label="N1"];
@ -745,7 +745,7 @@ r#"digraph single_edge {
let labels : Trivial = SomeNodesLabelled(vec![Some("A"), None]); let labels : Trivial = SomeNodesLabelled(vec![Some("A"), None]);
let result = test_input(LabelledGraph::new("test_some_labelled", labels, let result = test_input(LabelledGraph::new("test_some_labelled", labels,
vec![edge(0, 1, "A-1")])); vec![edge(0, 1, "A-1")]));
assert_eq!(result.unwrap().as_slice(), assert_eq!(result.unwrap(),
r#"digraph test_some_labelled { r#"digraph test_some_labelled {
N0[label="A"]; N0[label="A"];
N1[label="N1"]; N1[label="N1"];
@ -759,7 +759,7 @@ r#"digraph test_some_labelled {
let labels : Trivial = UnlabelledNodes(1); let labels : Trivial = UnlabelledNodes(1);
let r = test_input(LabelledGraph::new("single_cyclic_node", labels, let r = test_input(LabelledGraph::new("single_cyclic_node", labels,
vec!(edge(0, 0, "E")))); vec!(edge(0, 0, "E"))));
assert_eq!(r.unwrap().as_slice(), assert_eq!(r.unwrap(),
r#"digraph single_cyclic_node { r#"digraph single_cyclic_node {
N0[label="N0"]; N0[label="N0"];
N0 -> N0[label="E"]; N0 -> N0[label="E"];
@ -774,7 +774,7 @@ r#"digraph single_cyclic_node {
"hasse_diagram", labels, "hasse_diagram", labels,
vec!(edge(0, 1, ""), edge(0, 2, ""), vec!(edge(0, 1, ""), edge(0, 2, ""),
edge(1, 3, ""), edge(2, 3, "")))); edge(1, 3, ""), edge(2, 3, ""))));
assert_eq!(r.unwrap().as_slice(), assert_eq!(r.unwrap(),
r#"digraph hasse_diagram { r#"digraph hasse_diagram {
N0[label="{x,y}"]; N0[label="{x,y}"];
N1[label="{x}"]; N1[label="{x}"];
@ -812,7 +812,7 @@ r#"digraph hasse_diagram {
render(&g, &mut writer).unwrap(); render(&g, &mut writer).unwrap();
let r = (&mut writer.as_slice()).read_to_string(); let r = (&mut writer.as_slice()).read_to_string();
assert_eq!(r.unwrap().as_slice(), assert_eq!(r.unwrap(),
r#"digraph syntax_tree { r#"digraph syntax_tree {
N0[label="if test {\l branch1\l} else {\l branch2\l}\lafterward\l"]; N0[label="if test {\l branch1\l} else {\l branch2\l}\lafterward\l"];
N1[label="branch1"]; N1[label="branch1"];

View file

@ -100,7 +100,6 @@ mod tests {
#[test] #[test]
fn parse_logging_spec_valid() { fn parse_logging_spec_valid() {
let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4"); let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 3); assert_eq!(dirs.len(), 3);
assert_eq!(dirs[0].name, Some("crate1::mod1".to_string())); assert_eq!(dirs[0].name, Some("crate1::mod1".to_string()));
assert_eq!(dirs[0].level, 1); assert_eq!(dirs[0].level, 1);
@ -117,7 +116,6 @@ mod tests {
fn parse_logging_spec_invalid_crate() { fn parse_logging_spec_invalid_crate() {
// test parse_logging_spec with multiple = in specification // test parse_logging_spec with multiple = in specification
let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4"); let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1); assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].level, 4); assert_eq!(dirs[0].level, 4);
@ -128,7 +126,6 @@ mod tests {
fn parse_logging_spec_invalid_log_level() { fn parse_logging_spec_invalid_log_level() {
// test parse_logging_spec with 'noNumber' as log level // test parse_logging_spec with 'noNumber' as log level
let (dirs, filter) = parse_logging_spec("crate1::mod1=noNumber,crate2=4"); let (dirs, filter) = parse_logging_spec("crate1::mod1=noNumber,crate2=4");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1); assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].level, 4); assert_eq!(dirs[0].level, 4);
@ -139,7 +136,6 @@ mod tests {
fn parse_logging_spec_string_log_level() { fn parse_logging_spec_string_log_level() {
// test parse_logging_spec with 'warn' as log level // test parse_logging_spec with 'warn' as log level
let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2=warn"); let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2=warn");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1); assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].level, ::WARN); assert_eq!(dirs[0].level, ::WARN);
@ -150,7 +146,6 @@ mod tests {
fn parse_logging_spec_empty_log_level() { fn parse_logging_spec_empty_log_level() {
// test parse_logging_spec with '' as log level // test parse_logging_spec with '' as log level
let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2="); let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2=");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1); assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL); assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL);
@ -161,7 +156,6 @@ mod tests {
fn parse_logging_spec_global() { fn parse_logging_spec_global() {
// test parse_logging_spec with no crate // test parse_logging_spec with no crate
let (dirs, filter) = parse_logging_spec("warn,crate2=4"); let (dirs, filter) = parse_logging_spec("warn,crate2=4");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 2); assert_eq!(dirs.len(), 2);
assert_eq!(dirs[0].name, None); assert_eq!(dirs[0].name, None);
assert_eq!(dirs[0].level, 2); assert_eq!(dirs[0].level, 2);
@ -173,7 +167,6 @@ mod tests {
#[test] #[test]
fn parse_logging_spec_valid_filter() { fn parse_logging_spec_valid_filter() {
let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4/abc"); let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4/abc");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 3); assert_eq!(dirs.len(), 3);
assert_eq!(dirs[0].name, Some("crate1::mod1".to_string())); assert_eq!(dirs[0].name, Some("crate1::mod1".to_string()));
assert_eq!(dirs[0].level, 1); assert_eq!(dirs[0].level, 1);
@ -183,26 +176,24 @@ mod tests {
assert_eq!(dirs[2].name, Some("crate2".to_string())); assert_eq!(dirs[2].name, Some("crate2".to_string()));
assert_eq!(dirs[2].level, 4); assert_eq!(dirs[2].level, 4);
assert!(filter.is_some() && filter.unwrap().to_string().as_slice() == "abc"); assert!(filter.is_some() && filter.unwrap().to_string() == "abc");
} }
#[test] #[test]
fn parse_logging_spec_invalid_crate_filter() { fn parse_logging_spec_invalid_crate_filter() {
let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4/a.c"); let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4/a.c");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1); assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].level, 4); assert_eq!(dirs[0].level, 4);
assert!(filter.is_some() && filter.unwrap().to_string().as_slice() == "a.c"); assert!(filter.is_some() && filter.unwrap().to_string() == "a.c");
} }
#[test] #[test]
fn parse_logging_spec_empty_with_filter() { fn parse_logging_spec_empty_with_filter() {
let (dirs, filter) = parse_logging_spec("crate1/a*c"); let (dirs, filter) = parse_logging_spec("crate1/a*c");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1); assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate1".to_string())); assert_eq!(dirs[0].name, Some("crate1".to_string()));
assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL); assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL);
assert!(filter.is_some() && filter.unwrap().to_string().as_slice() == "a*c"); assert!(filter.is_some() && filter.unwrap().to_string() == "a*c");
} }
} }

View file

@ -523,11 +523,11 @@ impl<'a> Parser<'a> {
// Parse the min and max values from the regex. // Parse the min and max values from the regex.
let (mut min, mut max): (uint, Option<uint>); let (mut min, mut max): (uint, Option<uint>);
if !inner.as_slice().contains(",") { if !inner.contains(",") {
min = try!(self.parse_uint(inner.as_slice())); min = try!(self.parse_uint(inner.as_slice()));
max = Some(min); max = Some(min);
} else { } else {
let pieces: Vec<&str> = inner.as_slice().splitn(1, ',').collect(); let pieces: Vec<&str> = inner.splitn(1, ',').collect();
let (smin, smax) = (pieces[0], pieces[1]); let (smin, smax) = (pieces[0], pieces[1]);
if smin.len() == 0 { if smin.len() == 0 {
return self.err("Max repetitions cannot be specified \ return self.err("Max repetitions cannot be specified \
@ -751,7 +751,7 @@ impl<'a> Parser<'a> {
return self.err("Capture names must have at least 1 character.") return self.err("Capture names must have at least 1 character.")
} }
let name = self.slice(self.chari, closer); let name = self.slice(self.chari, closer);
if !name.as_slice().chars().all(is_valid_cap) { if !name.chars().all(is_valid_cap) {
return self.err( return self.err(
"Capture names can only have underscores, letters and digits.") "Capture names can only have underscores, letters and digits.")
} }

View file

@ -156,13 +156,13 @@ macro_rules! mat(
}; };
// The test set sometimes leave out capture groups, so truncate // The test set sometimes leave out capture groups, so truncate
// actual capture groups to match test set. // actual capture groups to match test set.
let (sexpect, mut sgot) = (expected.as_slice(), got.as_slice()); let mut sgot = got.as_slice();
if sgot.len() > sexpect.len() { if sgot.len() > expected.len() {
sgot = sgot[0..sexpect.len()] sgot = sgot[0..expected.len()]
} }
if sexpect != sgot { if expected != sgot {
panic!("For RE '{}' against '{}', expected '{}' but got '{}'", panic!("For RE '{}' against '{}', expected '{}' but got '{}'",
$re, text, sexpect, sgot); $re, text, expected, sgot);
} }
} }
); );

View file

@ -147,7 +147,7 @@ impl<'r, 't> Nfa<'r, 't> {
// jump ahead quickly. If it can't be found, then we can bail // jump ahead quickly. If it can't be found, then we can bail
// out early. // out early.
if self.prog.prefix.len() > 0 && clist.size == 0 { if self.prog.prefix.len() > 0 && clist.size == 0 {
let needle = self.prog.prefix.as_slice().as_bytes(); let needle = self.prog.prefix.as_bytes();
let haystack = self.input.as_bytes()[self.ic..]; let haystack = self.input.as_bytes()[self.ic..];
match find_prefix(needle, haystack) { match find_prefix(needle, haystack) {
None => break, None => break,

View file

@ -115,7 +115,7 @@ impl<'a> NfaGen<'a> {
// expression returned. // expression returned.
let num_cap_locs = 2 * self.prog.num_captures(); let num_cap_locs = 2 * self.prog.num_captures();
let num_insts = self.prog.insts.len(); let num_insts = self.prog.insts.len();
let cap_names = self.vec_expr(self.names.as_slice().iter(), let cap_names = self.vec_expr(self.names.iter(),
|cx, name| match *name { |cx, name| match *name {
Some(ref name) => { Some(ref name) => {
let name = name.as_slice(); let name = name.as_slice();
@ -125,14 +125,14 @@ impl<'a> NfaGen<'a> {
} }
); );
let prefix_anchor = let prefix_anchor =
match self.prog.insts.as_slice()[1] { match self.prog.insts[1] {
EmptyBegin(flags) if flags & FLAG_MULTI == 0 => true, EmptyBegin(flags) if flags & FLAG_MULTI == 0 => true,
_ => false, _ => false,
}; };
let init_groups = self.vec_expr(range(0, num_cap_locs), let init_groups = self.vec_expr(range(0, num_cap_locs),
|cx, _| cx.expr_none(self.sp)); |cx, _| cx.expr_none(self.sp));
let prefix_lit = Rc::new(self.prog.prefix.as_slice().as_bytes().to_vec()); let prefix_lit = Rc::new(self.prog.prefix.as_bytes().to_vec());
let prefix_bytes = self.cx.expr_lit(self.sp, ast::LitBinary(prefix_lit)); let prefix_bytes = self.cx.expr_lit(self.sp, ast::LitBinary(prefix_lit));
let check_prefix = self.check_prefix(); let check_prefix = self.check_prefix();

View file

@ -902,7 +902,7 @@ impl NonSnakeCase {
let mut buf = String::new(); let mut buf = String::new();
if s.is_empty() { continue; } if s.is_empty() { continue; }
for ch in s.chars() { for ch in s.chars() {
if !buf.is_empty() && buf.as_slice() != "'" if !buf.is_empty() && buf != "'"
&& ch.is_uppercase() && ch.is_uppercase()
&& !last_upper { && !last_upper {
words.push(buf); words.push(buf);

View file

@ -277,7 +277,7 @@ fn visit_item(e: &Env, i: &ast::Item) {
fn register_native_lib(sess: &Session, span: Option<Span>, name: String, fn register_native_lib(sess: &Session, span: Option<Span>, name: String,
kind: cstore::NativeLibaryKind) { kind: cstore::NativeLibaryKind) {
if name.as_slice().is_empty() { if name.is_empty() {
match span { match span {
Some(span) => { Some(span) => {
sess.span_err(span, "#[link(name = \"\")] given with \ sess.span_err(span, "#[link(name = \"\")] given with \
@ -304,7 +304,7 @@ fn existing_match(e: &Env, name: &str,
hash: Option<&Svh>) -> Option<ast::CrateNum> { hash: Option<&Svh>) -> Option<ast::CrateNum> {
let mut ret = None; let mut ret = None;
e.sess.cstore.iter_crate_data(|cnum, data| { e.sess.cstore.iter_crate_data(|cnum, data| {
if data.name.as_slice() != name { return } if data.name != name { return }
match hash { match hash {
Some(hash) if *hash == data.hash() => { ret = Some(cnum); return } Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }

View file

@ -162,7 +162,7 @@ impl CStore {
let mut ordering = Vec::new(); let mut ordering = Vec::new();
fn visit(cstore: &CStore, cnum: ast::CrateNum, fn visit(cstore: &CStore, cnum: ast::CrateNum,
ordering: &mut Vec<ast::CrateNum>) { ordering: &mut Vec<ast::CrateNum>) {
if ordering.as_slice().contains(&cnum) { return } if ordering.contains(&cnum) { return }
let meta = cstore.get_crate_data(cnum); let meta = cstore.get_crate_data(cnum);
for (_, &dep) in meta.cnum_map.iter() { for (_, &dep) in meta.cnum_map.iter() {
visit(cstore, dep, ordering); visit(cstore, dep, ordering);
@ -172,8 +172,7 @@ impl CStore {
for (&num, _) in self.metas.borrow().iter() { for (&num, _) in self.metas.borrow().iter() {
visit(self, num, &mut ordering); visit(self, num, &mut ordering);
} }
ordering.as_mut_slice().reverse(); ordering.reverse();
let ordering = ordering.as_slice();
let mut libs = self.used_crate_sources.borrow() let mut libs = self.used_crate_sources.borrow()
.iter() .iter()
.map(|src| (src.cnum, match prefer { .map(|src| (src.cnum, match prefer {

View file

@ -474,7 +474,7 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
// encoded metadata for static methods relative to Bar, // encoded metadata for static methods relative to Bar,
// but not yet for Foo. // but not yet for Foo.
// //
if path_differs || original_name.get() != exp.name.as_slice() { if path_differs || original_name.get() != exp.name {
if !encode_reexported_static_base_methods(ecx, rbml_w, exp) { if !encode_reexported_static_base_methods(ecx, rbml_w, exp) {
if encode_reexported_static_trait_methods(ecx, rbml_w, exp) { if encode_reexported_static_trait_methods(ecx, rbml_w, exp) {
debug!("(encode reexported static methods) {} [trait]", debug!("(encode reexported static methods) {} [trait]",

View file

@ -214,7 +214,7 @@ pub fn rust_path() -> Vec<Path> {
let mut env_rust_path: Vec<Path> = match get_rust_path() { let mut env_rust_path: Vec<Path> = match get_rust_path() {
Some(env_path) => { Some(env_path) => {
let env_path_components = let env_path_components =
env_path.as_slice().split_str(PATH_ENTRY_SEPARATOR); env_path.split_str(PATH_ENTRY_SEPARATOR);
env_path_components.map(|s| Path::new(s)).collect() env_path_components.map(|s| Path::new(s)).collect()
} }
None => Vec::new() None => Vec::new()

View file

@ -545,7 +545,7 @@ impl<'a> Context<'a> {
fn crate_matches(&mut self, crate_data: &[u8], libpath: &Path) -> bool { fn crate_matches(&mut self, crate_data: &[u8], libpath: &Path) -> bool {
if self.should_match_name { if self.should_match_name {
match decoder::maybe_get_crate_name(crate_data) { match decoder::maybe_get_crate_name(crate_data) {
Some(ref name) if self.crate_name == name.as_slice() => {} Some(ref name) if self.crate_name == *name => {}
_ => { info!("Rejecting via crate name"); return false } _ => { info!("Rejecting via crate name"); return false }
} }
} }
@ -560,7 +560,7 @@ impl<'a> Context<'a> {
None => { debug!("triple not present"); return false } None => { debug!("triple not present"); return false }
Some(t) => t, Some(t) => t,
}; };
if triple.as_slice() != self.triple { if triple != self.triple {
info!("Rejecting via crate triple: expected {} got {}", self.triple, triple); info!("Rejecting via crate triple: expected {} got {}", self.triple, triple);
self.rejected_via_triple.push(CrateMismatch { self.rejected_via_triple.push(CrateMismatch {
path: libpath.clone(), path: libpath.clone(),
@ -743,7 +743,7 @@ fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlo
let name = String::from_raw_buf_len(name_buf as *const u8, let name = String::from_raw_buf_len(name_buf as *const u8,
name_len as uint); name_len as uint);
debug!("get_metadata_section: name {}", name); debug!("get_metadata_section: name {}", name);
if read_meta_section_name(is_osx).as_slice() == name.as_slice() { if read_meta_section_name(is_osx) == name {
let cbuf = llvm::LLVMGetSectionContents(si.llsi); let cbuf = llvm::LLVMGetSectionContents(si.llsi);
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint; let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
let cvbuf: *const u8 = cbuf as *const u8; let cvbuf: *const u8 = cbuf as *const u8;

View file

@ -234,15 +234,15 @@ pub fn fixup_fragment_sets<'tcx>(this: &MoveData<'tcx>, tcx: &ty::ctxt<'tcx>) {
debug!("fragments 3 assigned: {}", path_lps(assigned.as_slice())); debug!("fragments 3 assigned: {}", path_lps(assigned.as_slice()));
// Fourth, build the leftover from the moved, assigned, and parents. // Fourth, build the leftover from the moved, assigned, and parents.
for m in moved.as_slice().iter() { for m in moved.iter() {
let lp = this.path_loan_path(*m); let lp = this.path_loan_path(*m);
add_fragment_siblings(this, tcx, &mut unmoved, lp, None); add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
} }
for a in assigned.as_slice().iter() { for a in assigned.iter() {
let lp = this.path_loan_path(*a); let lp = this.path_loan_path(*a);
add_fragment_siblings(this, tcx, &mut unmoved, lp, None); add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
} }
for p in parents.as_slice().iter() { for p in parents.iter() {
let lp = this.path_loan_path(*p); let lp = this.path_loan_path(*p);
add_fragment_siblings(this, tcx, &mut unmoved, lp, None); add_fragment_siblings(this, tcx, &mut unmoved, lp, None);
} }

View file

@ -31,14 +31,14 @@ pub struct LabelledCFG<'a, 'ast: 'a> {
fn replace_newline_with_backslash_l(s: String) -> String { fn replace_newline_with_backslash_l(s: String) -> String {
// Replacing newlines with \\l causes each line to be left-aligned, // Replacing newlines with \\l causes each line to be left-aligned,
// improving presentation of (long) pretty-printed expressions. // improving presentation of (long) pretty-printed expressions.
if s.as_slice().contains("\n") { if s.contains("\n") {
let mut s = s.replace("\n", "\\l"); let mut s = s.replace("\n", "\\l");
// Apparently left-alignment applies to the line that precedes // Apparently left-alignment applies to the line that precedes
// \l, not the line that follows; so, add \l at end of string // \l, not the line that follows; so, add \l at end of string
// if not already present, ensuring last line gets left-aligned // if not already present, ensuring last line gets left-aligned
// as well. // as well.
let mut last_two: Vec<_> = let mut last_two: Vec<_> =
s.as_slice().chars().rev().take(2).collect(); s.chars().rev().take(2).collect();
last_two.reverse(); last_two.reverse();
if last_two != ['\\', 'l'] { if last_two != ['\\', 'l'] {
s.push_str("\\l"); s.push_str("\\l");

View file

@ -321,7 +321,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
for attr in lint::gather_attrs(attrs).into_iter() { for attr in lint::gather_attrs(attrs).into_iter() {
match attr { match attr {
Ok((ref name, lint::Allow, _)) Ok((ref name, lint::Allow, _))
if name.get() == dead_code.as_slice() => return true, if name.get() == dead_code => return true,
_ => (), _ => (),
} }
} }

View file

@ -1065,7 +1065,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// the same bindings, and we also consider the first pattern to be // the same bindings, and we also consider the first pattern to be
// the "authoritative" set of ids // the "authoritative" set of ids
let arm_succ = let arm_succ =
self.define_bindings_in_arm_pats(arm.pats.as_slice().head().map(|p| &**p), self.define_bindings_in_arm_pats(arm.pats.head().map(|p| &**p),
guard_succ); guard_succ);
self.merge_from_succ(ln, arm_succ, first_merge); self.merge_from_succ(ln, arm_succ, first_merge);
first_merge = false; first_merge = false;
@ -1431,7 +1431,7 @@ fn check_arm(this: &mut Liveness, arm: &ast::Arm) {
// only consider the first pattern; any later patterns must have // only consider the first pattern; any later patterns must have
// the same bindings, and we also consider the first pattern to be // the same bindings, and we also consider the first pattern to be
// the "authoritative" set of ids // the "authoritative" set of ids
this.arm_pats_bindings(arm.pats.as_slice().head().map(|p| &**p), |this, ln, var, sp, id| { this.arm_pats_bindings(arm.pats.head().map(|p| &**p), |this, ln, var, sp, id| {
this.warn_about_unused(sp, id, ln, var); this.warn_about_unused(sp, id, ln, var);
}); });
visit::walk_arm(this, arm); visit::walk_arm(this, arm);

View file

@ -1668,7 +1668,7 @@ impl<'a> Resolver<'a> {
let module_path = match view_path.node { let module_path = match view_path.node {
ViewPathSimple(_, ref full_path, _) => { ViewPathSimple(_, ref full_path, _) => {
full_path.segments full_path.segments
.as_slice().init() .init()
.iter().map(|ident| ident.identifier.name) .iter().map(|ident| ident.identifier.name)
.collect() .collect()
} }
@ -1739,7 +1739,7 @@ impl<'a> Resolver<'a> {
continue; continue;
} }
}; };
let module_path = module_path.as_slice().init(); let module_path = module_path.init();
(module_path.to_vec(), name) (module_path.to_vec(), name)
} }
}; };
@ -3760,12 +3760,12 @@ impl<'a> Resolver<'a> {
.codemap() .codemap()
.span_to_snippet((*imports)[index].span) .span_to_snippet((*imports)[index].span)
.unwrap(); .unwrap();
if sn.as_slice().contains("::") { if sn.contains("::") {
self.resolve_error((*imports)[index].span, self.resolve_error((*imports)[index].span,
"unresolved import"); "unresolved import");
} else { } else {
let err = format!("unresolved import (maybe you meant `{}::*`?)", let err = format!("unresolved import (maybe you meant `{}::*`?)",
sn.as_slice().slice(0, sn.len())); sn.slice(0, sn.len()));
self.resolve_error((*imports)[index].span, err.as_slice()); self.resolve_error((*imports)[index].span, err.as_slice());
} }
} }
@ -5773,7 +5773,7 @@ impl<'a> Resolver<'a> {
}); });
if method_scope && token::get_name(self.self_name).get() if method_scope && token::get_name(self.self_name).get()
== wrong_name.as_slice() { == wrong_name {
self.resolve_error( self.resolve_error(
expr.span, expr.span,
"`self` is not available \ "`self` is not available \

View file

@ -2907,7 +2907,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
res = res | TC::ReachesFfiUnsafe; res = res | TC::ReachesFfiUnsafe;
} }
match repr_hints.as_slice().get(0) { match repr_hints.get(0) {
Some(h) => if !h.is_ffi_safe() { Some(h) => if !h.is_ffi_safe() {
res = res | TC::ReachesFfiUnsafe; res = res | TC::ReachesFfiUnsafe;
}, },
@ -3566,23 +3566,23 @@ pub fn positional_element_ty<'tcx>(cx: &ctxt<'tcx>,
variant: Option<ast::DefId>) -> Option<Ty<'tcx>> { variant: Option<ast::DefId>) -> Option<Ty<'tcx>> {
match (&ty.sty, variant) { match (&ty.sty, variant) {
(&ty_tup(ref v), None) => v.as_slice().get(i).map(|&t| t), (&ty_tup(ref v), None) => v.get(i).map(|&t| t),
(&ty_struct(def_id, ref substs), None) => lookup_struct_fields(cx, def_id) (&ty_struct(def_id, ref substs), None) => lookup_struct_fields(cx, def_id)
.as_slice().get(i) .get(i)
.map(|&t|lookup_item_type(cx, t.id).ty.subst(cx, substs)), .map(|&t|lookup_item_type(cx, t.id).ty.subst(cx, substs)),
(&ty_enum(def_id, ref substs), Some(variant_def_id)) => { (&ty_enum(def_id, ref substs), Some(variant_def_id)) => {
let variant_info = enum_variant_with_id(cx, def_id, variant_def_id); let variant_info = enum_variant_with_id(cx, def_id, variant_def_id);
variant_info.args.as_slice().get(i).map(|t|t.subst(cx, substs)) variant_info.args.get(i).map(|t|t.subst(cx, substs))
} }
(&ty_enum(def_id, ref substs), None) => { (&ty_enum(def_id, ref substs), None) => {
assert!(enum_is_univariant(cx, def_id)); assert!(enum_is_univariant(cx, def_id));
let enum_variants = enum_variants(cx, def_id); let enum_variants = enum_variants(cx, def_id);
let variant_info = &(*enum_variants)[0]; let variant_info = &(*enum_variants)[0];
variant_info.args.as_slice().get(i).map(|t|t.subst(cx, substs)) variant_info.args.get(i).map(|t|t.subst(cx, substs))
} }
_ => None _ => None

View file

@ -512,13 +512,13 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
{ {
let mut cg = basic_codegen_options(); let mut cg = basic_codegen_options();
for option in matches.opt_strs("C").into_iter() { for option in matches.opt_strs("C").into_iter() {
let mut iter = option.as_slice().splitn(1, '='); let mut iter = option.splitn(1, '=');
let key = iter.next().unwrap(); let key = iter.next().unwrap();
let value = iter.next(); let value = iter.next();
let option_to_lookup = key.replace("-", "_"); let option_to_lookup = key.replace("-", "_");
let mut found = false; let mut found = false;
for &(candidate, setter, opt_type_desc, _) in CG_OPTIONS.iter() { for &(candidate, setter, opt_type_desc, _) in CG_OPTIONS.iter() {
if option_to_lookup.as_slice() != candidate { continue } if option_to_lookup != candidate { continue }
if !setter(&mut cg, value) { if !setter(&mut cg, value) {
match (value, opt_type_desc) { match (value, opt_type_desc) {
(Some(..), None) => { (Some(..), None) => {
@ -714,7 +714,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
for &level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid].iter() { for &level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid].iter() {
for lint_name in matches.opt_strs(level.as_str()).into_iter() { for lint_name in matches.opt_strs(level.as_str()).into_iter() {
if lint_name.as_slice() == "help" { if lint_name == "help" {
describe_lints = true; describe_lints = true;
} else { } else {
lint_opts.push((lint_name.replace("-", "_").into_string(), level)); lint_opts.push((lint_name.replace("-", "_").into_string(), level));
@ -727,9 +727,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let debug_map = debugging_opts_map(); let debug_map = debugging_opts_map();
for debug_flag in debug_flags.iter() { for debug_flag in debug_flags.iter() {
let mut this_bit = 0; let mut this_bit = 0;
for tuple in debug_map.iter() { for &(name, _, bit) in debug_map.iter() {
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) }; if name == *debug_flag {
if *name == debug_flag.as_slice() {
this_bit = bit; this_bit = bit;
break; break;
} }
@ -749,7 +748,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
if !parse_only && !no_trans { if !parse_only && !no_trans {
let unparsed_output_types = matches.opt_strs("emit"); let unparsed_output_types = matches.opt_strs("emit");
for unparsed_output_type in unparsed_output_types.iter() { for unparsed_output_type in unparsed_output_types.iter() {
for part in unparsed_output_type.as_slice().split(',') { for part in unparsed_output_type.split(',') {
let output_type = match part.as_slice() { let output_type = match part.as_slice() {
"asm" => OutputTypeAssembly, "asm" => OutputTypeAssembly,
"ir" => OutputTypeLlvmAssembly, "ir" => OutputTypeLlvmAssembly,
@ -765,7 +764,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
} }
} }
}; };
output_types.as_mut_slice().sort(); output_types.sort();
output_types.dedup(); output_types.dedup();
if output_types.len() == 0 { if output_types.len() == 0 {
output_types.push(OutputTypeExe); output_types.push(OutputTypeExe);
@ -824,7 +823,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
}).collect(); }).collect();
let libs = matches.opt_strs("l").into_iter().map(|s| { let libs = matches.opt_strs("l").into_iter().map(|s| {
let mut parts = s.as_slice().rsplitn(1, ':'); let mut parts = s.rsplitn(1, ':');
let kind = parts.next().unwrap(); let kind = parts.next().unwrap();
let (name, kind) = match (parts.next(), kind) { let (name, kind) = match (parts.next(), kind) {
(None, name) | (None, name) |
@ -875,7 +874,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let mut externs = HashMap::new(); let mut externs = HashMap::new();
for arg in matches.opt_strs("extern").iter() { for arg in matches.opt_strs("extern").iter() {
let mut parts = arg.as_slice().splitn(1, '='); let mut parts = arg.splitn(1, '=');
let name = match parts.next() { let name = match parts.next() {
Some(s) => s, Some(s) => s,
None => early_error("--extern value must not be empty"), None => early_error("--extern value must not be empty"),
@ -925,7 +924,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
let mut crate_types: Vec<CrateType> = Vec::new(); let mut crate_types: Vec<CrateType> = Vec::new();
for unparsed_crate_type in list_list.iter() { for unparsed_crate_type in list_list.iter() {
for part in unparsed_crate_type.as_slice().split(',') { for part in unparsed_crate_type.split(',') {
let new_part = match part { let new_part = match part {
"lib" => default_lib_output(), "lib" => default_lib_output(),
"rlib" => CrateTypeRlib, "rlib" => CrateTypeRlib,

View file

@ -257,7 +257,7 @@ pub fn build_session_(sopts: config::Options,
let can_print_warnings = sopts.lint_opts let can_print_warnings = sopts.lint_opts
.iter() .iter()
.filter(|&&(ref key, _)| key.as_slice() == "warnings") .filter(|&&(ref key, _)| *key == "warnings")
.map(|&(_, ref level)| *level != lint::Allow) .map(|&(_, ref level)| *level != lint::Allow)
.last() .last()
.unwrap_or(true); .unwrap_or(true);

View file

@ -538,7 +538,7 @@ pub fn parameterized<'tcx>(cx: &ctxt<'tcx>,
pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String { pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String {
let mut s = typ.repr(cx).to_string(); let mut s = typ.repr(cx).to_string();
if s.len() >= 32u { if s.len() >= 32u {
s = s.as_slice().slice(0u, 32u).to_string(); s = s.slice(0u, 32u).to_string();
} }
return s; return s;
} }

View file

@ -12,7 +12,7 @@ use target_strs;
use syntax::abi; use syntax::abi;
pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t { pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t {
let cc_args = if target_triple.as_slice().contains("thumb") { let cc_args = if target_triple.contains("thumb") {
vec!("-mthumb".to_string()) vec!("-mthumb".to_string())
} else { } else {
vec!("-marm".to_string()) vec!("-marm".to_string())

View file

@ -145,8 +145,8 @@ mod test {
"path2".to_string() "path2".to_string()
]); ]);
assert_eq!(flags, assert_eq!(flags,
vec!("-Wl,-rpath,path1".to_string(), ["-Wl,-rpath,path1",
"-Wl,-rpath,path2".to_string())); "-Wl,-rpath,path2"]);
} }
#[test] #[test]
@ -156,9 +156,9 @@ mod test {
"rpath2".to_string(), "rpath2".to_string(),
"rpath1".to_string() "rpath1".to_string()
]); ]);
assert!(res.as_slice() == [ assert!(res == [
"rpath1".to_string(), "rpath1",
"rpath2".to_string() "rpath2",
]); ]);
} }
@ -176,11 +176,11 @@ mod test {
"4a".to_string(), "4a".to_string(),
"3".to_string() "3".to_string()
]); ]);
assert!(res.as_slice() == [ assert!(res == [
"1a".to_string(), "1a",
"2".to_string(), "2",
"4a".to_string(), "4a",
"3".to_string() "3",
]); ]);
} }
@ -196,7 +196,7 @@ mod test {
realpath: |p| Ok(p.clone()) realpath: |p| Ok(p.clone())
}; };
let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so"));
assert_eq!(res.as_slice(), "$ORIGIN/../lib"); assert_eq!(res, "$ORIGIN/../lib");
} }
#[test] #[test]
@ -211,7 +211,7 @@ mod test {
realpath: |p| Ok(p.clone()) realpath: |p| Ok(p.clone())
}; };
let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so"));
assert_eq!(res.as_slice(), "$ORIGIN/../lib"); assert_eq!(res, "$ORIGIN/../lib");
} }
#[test] #[test]
@ -226,7 +226,7 @@ mod test {
realpath: |p| Ok(p.clone()) realpath: |p| Ok(p.clone())
}; };
let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so"));
assert_eq!(res.as_slice(), "$ORIGIN/../lib"); assert_eq!(res, "$ORIGIN/../lib");
} }
#[test] #[test]
@ -241,6 +241,6 @@ mod test {
realpath: |p| Ok(p.clone()) realpath: |p| Ok(p.clone())
}; };
let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so"));
assert_eq!(res.as_slice(), "@loader_path/../lib"); assert_eq!(res, "@loader_path/../lib");
} }
} }

View file

@ -263,7 +263,7 @@ pub trait Digest {
/// Convenience function that retrieves the result of a digest as a /// Convenience function that retrieves the result of a digest as a
/// String in hexadecimal format. /// String in hexadecimal format.
fn result_str(&mut self) -> String { fn result_str(&mut self) -> String {
self.result_bytes().as_slice().to_hex().to_string() self.result_bytes().to_hex().to_string()
} }
} }
@ -568,7 +568,6 @@ mod tests {
while left > 0u { while left > 0u {
let take = (left + 1u) / 2u; let take = (left + 1u) / 2u;
sh.input_str(t.input sh.input_str(t.input
.as_slice()
.slice(len - left, take + len - left)); .slice(len - left, take + len - left));
left = left - take; left = left - take;
} }

View file

@ -200,7 +200,7 @@ impl Target {
pub fn adjust_abi(&self, abi: abi::Abi) -> abi::Abi { pub fn adjust_abi(&self, abi: abi::Abi) -> abi::Abi {
match abi { match abi {
abi::System => { abi::System => {
if self.options.is_like_windows && self.arch.as_slice() == "x86" { if self.options.is_like_windows && self.arch == "x86" {
abi::Stdcall abi::Stdcall
} else { } else {
abi::C abi::C
@ -308,7 +308,6 @@ impl Target {
( $($name:ident),+ ) => ( ( $($name:ident),+ ) => (
{ {
let target = target.replace("-", "_"); let target = target.replace("-", "_");
let target = target.as_slice();
if false { } if false { }
$( $(
else if target == stringify!($name) { else if target == stringify!($name) {

View file

@ -682,7 +682,7 @@ pub fn collect_crate_types(session: &Session,
if base.len() == 0 { if base.len() == 0 {
base.push(link::default_output_for_target(session)); base.push(link::default_output_for_target(session));
} }
base.as_mut_slice().sort(); base.sort();
base.dedup(); base.dedup();
} }

View file

@ -378,13 +378,13 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
// Don't handle -W help here, because we might first load plugins. // Don't handle -W help here, because we might first load plugins.
let r = matches.opt_strs("Z"); let r = matches.opt_strs("Z");
if r.iter().any(|x| x.as_slice() == "help") { if r.iter().any(|x| *x == "help") {
describe_debug_flags(); describe_debug_flags();
return None; return None;
} }
let cg_flags = matches.opt_strs("C"); let cg_flags = matches.opt_strs("C");
if cg_flags.iter().any(|x| x.as_slice() == "help") { if cg_flags.iter().any(|x| *x == "help") {
describe_codegen_flags(); describe_codegen_flags();
return None; return None;
} }

View file

@ -140,7 +140,7 @@ pub fn find_crate_name(sess: Option<&Session>,
if let Some(sess) = sess { if let Some(sess) = sess {
if let Some(ref s) = sess.opts.crate_name { if let Some(ref s) = sess.opts.crate_name {
if let Some((attr, ref name)) = attr_crate_name { if let Some((attr, ref name)) = attr_crate_name {
if s.as_slice() != name.get() { if *s != name.get() {
let msg = format!("--crate-name and #[crate_name] are \ let msg = format!("--crate-name and #[crate_name] are \
required to match, but `{}` != `{}`", required to match, but `{}` != `{}`",
s, name); s, name);
@ -249,7 +249,7 @@ pub fn sanitize(s: &str) -> String {
let mut tstr = String::new(); let mut tstr = String::new();
for c in c.escape_unicode() { tstr.push(c) } for c in c.escape_unicode() { tstr.push(c) }
result.push('$'); result.push('$');
result.push_str(tstr.as_slice().slice_from(1)); result.push_str(tstr.slice_from(1));
} }
} }
} }
@ -669,7 +669,7 @@ fn link_rlib<'a>(sess: &'a Session,
fn write_rlib_bytecode_object_v1<T: Writer>(writer: &mut T, fn write_rlib_bytecode_object_v1<T: Writer>(writer: &mut T,
bc_data_deflated: &[u8]) bc_data_deflated: &[u8])
-> ::std::io::IoResult<()> { -> ::std::io::IoResult<()> {
let bc_data_deflated_size: u64 = bc_data_deflated.as_slice().len() as u64; let bc_data_deflated_size: u64 = bc_data_deflated.len() as u64;
try! { writer.write(RLIB_BYTECODE_OBJECT_MAGIC) }; try! { writer.write(RLIB_BYTECODE_OBJECT_MAGIC) };
try! { writer.write_le_u32(1) }; try! { writer.write_le_u32(1) };
@ -910,10 +910,10 @@ fn link_args(cmd: &mut Command,
let args = sess.opts.cg.link_args.as_ref().unwrap_or(&empty_vec); let args = sess.opts.cg.link_args.as_ref().unwrap_or(&empty_vec);
let mut args = args.iter().chain(used_link_args.iter()); let mut args = args.iter().chain(used_link_args.iter());
if !dylib if !dylib
&& (t.options.relocation_model.as_slice() == "pic" && (t.options.relocation_model == "pic"
|| sess.opts.cg.relocation_model.as_ref() || *sess.opts.cg.relocation_model.as_ref()
.unwrap_or(&empty_str).as_slice() == "pic") .unwrap_or(&empty_str) == "pic")
&& !args.any(|x| x.as_slice() == "-static") { && !args.any(|x| *x == "-static") {
cmd.arg("-pie"); cmd.arg("-pie");
} }
} }

View file

@ -143,7 +143,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
// Internalize everything but the reachable symbols of the current module // Internalize everything but the reachable symbols of the current module
let cstrs: Vec<::std::c_str::CString> = let cstrs: Vec<::std::c_str::CString> =
reachable.iter().map(|s| s.as_slice().to_c_str()).collect(); reachable.iter().map(|s| s.to_c_str()).collect();
let arr: Vec<*const i8> = cstrs.iter().map(|c| c.as_ptr()).collect(); let arr: Vec<*const i8> = cstrs.iter().map(|c| c.as_ptr()).collect();
let ptr = arr.as_ptr(); let ptr = arr.as_ptr();
unsafe { unsafe {

View file

@ -363,7 +363,7 @@ unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_vo
let pass_name = pass_name.as_str().expect("got a non-UTF8 pass name from LLVM"); let pass_name = pass_name.as_str().expect("got a non-UTF8 pass name from LLVM");
let enabled = match cgcx.remark { let enabled = match cgcx.remark {
AllPasses => true, AllPasses => true,
SomePasses(ref v) => v.iter().any(|s| s.as_slice() == pass_name), SomePasses(ref v) => v.iter().any(|s| *s == pass_name),
}; };
if enabled { if enabled {
@ -421,7 +421,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
// If we're verifying or linting, add them to the function pass // If we're verifying or linting, add them to the function pass
// manager. // manager.
let addpass = |pass: &str| { let addpass = |pass: &str| {
pass.as_slice().with_c_str(|s| llvm::LLVMRustAddPass(fpm, s)) pass.with_c_str(|s| llvm::LLVMRustAddPass(fpm, s))
}; };
if !config.no_verify { assert!(addpass("verify")); } if !config.no_verify { assert!(addpass("verify")); }
@ -433,7 +433,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
} }
for pass in config.passes.iter() { for pass in config.passes.iter() {
pass.as_slice().with_c_str(|s| { pass.with_c_str(|s| {
if !llvm::LLVMRustAddPass(mpm, s) { if !llvm::LLVMRustAddPass(mpm, s) {
cgcx.handler.warn(format!("unknown pass {}, ignoring", cgcx.handler.warn(format!("unknown pass {}, ignoring",
*pass).as_slice()); *pass).as_slice());

View file

@ -163,7 +163,7 @@ impl<'a> FmtStrs<'a> {
let values = values.iter().map(|s| { let values = values.iter().map(|s| {
// Never take more than 1020 chars // Never take more than 1020 chars
if s.len() > 1020 { if s.len() > 1020 {
s.as_slice().slice_to(1020) s.slice_to(1020)
} else { } else {
s.as_slice() s.as_slice()
} }

View file

@ -122,7 +122,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
}; };
let r = ia.asm.get().with_c_str(|a| { let r = ia.asm.get().with_c_str(|a| {
constraints.as_slice().with_c_str(|c| { constraints.with_c_str(|c| {
InlineAsmCall(bcx, InlineAsmCall(bcx,
a, a,
c, c,

View file

@ -2739,7 +2739,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
format!("Illegal null byte in export_name \ format!("Illegal null byte in export_name \
value: `{}`", sym).as_slice()); value: `{}`", sym).as_slice());
} }
let g = sym.as_slice().with_c_str(|buf| { let g = sym.with_c_str(|buf| {
llvm::LLVMAddGlobal(ccx.llmod(), llty, buf) llvm::LLVMAddGlobal(ccx.llmod(), llty, buf)
}); });

View file

@ -774,7 +774,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let comment_text = format!("{} {}", "#", let comment_text = format!("{} {}", "#",
sanitized.replace("\n", "\n\t# ")); sanitized.replace("\n", "\n\t# "));
self.count_insn("inlineasm"); self.count_insn("inlineasm");
let asm = comment_text.as_slice().with_c_str(|c| { let asm = comment_text.with_c_str(|c| {
unsafe { unsafe {
llvm::LLVMConstInlineAsm(Type::func(&[], &Type::void(self.ccx)).to_ref(), llvm::LLVMConstInlineAsm(Type::func(&[], &Type::void(self.ccx)).to_ref(),
c, noname(), False, False) c, noname(), False, False)

View file

@ -222,14 +222,12 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
sess.target sess.target
.target .target
.data_layout .data_layout
.as_slice()
.with_c_str(|buf| { .with_c_str(|buf| {
llvm::LLVMSetDataLayout(llmod, buf); llvm::LLVMSetDataLayout(llmod, buf);
}); });
sess.target sess.target
.target .target
.llvm_target .llvm_target
.as_slice()
.with_c_str(|buf| { .with_c_str(|buf| {
llvm::LLVMRustSetNormalizedTarget(llmod, buf); llvm::LLVMRustSetNormalizedTarget(llmod, buf);
}); });

View file

@ -824,8 +824,8 @@ pub fn create_global_var_metadata(cx: &CrateContext,
namespace_node.mangled_name_of_contained_item(var_name.as_slice()); namespace_node.mangled_name_of_contained_item(var_name.as_slice());
let var_scope = namespace_node.scope; let var_scope = namespace_node.scope;
var_name.as_slice().with_c_str(|var_name| { var_name.with_c_str(|var_name| {
linkage_name.as_slice().with_c_str(|linkage_name| { linkage_name.with_c_str(|linkage_name| {
unsafe { unsafe {
llvm::LLVMDIBuilderCreateStaticVariable(DIB(cx), llvm::LLVMDIBuilderCreateStaticVariable(DIB(cx),
var_scope, var_scope,
@ -1323,7 +1323,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let containing_scope = namespace_node.scope; let containing_scope = namespace_node.scope;
(linkage_name, containing_scope) (linkage_name, containing_scope)
} else { } else {
(function_name.as_slice().to_string(), file_metadata) (function_name.clone(), file_metadata)
}; };
// Clang sets this parameter to the opening brace of the function's block, // Clang sets this parameter to the opening brace of the function's block,
@ -1332,8 +1332,8 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let is_local_to_unit = is_node_local_to_unit(cx, fn_ast_id); let is_local_to_unit = is_node_local_to_unit(cx, fn_ast_id);
let fn_metadata = function_name.as_slice().with_c_str(|function_name| { let fn_metadata = function_name.with_c_str(|function_name| {
linkage_name.as_slice().with_c_str(|linkage_name| { linkage_name.with_c_str(|linkage_name| {
unsafe { unsafe {
llvm::LLVMDIBuilderCreateFunction( llvm::LLVMDIBuilderCreateFunction(
DIB(cx), DIB(cx),
@ -1554,7 +1554,7 @@ fn compile_unit_metadata(cx: &CrateContext) {
path_bytes.insert(1, prefix[1]); path_bytes.insert(1, prefix[1]);
} }
path_bytes.as_slice().to_c_str() path_bytes.to_c_str()
} }
_ => fallback_path(cx) _ => fallback_path(cx)
} }
@ -1589,7 +1589,7 @@ fn compile_unit_metadata(cx: &CrateContext) {
}); });
fn fallback_path(cx: &CrateContext) -> CString { fn fallback_path(cx: &CrateContext) -> CString {
cx.link_meta().crate_name.as_slice().to_c_str() cx.link_meta().crate_name.to_c_str()
} }
} }
@ -1796,7 +1796,7 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let pointer_llvm_type = type_of::type_of(cx, pointer_type); let pointer_llvm_type = type_of::type_of(cx, pointer_type);
let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type); let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type);
let name = compute_debuginfo_type_name(cx, pointer_type, false); let name = compute_debuginfo_type_name(cx, pointer_type, false);
let ptr_metadata = name.as_slice().with_c_str(|name| { let ptr_metadata = name.with_c_str(|name| {
unsafe { unsafe {
llvm::LLVMDIBuilderCreatePointerType( llvm::LLVMDIBuilderCreatePointerType(
DIB(cx), DIB(cx),
@ -2488,8 +2488,8 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
.borrow() .borrow()
.get_unique_type_id_as_string(unique_type_id); .get_unique_type_id_as_string(unique_type_id);
let enum_metadata = enum_name.as_slice().with_c_str(|enum_name| { let enum_metadata = enum_name.with_c_str(|enum_name| {
unique_type_id_str.as_slice().with_c_str(|unique_type_id_str| { unique_type_id_str.with_c_str(|unique_type_id_str| {
unsafe { unsafe {
llvm::LLVMDIBuilderCreateUnionType( llvm::LLVMDIBuilderCreateUnionType(
DIB(cx), DIB(cx),
@ -2616,7 +2616,7 @@ fn set_members_of_composite_type(cx: &CrateContext,
ComputedMemberOffset => machine::llelement_offset(cx, composite_llvm_type, i) ComputedMemberOffset => machine::llelement_offset(cx, composite_llvm_type, i)
}; };
member_description.name.as_slice().with_c_str(|member_name| { member_description.name.with_c_str(|member_name| {
unsafe { unsafe {
llvm::LLVMDIBuilderCreateMemberType( llvm::LLVMDIBuilderCreateMemberType(
DIB(cx), DIB(cx),
@ -2656,7 +2656,7 @@ fn create_struct_stub(cx: &CrateContext,
.get_unique_type_id_as_string(unique_type_id); .get_unique_type_id_as_string(unique_type_id);
let metadata_stub = unsafe { let metadata_stub = unsafe {
struct_type_name.with_c_str(|name| { struct_type_name.with_c_str(|name| {
unique_type_id_str.as_slice().with_c_str(|unique_type_id| { unique_type_id_str.with_c_str(|unique_type_id| {
// LLVMDIBuilderCreateStructType() wants an empty array. A null // LLVMDIBuilderCreateStructType() wants an empty array. A null
// pointer will lead to hard to trace and debug LLVM assertions // pointer will lead to hard to trace and debug LLVM assertions
// later on in llvm/lib/IR/Value.cpp. // later on in llvm/lib/IR/Value.cpp.

View file

@ -496,7 +496,7 @@ pub fn declare_tydesc<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>)
let llalign = llalign_of(ccx, llty); let llalign = llalign_of(ccx, llty);
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc"); let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc");
debug!("+++ declare_tydesc {} {}", ppaux::ty_to_string(ccx.tcx(), t), name); debug!("+++ declare_tydesc {} {}", ppaux::ty_to_string(ccx.tcx(), t), name);
let gvar = name.as_slice().with_c_str(|buf| { let gvar = name.with_c_str(|buf| {
unsafe { unsafe {
llvm::LLVMAddGlobal(ccx.llmod(), ccx.tydesc_type().to_ref(), buf) llvm::LLVMAddGlobal(ccx.llmod(), ccx.tydesc_type().to_ref(), buf)
} }

View file

@ -341,10 +341,10 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
fn is_doc_hidden(a: &clean::Attribute) -> bool { fn is_doc_hidden(a: &clean::Attribute) -> bool {
match *a { match *a {
clean::List(ref name, ref inner) if name.as_slice() == "doc" => { clean::List(ref name, ref inner) if *name == "doc" => {
inner.iter().any(|a| { inner.iter().any(|a| {
match *a { match *a {
clean::Word(ref s) => s.as_slice() == "hidden", clean::Word(ref s) => *s == "hidden",
_ => false, _ => false,
} }
}) })

View file

@ -256,7 +256,7 @@ impl Item {
pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> { pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> {
for attr in self.attrs.iter() { for attr in self.attrs.iter() {
match *attr { match *attr {
List(ref x, ref list) if "doc" == x.as_slice() => { List(ref x, ref list) if "doc" == *x => {
return Some(list.as_slice()); return Some(list.as_slice());
} }
_ => {} _ => {}
@ -270,7 +270,7 @@ impl Item {
pub fn doc_value<'a>(&'a self) -> Option<&'a str> { pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
for attr in self.attrs.iter() { for attr in self.attrs.iter() {
match *attr { match *attr {
NameValue(ref x, ref v) if "doc" == x.as_slice() => { NameValue(ref x, ref v) if "doc" == *x => {
return Some(v.as_slice()); return Some(v.as_slice());
} }
_ => {} _ => {}
@ -284,7 +284,7 @@ impl Item {
Some(ref l) => { Some(ref l) => {
for innerattr in l.iter() { for innerattr in l.iter() {
match *innerattr { match *innerattr {
Word(ref s) if "hidden" == s.as_slice() => { Word(ref s) if "hidden" == *s => {
return true return true
} }
_ => (), _ => (),
@ -1217,13 +1217,13 @@ impl PrimitiveType {
fn find(attrs: &[Attribute]) -> Option<PrimitiveType> { fn find(attrs: &[Attribute]) -> Option<PrimitiveType> {
for attr in attrs.iter() { for attr in attrs.iter() {
let list = match *attr { let list = match *attr {
List(ref k, ref l) if k.as_slice() == "doc" => l, List(ref k, ref l) if *k == "doc" => l,
_ => continue, _ => continue,
}; };
for sub_attr in list.iter() { for sub_attr in list.iter() {
let value = match *sub_attr { let value = match *sub_attr {
NameValue(ref k, ref v) NameValue(ref k, ref v)
if k.as_slice() == "primitive" => v.as_slice(), if *k == "primitive" => v.as_slice(),
_ => continue, _ => continue,
}; };
match PrimitiveType::from_str(value) { match PrimitiveType::from_str(value) {

View file

@ -251,8 +251,8 @@ fn path(w: &mut fmt::Formatter, path: &clean::Path, print_all: bool,
Some(root) => { Some(root) => {
let mut root = String::from_str(root.as_slice()); let mut root = String::from_str(root.as_slice());
for seg in path.segments[..amt].iter() { for seg in path.segments[..amt].iter() {
if "super" == seg.name.as_slice() || if "super" == seg.name ||
"self" == seg.name.as_slice() { "self" == seg.name {
try!(write!(w, "{}::", seg.name)); try!(write!(w, "{}::", seg.name));
} else { } else {
root.push_str(seg.name.as_slice()); root.push_str(seg.name.as_slice());
@ -337,7 +337,7 @@ fn primitive_link(f: &mut fmt::Formatter,
Some(root) => { Some(root) => {
try!(write!(f, "<a href='{}{}/primitive.{}.html'>", try!(write!(f, "<a href='{}{}/primitive.{}.html'>",
root, root,
path.ref0().as_slice().head().unwrap(), path.ref0().head().unwrap(),
prim.to_url_str())); prim.to_url_str()));
needs_termination = true; needs_termination = true;
} }

View file

@ -231,7 +231,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
}; };
// Transform the contents of the header into a hyphenated string // Transform the contents of the header into a hyphenated string
let id = s.as_slice().words().map(|s| s.to_ascii_lower()) let id = s.words().map(|s| s.to_ascii_lower())
.collect::<Vec<String>>().connect("-"); .collect::<Vec<String>>().connect("-");
// This is a terrible hack working around how hoedown gives us rendered // This is a terrible hack working around how hoedown gives us rendered
@ -393,7 +393,7 @@ impl LangString {
let mut seen_other_tags = false; let mut seen_other_tags = false;
let mut data = LangString::all_false(); let mut data = LangString::all_false();
let mut tokens = string.as_slice().split(|c: char| let mut tokens = string.split(|c: char|
!(c == '_' || c == '-' || c.is_alphanumeric()) !(c == '_' || c == '-' || c.is_alphanumeric())
); );

View file

@ -277,15 +277,15 @@ pub fn run(mut krate: clean::Crate,
for attr in attrs.iter() { for attr in attrs.iter() {
match *attr { match *attr {
clean::NameValue(ref x, ref s) clean::NameValue(ref x, ref s)
if "html_favicon_url" == x.as_slice() => { if "html_favicon_url" == *x => {
cx.layout.favicon = s.to_string(); cx.layout.favicon = s.to_string();
} }
clean::NameValue(ref x, ref s) clean::NameValue(ref x, ref s)
if "html_logo_url" == x.as_slice() => { if "html_logo_url" == *x => {
cx.layout.logo = s.to_string(); cx.layout.logo = s.to_string();
} }
clean::NameValue(ref x, ref s) clean::NameValue(ref x, ref s)
if "html_playground_url" == x.as_slice() => { if "html_playground_url" == *x => {
cx.layout.playground_url = s.to_string(); cx.layout.playground_url = s.to_string();
markdown::PLAYGROUND_KRATE.with(|slot| { markdown::PLAYGROUND_KRATE.with(|slot| {
if slot.borrow().is_none() { if slot.borrow().is_none() {
@ -295,7 +295,7 @@ pub fn run(mut krate: clean::Crate,
}); });
} }
clean::Word(ref x) clean::Word(ref x)
if "html_no_source" == x.as_slice() => { if "html_no_source" == *x => {
cx.include_sources = false; cx.include_sources = false;
} }
_ => {} _ => {}
@ -434,7 +434,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult<String>
for (i, item) in cache.search_index.iter().enumerate() { for (i, item) in cache.search_index.iter().enumerate() {
// Omit the path if it is same to that of the prior item. // Omit the path if it is same to that of the prior item.
let path; let path;
if lastpath.as_slice() == item.path.as_slice() { if lastpath == item.path {
path = ""; path = "";
} else { } else {
lastpath = item.path.to_string(); lastpath = item.path.to_string();
@ -513,10 +513,10 @@ fn write_shared(cx: &Context,
if path.exists() { if path.exists() {
for line in BufferedReader::new(File::open(path)).lines() { for line in BufferedReader::new(File::open(path)).lines() {
let line = try!(line); let line = try!(line);
if !line.as_slice().starts_with(key) { if !line.starts_with(key) {
continue continue
} }
if line.as_slice().starts_with( if line.starts_with(
format!("{}['{}']", key, krate).as_slice()) { format!("{}['{}']", key, krate).as_slice()) {
continue continue
} }
@ -670,12 +670,12 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
// external crate // external crate
for attr in e.attrs.iter() { for attr in e.attrs.iter() {
match *attr { match *attr {
clean::List(ref x, ref list) if "doc" == x.as_slice() => { clean::List(ref x, ref list) if "doc" == *x => {
for attr in list.iter() { for attr in list.iter() {
match *attr { match *attr {
clean::NameValue(ref x, ref s) clean::NameValue(ref x, ref s)
if "html_root_url" == x.as_slice() => { if "html_root_url" == *x => {
if s.as_slice().ends_with("/") { if s.ends_with("/") {
return Remote(s.to_string()); return Remote(s.to_string());
} }
return Remote(format!("{}/", s)); return Remote(format!("{}/", s));
@ -964,7 +964,7 @@ impl DocFolder for Cache {
let dox = match attrs.into_iter().find(|a| { let dox = match attrs.into_iter().find(|a| {
match *a { match *a {
clean::NameValue(ref x, _) clean::NameValue(ref x, _)
if "doc" == x.as_slice() => { if "doc" == *x => {
true true
} }
_ => false _ => false
@ -1261,7 +1261,7 @@ impl Context {
} }
for (_, items) in map.iter_mut() { for (_, items) in map.iter_mut() {
items.as_mut_slice().sort(); items.sort();
} }
return map; return map;
} }

View file

@ -299,7 +299,7 @@ fn acquire_input(input: &str,
fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> { fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
let mut externs = HashMap::new(); let mut externs = HashMap::new();
for arg in matches.opt_strs("extern").iter() { for arg in matches.opt_strs("extern").iter() {
let mut parts = arg.as_slice().splitn(1, '='); let mut parts = arg.splitn(1, '=');
let name = match parts.next() { let name = match parts.next() {
Some(s) => s, Some(s) => s,
None => { None => {
@ -363,18 +363,18 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
for inner in nested.iter() { for inner in nested.iter() {
match *inner { match *inner {
clean::Word(ref x) clean::Word(ref x)
if "no_default_passes" == x.as_slice() => { if "no_default_passes" == *x => {
default_passes = false; default_passes = false;
} }
clean::NameValue(ref x, ref value) clean::NameValue(ref x, ref value)
if "passes" == x.as_slice() => { if "passes" == *x => {
for pass in value.as_slice().words() { for pass in value.words() {
passes.push(pass.to_string()); passes.push(pass.to_string());
} }
} }
clean::NameValue(ref x, ref value) clean::NameValue(ref x, ref value)
if "plugins" == x.as_slice() => { if "plugins" == *x => {
for p in value.as_slice().words() { for p in value.words() {
plugins.push(p.to_string()); plugins.push(p.to_string());
} }
} }
@ -397,7 +397,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
for pass in passes.iter() { for pass in passes.iter() {
let plugin = match PASSES.iter() let plugin = match PASSES.iter()
.position(|&(p, _, _)| { .position(|&(p, _, _)| {
p == pass.as_slice() p == *pass
}) { }) {
Some(i) => PASSES[i].val1(), Some(i) => PASSES[i].val1(),
None => { None => {
@ -434,7 +434,7 @@ fn json_input(input: &str) -> Result<Output, String> {
// Make sure the schema is what we expect // Make sure the schema is what we expect
match obj.remove(&"schema".to_string()) { match obj.remove(&"schema".to_string()) {
Some(Json::String(version)) => { Some(Json::String(version)) => {
if version.as_slice() != SCHEMA_VERSION { if version != SCHEMA_VERSION {
return Err(format!( return Err(format!(
"sorry, but I only understand version {}", "sorry, but I only understand version {}",
SCHEMA_VERSION)) SCHEMA_VERSION))

View file

@ -258,7 +258,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
for attr in i.attrs.iter() { for attr in i.attrs.iter() {
match attr { match attr {
&clean::NameValue(ref x, ref s) &clean::NameValue(ref x, ref s)
if "doc" == x.as_slice() => { if "doc" == *x => {
avec.push(clean::NameValue("doc".to_string(), avec.push(clean::NameValue("doc".to_string(),
unindent(s.as_slice()))) unindent(s.as_slice())))
} }
@ -283,7 +283,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
for attr in i.attrs.iter() { for attr in i.attrs.iter() {
match *attr { match *attr {
clean::NameValue(ref x, ref s) clean::NameValue(ref x, ref s)
if "doc" == x.as_slice() => { if "doc" == *x => {
docstr.push_str(s.as_slice()); docstr.push_str(s.as_slice());
docstr.push('\n'); docstr.push('\n');
}, },
@ -291,7 +291,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
} }
} }
let mut a: Vec<clean::Attribute> = i.attrs.iter().filter(|&a| match a { let mut a: Vec<clean::Attribute> = i.attrs.iter().filter(|&a| match a {
&clean::NameValue(ref x, _) if "doc" == x.as_slice() => false, &clean::NameValue(ref x, _) if "doc" == *x => false,
_ => true _ => true
}).map(|x| x.clone()).collect(); }).map(|x| x.clone()).collect();
if docstr.len() > 0 { if docstr.len() > 0 {
@ -374,14 +374,14 @@ mod unindent_tests {
fn should_unindent() { fn should_unindent() {
let s = " line1\n line2".to_string(); let s = " line1\n line2".to_string();
let r = unindent(s.as_slice()); let r = unindent(s.as_slice());
assert_eq!(r.as_slice(), "line1\nline2"); assert_eq!(r, "line1\nline2");
} }
#[test] #[test]
fn should_unindent_multiple_paragraphs() { fn should_unindent_multiple_paragraphs() {
let s = " line1\n\n line2".to_string(); let s = " line1\n\n line2".to_string();
let r = unindent(s.as_slice()); let r = unindent(s.as_slice());
assert_eq!(r.as_slice(), "line1\n\nline2"); assert_eq!(r, "line1\n\nline2");
} }
#[test] #[test]
@ -390,7 +390,7 @@ mod unindent_tests {
// base indentation and should be preserved // base indentation and should be preserved
let s = " line1\n\n line2".to_string(); let s = " line1\n\n line2".to_string();
let r = unindent(s.as_slice()); let r = unindent(s.as_slice());
assert_eq!(r.as_slice(), "line1\n\n line2"); assert_eq!(r, "line1\n\n line2");
} }
#[test] #[test]
@ -402,13 +402,13 @@ mod unindent_tests {
// and continue here"] // and continue here"]
let s = "line1\n line2".to_string(); let s = "line1\n line2".to_string();
let r = unindent(s.as_slice()); let r = unindent(s.as_slice());
assert_eq!(r.as_slice(), "line1\nline2"); assert_eq!(r, "line1\nline2");
} }
#[test] #[test]
fn should_not_ignore_first_line_indent_in_a_single_line_para() { fn should_not_ignore_first_line_indent_in_a_single_line_para() {
let s = "line1\n\n line2".to_string(); let s = "line1\n\n line2".to_string();
let r = unindent(s.as_slice()); let r = unindent(s.as_slice());
assert_eq!(r.as_slice(), "line1\n\n line2"); assert_eq!(r, "line1\n\n line2");
} }
} }

View file

@ -286,59 +286,58 @@ mod tests {
#[test] #[test]
fn test_to_base64_basic() { fn test_to_base64_basic() {
assert_eq!("".as_bytes().to_base64(STANDARD), "".to_string()); assert_eq!("".as_bytes().to_base64(STANDARD), "");
assert_eq!("f".as_bytes().to_base64(STANDARD), "Zg==".to_string()); assert_eq!("f".as_bytes().to_base64(STANDARD), "Zg==");
assert_eq!("fo".as_bytes().to_base64(STANDARD), "Zm8=".to_string()); assert_eq!("fo".as_bytes().to_base64(STANDARD), "Zm8=");
assert_eq!("foo".as_bytes().to_base64(STANDARD), "Zm9v".to_string()); assert_eq!("foo".as_bytes().to_base64(STANDARD), "Zm9v");
assert_eq!("foob".as_bytes().to_base64(STANDARD), "Zm9vYg==".to_string()); assert_eq!("foob".as_bytes().to_base64(STANDARD), "Zm9vYg==");
assert_eq!("fooba".as_bytes().to_base64(STANDARD), "Zm9vYmE=".to_string()); assert_eq!("fooba".as_bytes().to_base64(STANDARD), "Zm9vYmE=");
assert_eq!("foobar".as_bytes().to_base64(STANDARD), "Zm9vYmFy".to_string()); assert_eq!("foobar".as_bytes().to_base64(STANDARD), "Zm9vYmFy");
} }
#[test] #[test]
fn test_to_base64_line_break() { fn test_to_base64_line_break() {
assert!(![0u8, ..1000].to_base64(Config {line_length: None, ..STANDARD}) assert!(![0u8, ..1000].to_base64(Config {line_length: None, ..STANDARD})
.as_slice()
.contains("\r\n")); .contains("\r\n"));
assert_eq!("foobar".as_bytes().to_base64(Config {line_length: Some(4), assert_eq!("foobar".as_bytes().to_base64(Config {line_length: Some(4),
..STANDARD}), ..STANDARD}),
"Zm9v\r\nYmFy".to_string()); "Zm9v\r\nYmFy");
} }
#[test] #[test]
fn test_to_base64_padding() { fn test_to_base64_padding() {
assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zg".to_string()); assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zg");
assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zm8".to_string()); assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zm8");
} }
#[test] #[test]
fn test_to_base64_url_safe() { fn test_to_base64_url_safe() {
assert_eq!([251, 255].to_base64(URL_SAFE), "-_8".to_string()); assert_eq!([251, 255].to_base64(URL_SAFE), "-_8");
assert_eq!([251, 255].to_base64(STANDARD), "+/8=".to_string()); assert_eq!([251, 255].to_base64(STANDARD), "+/8=");
} }
#[test] #[test]
fn test_from_base64_basic() { fn test_from_base64_basic() {
assert_eq!("".from_base64().unwrap().as_slice(), "".as_bytes()); assert_eq!("".from_base64().unwrap(), b"");
assert_eq!("Zg==".from_base64().unwrap().as_slice(), "f".as_bytes()); assert_eq!("Zg==".from_base64().unwrap(), b"f");
assert_eq!("Zm8=".from_base64().unwrap().as_slice(), "fo".as_bytes()); assert_eq!("Zm8=".from_base64().unwrap(), b"fo");
assert_eq!("Zm9v".from_base64().unwrap().as_slice(), "foo".as_bytes()); assert_eq!("Zm9v".from_base64().unwrap(), b"foo");
assert_eq!("Zm9vYg==".from_base64().unwrap().as_slice(), "foob".as_bytes()); assert_eq!("Zm9vYg==".from_base64().unwrap(), b"foob");
assert_eq!("Zm9vYmE=".from_base64().unwrap().as_slice(), "fooba".as_bytes()); assert_eq!("Zm9vYmE=".from_base64().unwrap(), b"fooba");
assert_eq!("Zm9vYmFy".from_base64().unwrap().as_slice(), "foobar".as_bytes()); assert_eq!("Zm9vYmFy".from_base64().unwrap(), b"foobar");
} }
#[test] #[test]
fn test_from_base64_bytes() { fn test_from_base64_bytes() {
assert_eq!(b"Zm9vYmFy".from_base64().unwrap().as_slice(), "foobar".as_bytes()); assert_eq!(b"Zm9vYmFy".from_base64().unwrap(), b"foobar");
} }
#[test] #[test]
fn test_from_base64_newlines() { fn test_from_base64_newlines() {
assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap().as_slice(), assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(),
"foobar".as_bytes()); b"foobar");
assert_eq!("Zm9vYg==\r\n".from_base64().unwrap().as_slice(), assert_eq!("Zm9vYg==\r\n".from_base64().unwrap(),
"foob".as_bytes()); b"foob");
} }
#[test] #[test]
@ -364,13 +363,10 @@ mod tests {
for _ in range(0u, 1000) { for _ in range(0u, 1000) {
let times = task_rng().gen_range(1u, 100); let times = task_rng().gen_range(1u, 100);
let v = Vec::from_fn(times, |_| random::<u8>()); let v = Vec::from_fn(times, |_| random::<u8>());
assert_eq!(v.as_slice() assert_eq!(v.to_base64(STANDARD)
.to_base64(STANDARD)
.as_slice()
.from_base64() .from_base64()
.unwrap() .unwrap(),
.as_slice(), v);
v.as_slice());
} }
} }
@ -390,7 +386,7 @@ mod tests {
"; ";
let sb = s.as_bytes().to_base64(STANDARD); let sb = s.as_bytes().to_base64(STANDARD);
b.iter(|| { b.iter(|| {
sb.as_slice().from_base64().unwrap(); sb.from_base64().unwrap();
}); });
b.bytes = sb.len() as u64; b.bytes = sb.len() as u64;
} }

View file

@ -158,15 +158,15 @@ mod tests {
#[test] #[test]
pub fn test_to_hex() { pub fn test_to_hex() {
assert_eq!("foobar".as_bytes().to_hex(), "666f6f626172".to_string()); assert_eq!("foobar".as_bytes().to_hex(), "666f6f626172");
} }
#[test] #[test]
pub fn test_from_hex_okay() { pub fn test_from_hex_okay() {
assert_eq!("666f6f626172".from_hex().unwrap().as_slice(), assert_eq!("666f6f626172".from_hex().unwrap(),
"foobar".as_bytes()); b"foobar");
assert_eq!("666F6F626172".from_hex().unwrap().as_slice(), assert_eq!("666F6F626172".from_hex().unwrap(),
"foobar".as_bytes()); b"foobar");
} }
#[test] #[test]
@ -182,8 +182,8 @@ mod tests {
#[test] #[test]
pub fn test_from_hex_ignores_whitespace() { pub fn test_from_hex_ignores_whitespace() {
assert_eq!("666f 6f6\r\n26172 ".from_hex().unwrap().as_slice(), assert_eq!("666f 6f6\r\n26172 ".from_hex().unwrap(),
"foobar".as_bytes()); b"foobar");
} }
#[test] #[test]
@ -197,15 +197,11 @@ mod tests {
pub fn test_from_hex_all_bytes() { pub fn test_from_hex_all_bytes() {
for i in range(0u, 256) { for i in range(0u, 256) {
let ii: &[u8] = &[i as u8]; let ii: &[u8] = &[i as u8];
assert_eq!(format!("{:02x}", i as uint).as_slice() assert_eq!(format!("{:02x}", i as uint).from_hex()
.from_hex() .unwrap(),
.unwrap()
.as_slice(),
ii); ii);
assert_eq!(format!("{:02X}", i as uint).as_slice() assert_eq!(format!("{:02X}", i as uint).from_hex()
.from_hex() .unwrap(),
.unwrap()
.as_slice(),
ii); ii);
} }
} }
@ -226,7 +222,7 @@ mod tests {
"; ";
let sb = s.as_bytes().to_hex(); let sb = s.as_bytes().to_hex();
b.iter(|| { b.iter(|| {
sb.as_slice().from_hex().unwrap(); sb.from_hex().unwrap();
}); });
b.bytes = sb.len() as u64; b.bytes = sb.len() as u64;
} }

View file

@ -2039,7 +2039,7 @@ impl ::Decoder<DecoderError> for Decoder {
fn read_char(&mut self) -> DecodeResult<char> { fn read_char(&mut self) -> DecodeResult<char> {
let s = try!(self.read_str()); let s = try!(self.read_str());
{ {
let mut it = s.as_slice().chars(); let mut it = s.chars();
match (it.next(), it.next()) { match (it.next(), it.next()) {
// exactly one character // exactly one character
(Some(c), None) => return Ok(c), (Some(c), None) => return Ok(c),
@ -2486,76 +2486,76 @@ mod tests {
#[test] #[test]
fn test_write_null() { fn test_write_null() {
assert_eq!(Null.to_string().into_string(), "null".to_string()); assert_eq!(Null.to_string().into_string(), "null");
assert_eq!(Null.to_pretty_str().into_string(), "null".to_string()); assert_eq!(Null.to_pretty_str().into_string(), "null");
} }
#[test] #[test]
fn test_write_i64() { fn test_write_i64() {
assert_eq!(U64(0).to_string().into_string(), "0".to_string()); assert_eq!(U64(0).to_string().into_string(), "0");
assert_eq!(U64(0).to_pretty_str().into_string(), "0".to_string()); assert_eq!(U64(0).to_pretty_str().into_string(), "0");
assert_eq!(U64(1234).to_string().into_string(), "1234".to_string()); assert_eq!(U64(1234).to_string().into_string(), "1234");
assert_eq!(U64(1234).to_pretty_str().into_string(), "1234".to_string()); assert_eq!(U64(1234).to_pretty_str().into_string(), "1234");
assert_eq!(I64(-5678).to_string().into_string(), "-5678".to_string()); assert_eq!(I64(-5678).to_string().into_string(), "-5678");
assert_eq!(I64(-5678).to_pretty_str().into_string(), "-5678".to_string()); assert_eq!(I64(-5678).to_pretty_str().into_string(), "-5678");
} }
#[test] #[test]
fn test_write_f64() { fn test_write_f64() {
assert_eq!(F64(3.0).to_string().into_string(), "3".to_string()); assert_eq!(F64(3.0).to_string().into_string(), "3");
assert_eq!(F64(3.0).to_pretty_str().into_string(), "3".to_string()); assert_eq!(F64(3.0).to_pretty_str().into_string(), "3");
assert_eq!(F64(3.1).to_string().into_string(), "3.1".to_string()); assert_eq!(F64(3.1).to_string().into_string(), "3.1");
assert_eq!(F64(3.1).to_pretty_str().into_string(), "3.1".to_string()); assert_eq!(F64(3.1).to_pretty_str().into_string(), "3.1");
assert_eq!(F64(-1.5).to_string().into_string(), "-1.5".to_string()); assert_eq!(F64(-1.5).to_string().into_string(), "-1.5");
assert_eq!(F64(-1.5).to_pretty_str().into_string(), "-1.5".to_string()); assert_eq!(F64(-1.5).to_pretty_str().into_string(), "-1.5");
assert_eq!(F64(0.5).to_string().into_string(), "0.5".to_string()); assert_eq!(F64(0.5).to_string().into_string(), "0.5");
assert_eq!(F64(0.5).to_pretty_str().into_string(), "0.5".to_string()); assert_eq!(F64(0.5).to_pretty_str().into_string(), "0.5");
assert_eq!(F64(f64::NAN).to_string().into_string(), "null".to_string()); assert_eq!(F64(f64::NAN).to_string().into_string(), "null");
assert_eq!(F64(f64::NAN).to_pretty_str().into_string(), "null".to_string()); assert_eq!(F64(f64::NAN).to_pretty_str().into_string(), "null");
assert_eq!(F64(f64::INFINITY).to_string().into_string(), "null".to_string()); assert_eq!(F64(f64::INFINITY).to_string().into_string(), "null");
assert_eq!(F64(f64::INFINITY).to_pretty_str().into_string(), "null".to_string()); assert_eq!(F64(f64::INFINITY).to_pretty_str().into_string(), "null");
assert_eq!(F64(f64::NEG_INFINITY).to_string().into_string(), "null".to_string()); assert_eq!(F64(f64::NEG_INFINITY).to_string().into_string(), "null");
assert_eq!(F64(f64::NEG_INFINITY).to_pretty_str().into_string(), "null".to_string()); assert_eq!(F64(f64::NEG_INFINITY).to_pretty_str().into_string(), "null");
} }
#[test] #[test]
fn test_write_str() { fn test_write_str() {
assert_eq!(String("".to_string()).to_string().into_string(), "\"\"".to_string()); assert_eq!(String("".to_string()).to_string().into_string(), "\"\"");
assert_eq!(String("".to_string()).to_pretty_str().into_string(), "\"\"".to_string()); assert_eq!(String("".to_string()).to_pretty_str().into_string(), "\"\"");
assert_eq!(String("foo".to_string()).to_string().into_string(), "\"foo\"".to_string()); assert_eq!(String("foo".to_string()).to_string().into_string(), "\"foo\"");
assert_eq!(String("foo".to_string()).to_pretty_str().into_string(), "\"foo\"".to_string()); assert_eq!(String("foo".to_string()).to_pretty_str().into_string(), "\"foo\"");
} }
#[test] #[test]
fn test_write_bool() { fn test_write_bool() {
assert_eq!(Boolean(true).to_string().into_string(), "true".to_string()); assert_eq!(Boolean(true).to_string().into_string(), "true");
assert_eq!(Boolean(true).to_pretty_str().into_string(), "true".to_string()); assert_eq!(Boolean(true).to_pretty_str().into_string(), "true");
assert_eq!(Boolean(false).to_string().into_string(), "false".to_string()); assert_eq!(Boolean(false).to_string().into_string(), "false");
assert_eq!(Boolean(false).to_pretty_str().into_string(), "false".to_string()); assert_eq!(Boolean(false).to_pretty_str().into_string(), "false");
} }
#[test] #[test]
fn test_write_array() { fn test_write_array() {
assert_eq!(Array(vec![]).to_string().into_string(), "[]".to_string()); assert_eq!(Array(vec![]).to_string().into_string(), "[]");
assert_eq!(Array(vec![]).to_pretty_str().into_string(), "[]".to_string()); assert_eq!(Array(vec![]).to_pretty_str().into_string(), "[]");
assert_eq!(Array(vec![Boolean(true)]).to_string().into_string(), "[true]".to_string()); assert_eq!(Array(vec![Boolean(true)]).to_string().into_string(), "[true]");
assert_eq!( assert_eq!(
Array(vec![Boolean(true)]).to_pretty_str().into_string(), Array(vec![Boolean(true)]).to_pretty_str().into_string(),
"\ "\
[\n \ [\n \
true\n\ true\n\
]".to_string() ]"
); );
let long_test_array = Array(vec![ let long_test_array = Array(vec![
@ -2564,7 +2564,7 @@ mod tests {
Array(vec![String("foo\nbar".to_string()), F64(3.5)])]); Array(vec![String("foo\nbar".to_string()), F64(3.5)])]);
assert_eq!(long_test_array.to_string().into_string(), assert_eq!(long_test_array.to_string().into_string(),
"[false,null,[\"foo\\nbar\",3.5]]".to_string()); "[false,null,[\"foo\\nbar\",3.5]]");
assert_eq!( assert_eq!(
long_test_array.to_pretty_str().into_string(), long_test_array.to_pretty_str().into_string(),
"\ "\
@ -2575,27 +2575,27 @@ mod tests {
\"foo\\nbar\",\n \ \"foo\\nbar\",\n \
3.5\n \ 3.5\n \
]\n\ ]\n\
]".to_string() ]"
); );
} }
#[test] #[test]
fn test_write_object() { fn test_write_object() {
assert_eq!(mk_object(&[]).to_string().into_string(), "{}".to_string()); assert_eq!(mk_object(&[]).to_string().into_string(), "{}");
assert_eq!(mk_object(&[]).to_pretty_str().into_string(), "{}".to_string()); assert_eq!(mk_object(&[]).to_pretty_str().into_string(), "{}");
assert_eq!( assert_eq!(
mk_object(&[ mk_object(&[
("a".to_string(), Boolean(true)) ("a".to_string(), Boolean(true))
]).to_string().into_string(), ]).to_string().into_string(),
"{\"a\":true}".to_string() "{\"a\":true}"
); );
assert_eq!( assert_eq!(
mk_object(&[("a".to_string(), Boolean(true))]).to_pretty_str(), mk_object(&[("a".to_string(), Boolean(true))]).to_pretty_str(),
"\ "\
{\n \ {\n \
\"a\": true\n\ \"a\": true\n\
}".to_string() }"
); );
let complex_obj = mk_object(&[ let complex_obj = mk_object(&[
@ -2612,7 +2612,7 @@ mod tests {
{\"c\":\"\\f\\r\"},\ {\"c\":\"\\f\\r\"},\
{\"d\":\"\"}\ {\"d\":\"\"}\
]\ ]\
}".to_string() }"
); );
assert_eq!( assert_eq!(
complex_obj.to_pretty_str().into_string(), complex_obj.to_pretty_str().into_string(),
@ -2626,7 +2626,7 @@ mod tests {
\"d\": \"\"\n \ \"d\": \"\"\n \
}\n \ }\n \
]\n\ ]\n\
}".to_string() }"
); );
let a = mk_object(&[ let a = mk_object(&[
@ -2660,14 +2660,14 @@ mod tests {
let mut encoder = Encoder::new(writer); let mut encoder = Encoder::new(writer);
animal.encode(&mut encoder).unwrap(); animal.encode(&mut encoder).unwrap();
}), }),
"\"Dog\"".to_string() "\"Dog\""
); );
assert_eq!( assert_eq!(
with_str_writer(|writer| { with_str_writer(|writer| {
let mut encoder = PrettyEncoder::new(writer); let mut encoder = PrettyEncoder::new(writer);
animal.encode(&mut encoder).unwrap(); animal.encode(&mut encoder).unwrap();
}), }),
"\"Dog\"".to_string() "\"Dog\""
); );
let animal = Frog("Henry".to_string(), 349); let animal = Frog("Henry".to_string(), 349);
@ -2676,7 +2676,7 @@ mod tests {
let mut encoder = Encoder::new(writer); let mut encoder = Encoder::new(writer);
animal.encode(&mut encoder).unwrap(); animal.encode(&mut encoder).unwrap();
}), }),
"{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}".to_string() "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}"
); );
assert_eq!( assert_eq!(
with_str_writer(|writer| { with_str_writer(|writer| {
@ -2689,7 +2689,7 @@ mod tests {
\"Henry\",\n \ \"Henry\",\n \
349\n \ 349\n \
]\n\ ]\n\
}".to_string() }"
); );
} }
@ -2700,14 +2700,14 @@ mod tests {
let mut encoder = Encoder::new(writer); let mut encoder = Encoder::new(writer);
value.encode(&mut encoder).unwrap(); value.encode(&mut encoder).unwrap();
}); });
assert_eq!(s, "\"jodhpurs\"".to_string()); assert_eq!(s, "\"jodhpurs\"");
let value = Some("jodhpurs".to_string()); let value = Some("jodhpurs".to_string());
let s = with_str_writer(|writer| { let s = with_str_writer(|writer| {
let mut encoder = PrettyEncoder::new(writer); let mut encoder = PrettyEncoder::new(writer);
value.encode(&mut encoder).unwrap(); value.encode(&mut encoder).unwrap();
}); });
assert_eq!(s, "\"jodhpurs\"".to_string()); assert_eq!(s, "\"jodhpurs\"");
} }
#[test] #[test]
@ -2717,13 +2717,13 @@ mod tests {
let mut encoder = Encoder::new(writer); let mut encoder = Encoder::new(writer);
value.encode(&mut encoder).unwrap(); value.encode(&mut encoder).unwrap();
}); });
assert_eq!(s, "null".to_string()); assert_eq!(s, "null");
let s = with_str_writer(|writer| { let s = with_str_writer(|writer| {
let mut encoder = Encoder::new(writer); let mut encoder = Encoder::new(writer);
value.encode(&mut encoder).unwrap(); value.encode(&mut encoder).unwrap();
}); });
assert_eq!(s, "null".to_string()); assert_eq!(s, "null");
} }
#[test] #[test]
@ -2860,7 +2860,7 @@ mod tests {
for &(i, o) in s.iter() { for &(i, o) in s.iter() {
let v: string::String = super::decode(i).unwrap(); let v: string::String = super::decode(i).unwrap();
assert_eq!(v.as_slice(), o); assert_eq!(v, o);
} }
} }
@ -3778,7 +3778,7 @@ mod tests {
fn bench_streaming_large(b: &mut Bencher) { fn bench_streaming_large(b: &mut Bencher) {
let src = big_json(); let src = big_json();
b.iter( || { b.iter( || {
let mut parser = Parser::new(src.as_slice().chars()); let mut parser = Parser::new(src.chars());
loop { loop {
match parser.next() { match parser.next() {
None => return, None => return,

View file

@ -678,16 +678,16 @@ mod tests {
assert_eq!(test.to_ascii(), b); assert_eq!(test.to_ascii(), b);
assert_eq!("( ;".to_ascii(), b); assert_eq!("( ;".to_ascii(), b);
let v = vec![40u8, 32u8, 59u8]; let v = vec![40u8, 32u8, 59u8];
assert_eq!(v.as_slice().to_ascii(), b); assert_eq!(v.to_ascii(), b);
assert_eq!("( ;".to_string().as_slice().to_ascii(), b); assert_eq!("( ;".to_string().to_ascii(), b);
assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string()); assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#");
assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string()); assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#");
assert_eq!("".to_ascii().to_lowercase().into_string(), "".to_string()); assert_eq!("".to_ascii().to_lowercase().into_string(), "");
assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca".to_string()); assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca");
let mixed = "abcDEFxyz:.;".to_ascii(); let mixed = "abcDEFxyz:.;".to_ascii();
assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;".to_string()); assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;");
assert!("aBcDeF&?#".to_ascii().eq_ignore_case("AbCdEf&?#".to_ascii())); assert!("aBcDeF&?#".to_ascii().eq_ignore_case("AbCdEf&?#".to_ascii()));
@ -699,12 +699,12 @@ mod tests {
#[test] #[test]
fn test_ascii_vec_ng() { fn test_ascii_vec_ng() {
assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string()); assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#");
assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string()); assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#");
assert_eq!("".to_ascii().to_lowercase().into_string(), "".to_string()); assert_eq!("".to_ascii().to_lowercase().into_string(), "");
assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca".to_string()); assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca");
let mixed = "abcDEFxyz:.;".to_ascii(); let mixed = "abcDEFxyz:.;".to_ascii();
assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;".to_string()); assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;");
} }
#[test] #[test]
@ -721,8 +721,8 @@ mod tests {
#[test] #[test]
fn test_ascii_into_string() { fn test_ascii_into_string() {
assert_eq!(vec2ascii![40, 32, 59].into_string(), "( ;".to_string()); assert_eq!(vec2ascii![40, 32, 59].into_string(), "( ;");
assert_eq!(vec2ascii!(40, 32, 59).into_string(), "( ;".to_string()); assert_eq!(vec2ascii!(40, 32, 59).into_string(), "( ;");
} }
#[test] #[test]
@ -774,14 +774,14 @@ mod tests {
#[test] #[test]
fn test_to_ascii_upper() { fn test_to_ascii_upper() {
assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL".to_string()); assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL");
assert_eq!("hıß".to_ascii_upper(), "Hıß".to_string()); assert_eq!("hıß".to_ascii_upper(), "Hıß");
let mut i = 0; let mut i = 0;
while i <= 500 { while i <= 500 {
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 } let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
else { i }; else { i };
assert_eq!((from_u32(i).unwrap()).to_string().as_slice().to_ascii_upper(), assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_upper(),
(from_u32(upper).unwrap()).to_string()) (from_u32(upper).unwrap()).to_string())
i += 1; i += 1;
} }
@ -789,15 +789,15 @@ mod tests {
#[test] #[test]
fn test_to_ascii_lower() { fn test_to_ascii_lower() {
assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl".to_string()); assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl");
// Dotted capital I, Kelvin sign, Sharp S. // Dotted capital I, Kelvin sign, Sharp S.
assert_eq!("ß".to_ascii_lower(), "ß".to_string()); assert_eq!("ß".to_ascii_lower(), "ß");
let mut i = 0; let mut i = 0;
while i <= 500 { while i <= 500 {
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
else { i }; else { i };
assert_eq!((from_u32(i).unwrap()).to_string().as_slice().to_ascii_lower(), assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_lower(),
(from_u32(lower).unwrap()).to_string()) (from_u32(lower).unwrap()).to_string())
i += 1; i += 1;
} }
@ -807,7 +807,7 @@ mod tests {
fn test_into_ascii_upper() { fn test_into_ascii_upper() {
assert_eq!(("url()URL()uRl()ürl".to_string()).into_ascii_upper(), assert_eq!(("url()URL()uRl()ürl".to_string()).into_ascii_upper(),
"URL()URL()URL()üRL".to_string()); "URL()URL()URL()üRL".to_string());
assert_eq!(("hıß".to_string()).into_ascii_upper(), "Hıß".to_string()); assert_eq!(("hıß".to_string()).into_ascii_upper(), "Hıß");
let mut i = 0; let mut i = 0;
while i <= 500 { while i <= 500 {
@ -822,9 +822,9 @@ mod tests {
#[test] #[test]
fn test_into_ascii_lower() { fn test_into_ascii_lower() {
assert_eq!(("url()URL()uRl()Ürl".to_string()).into_ascii_lower(), assert_eq!(("url()URL()uRl()Ürl".to_string()).into_ascii_lower(),
"url()url()url()Ürl".to_string()); "url()url()url()Ürl");
// Dotted capital I, Kelvin sign, Sharp S. // Dotted capital I, Kelvin sign, Sharp S.
assert_eq!(("ß".to_string()).into_ascii_lower(), "ß".to_string()); assert_eq!(("ß".to_string()).into_ascii_lower(), "ß");
let mut i = 0; let mut i = 0;
while i <= 500 { while i <= 500 {
@ -851,7 +851,7 @@ mod tests {
let c = i; let c = i;
let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 } let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 }
else { c }; else { c };
assert!((from_u32(i).unwrap()).to_string().as_slice().eq_ignore_ascii_case( assert!((from_u32(i).unwrap()).to_string().eq_ignore_ascii_case(
(from_u32(lower).unwrap()).to_string().as_slice())); (from_u32(lower).unwrap()).to_string().as_slice()));
i += 1; i += 1;
} }
@ -860,12 +860,12 @@ mod tests {
#[test] #[test]
fn test_to_string() { fn test_to_string() {
let s = Ascii{ chr: b't' }.to_string(); let s = Ascii{ chr: b't' }.to_string();
assert_eq!(s, "t".to_string()); assert_eq!(s, "t");
} }
#[test] #[test]
fn test_show() { fn test_show() {
let c = Ascii { chr: b't' }; let c = Ascii { chr: b't' };
assert_eq!(format!("{}", c), "t".to_string()); assert_eq!(format!("{}", c), "t");
} }
} }

View file

@ -1548,7 +1548,7 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { for i in range(0u, 200) {
assert_eq!(v.borrow().as_slice()[i], 0); assert_eq!(v.borrow()[i], 0);
} }
}); });
@ -1560,7 +1560,7 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { for i in range(0u, 200) {
assert_eq!(v.borrow().as_slice()[i], 1); assert_eq!(v.borrow()[i], 1);
} }
}); });
@ -1571,27 +1571,27 @@ mod test_map {
assert!(v.is_some()); assert!(v.is_some());
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
assert_eq!(v.borrow().as_slice()[i], 1); assert_eq!(v.borrow()[i], 1);
assert_eq!(v.borrow().as_slice()[i+100], 1); assert_eq!(v.borrow()[i+100], 1);
}); });
} }
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 50) { for i in range(0u, 50) {
assert_eq!(v.borrow().as_slice()[i], 0); assert_eq!(v.borrow()[i], 0);
assert_eq!(v.borrow().as_slice()[i+100], 0); assert_eq!(v.borrow()[i+100], 0);
} }
for i in range(50u, 100) { for i in range(50u, 100) {
assert_eq!(v.borrow().as_slice()[i], 1); assert_eq!(v.borrow()[i], 1);
assert_eq!(v.borrow().as_slice()[i+100], 1); assert_eq!(v.borrow()[i+100], 1);
} }
}); });
} }
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { for i in range(0u, 200) {
assert_eq!(v.borrow().as_slice()[i], 0); assert_eq!(v.borrow()[i], 0);
} }
}); });
} }
@ -1607,7 +1607,7 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { for i in range(0u, 200) {
assert_eq!(v.borrow().as_slice()[i], 0); assert_eq!(v.borrow()[i], 0);
} }
}); });
@ -1619,7 +1619,7 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { for i in range(0u, 200) {
assert_eq!(v.borrow().as_slice()[i], 1); assert_eq!(v.borrow()[i], 1);
} }
}); });
@ -1634,7 +1634,7 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { for i in range(0u, 200) {
assert_eq!(v.borrow().as_slice()[i], 1); assert_eq!(v.borrow()[i], 1);
} }
}); });
@ -1642,11 +1642,11 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
let nk = range(0u, 100).filter(|&i| { let nk = range(0u, 100).filter(|&i| {
v.borrow().as_slice()[i] == 1 v.borrow()[i] == 1
}).count(); }).count();
let nv = range(0u, 100).filter(|&i| { let nv = range(0u, 100).filter(|&i| {
v.borrow().as_slice()[i+100] == 1 v.borrow()[i+100] == 1
}).count(); }).count();
assert_eq!(nk, 50); assert_eq!(nk, 50);
@ -1656,7 +1656,7 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { for i in range(0u, 200) {
assert_eq!(v.borrow().as_slice()[i], 0); assert_eq!(v.borrow()[i], 0);
} }
}); });
} }
@ -1905,8 +1905,8 @@ mod test_map {
let map_str = format!("{}", map); let map_str = format!("{}", map);
assert!(map_str == "{1: 2, 3: 4}".to_string() || map_str == "{3: 4, 1: 2}".to_string()); assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
assert_eq!(format!("{}", empty), "{}".to_string()); assert_eq!(format!("{}", empty), "{}");
} }
#[test] #[test]

View file

@ -827,7 +827,7 @@ mod test_set {
}; };
let v = hs.into_iter().collect::<Vec<char>>(); let v = hs.into_iter().collect::<Vec<char>>();
assert!(['a', 'b'][] == v.as_slice() || ['b', 'a'][] == v.as_slice()); assert!(['a', 'b'] == v || ['b', 'a'] == v);
} }
#[test] #[test]
@ -862,7 +862,7 @@ mod test_set {
let set_str = format!("{}", set); let set_str = format!("{}", set);
assert!(set_str == "{1, 2}".to_string() || set_str == "{2, 1}".to_string()); assert!(set_str == "{1, 2}" || set_str == "{2, 1}");
assert_eq!(format!("{}", empty), "{}".to_string()); assert_eq!(format!("{}", empty), "{}");
} }
} }

View file

@ -447,15 +447,15 @@ mod tests {
cache.insert(1, 10); cache.insert(1, 10);
cache.insert(2, 20); cache.insert(2, 20);
cache.insert(3, 30); cache.insert(3, 30);
assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}".to_string()); assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}");
cache.insert(2, 22); cache.insert(2, 22);
assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}".to_string()); assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}");
cache.insert(6, 60); cache.insert(6, 60);
assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}".to_string()); assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}");
cache.get(&3); cache.get(&3);
assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}".to_string()); assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}");
cache.set_capacity(2); cache.set_capacity(2);
assert_eq!(cache.to_string(), "{3: 30, 6: 60}".to_string()); assert_eq!(cache.to_string(), "{3: 30, 6: 60}");
} }
#[test] #[test]
@ -466,6 +466,6 @@ mod tests {
cache.clear(); cache.clear();
assert!(cache.get(&1).is_none()); assert!(cache.get(&1).is_none());
assert!(cache.get(&2).is_none()); assert!(cache.get(&2).is_none());
assert_eq!(cache.to_string(), "{}".to_string()); assert_eq!(cache.to_string(), "{}");
} }
} }

View file

@ -450,30 +450,30 @@ mod test {
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(3), nread); assert_eq!(Ok(3), nread);
let b: &[_] = &[5, 6, 7]; let b: &[_] = &[5, 6, 7];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0, 0]; let mut buf = [0, 0];
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(2), nread); assert_eq!(Ok(2), nread);
let b: &[_] = &[0, 1]; let b: &[_] = &[0, 1];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0]; let mut buf = [0];
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(1), nread); assert_eq!(Ok(1), nread);
let b: &[_] = &[2]; let b: &[_] = &[2];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0, 0, 0]; let mut buf = [0, 0, 0];
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(1), nread); assert_eq!(Ok(1), nread);
let b: &[_] = &[3, 0, 0]; let b: &[_] = &[3, 0, 0];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(1), nread); assert_eq!(Ok(1), nread);
let b: &[_] = &[4, 0, 0]; let b: &[_] = &[4, 0, 0];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert!(reader.read(&mut buf).is_err()); assert!(reader.read(&mut buf).is_err());
} }

View file

@ -176,28 +176,28 @@ mod test {
assert_eq!(Ok(3), reader.read(&mut buf)); assert_eq!(Ok(3), reader.read(&mut buf));
let a: &[u8] = &[1,2,3]; let a: &[u8] = &[1,2,3];
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
assert_eq!(Ok(3), reader.read(&mut buf)); assert_eq!(Ok(3), reader.read(&mut buf));
let a: &[u8] = &[4,5,6]; let a: &[u8] = &[4,5,6];
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
assert_eq!(Ok(2), reader.read(&mut buf)); assert_eq!(Ok(2), reader.read(&mut buf));
let a: &[u8] = &[7,8,6]; let a: &[u8] = &[7,8,6];
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
match reader.read(buf.as_mut_slice()) { match reader.read(buf.as_mut_slice()) {
Ok(..) => panic!(), Ok(..) => panic!(),
Err(e) => assert_eq!(e.kind, io::EndOfFile), Err(e) => assert_eq!(e.kind, io::EndOfFile),
} }
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
// Ensure it continues to panic in the same way. // Ensure it continues to panic in the same way.
match reader.read(buf.as_mut_slice()) { match reader.read(buf.as_mut_slice()) {
Ok(..) => panic!(), Ok(..) => panic!(),
Err(e) => assert_eq!(e.kind, io::EndOfFile), Err(e) => assert_eq!(e.kind, io::EndOfFile),
} }
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
} }
#[test] #[test]

View file

@ -838,7 +838,7 @@ mod test {
macro_rules! error( ($e:expr, $s:expr) => ( macro_rules! error( ($e:expr, $s:expr) => (
match $e { match $e {
Ok(_) => panic!("Unexpected success. Should've been: {}", $s), Ok(_) => panic!("Unexpected success. Should've been: {}", $s),
Err(ref err) => assert!(err.to_string().as_slice().contains($s.as_slice()), Err(ref err) => assert!(err.to_string().contains($s.as_slice()),
format!("`{}` did not contain `{}`", err, $s)) format!("`{}` did not contain `{}`", err, $s))
} }
) ) ) )
@ -996,7 +996,7 @@ mod test {
} }
check!(unlink(filename)); check!(unlink(filename));
let read_str = str::from_utf8(&read_mem).unwrap(); let read_str = str::from_utf8(&read_mem).unwrap();
assert!(read_str.as_slice() == final_msg.as_slice()); assert!(read_str == final_msg);
} }
#[test] #[test]
@ -1104,7 +1104,7 @@ mod test {
let f = dir.join(format!("{}.txt", n)); let f = dir.join(format!("{}.txt", n));
let mut w = check!(File::create(&f)); let mut w = check!(File::create(&f));
let msg_str = format!("{}{}", prefix, n.to_string()); let msg_str = format!("{}{}", prefix, n.to_string());
let msg = msg_str.as_slice().as_bytes(); let msg = msg_str.as_bytes();
check!(w.write(msg)); check!(w.write(msg));
} }
let files = check!(readdir(dir)); let files = check!(readdir(dir));

View file

@ -444,7 +444,7 @@ mod test {
assert_eq!(writer.write(&[10]).unwrap_err().kind, io::EndOfFile); assert_eq!(writer.write(&[10]).unwrap_err().kind, io::EndOfFile);
} }
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
} }
#[test] #[test]
@ -473,7 +473,7 @@ mod test {
} }
let b: &[_] = &[1, 3, 2, 0, 0, 0, 0, 4]; let b: &[_] = &[1, 3, 2, 0, 0, 0, 0, 4];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
} }
#[test] #[test]
@ -498,12 +498,12 @@ mod test {
assert_eq!(reader.read(&mut buf), Ok(1)); assert_eq!(reader.read(&mut buf), Ok(1));
assert_eq!(reader.tell(), Ok(1)); assert_eq!(reader.tell(), Ok(1));
let b: &[_] = &[0]; let b: &[_] = &[0];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0, ..4]; let mut buf = [0, ..4];
assert_eq!(reader.read(&mut buf), Ok(4)); assert_eq!(reader.read(&mut buf), Ok(4));
assert_eq!(reader.tell(), Ok(5)); assert_eq!(reader.tell(), Ok(5));
let b: &[_] = &[1, 2, 3, 4]; let b: &[_] = &[1, 2, 3, 4];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert_eq!(reader.read(&mut buf), Ok(3)); assert_eq!(reader.read(&mut buf), Ok(3));
let b: &[_] = &[5, 6, 7]; let b: &[_] = &[5, 6, 7];
assert_eq!(buf[0..3], b); assert_eq!(buf[0..3], b);
@ -551,12 +551,12 @@ mod test {
assert_eq!(reader.read(&mut buf), Ok(1)); assert_eq!(reader.read(&mut buf), Ok(1));
assert_eq!(reader.tell(), Ok(1)); assert_eq!(reader.tell(), Ok(1));
let b: &[_] = &[0]; let b: &[_] = &[0];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0, ..4]; let mut buf = [0, ..4];
assert_eq!(reader.read(&mut buf), Ok(4)); assert_eq!(reader.read(&mut buf), Ok(4));
assert_eq!(reader.tell(), Ok(5)); assert_eq!(reader.tell(), Ok(5));
let b: &[_] = &[1, 2, 3, 4]; let b: &[_] = &[1, 2, 3, 4];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert_eq!(reader.read(&mut buf), Ok(3)); assert_eq!(reader.read(&mut buf), Ok(3));
let b: &[_] = &[5, 6, 7]; let b: &[_] = &[5, 6, 7];
assert_eq!(buf[0..3], b); assert_eq!(buf[0..3], b);
@ -592,7 +592,7 @@ mod test {
writer.write_line("testing").unwrap(); writer.write_line("testing").unwrap();
writer.write_str("testing").unwrap(); writer.write_str("testing").unwrap();
let mut r = BufReader::new(writer.get_ref()); let mut r = BufReader::new(writer.get_ref());
assert_eq!(r.read_to_string().unwrap(), "testingtesting\ntesting".to_string()); assert_eq!(r.read_to_string().unwrap(), "testingtesting\ntesting");
} }
#[test] #[test]
@ -602,7 +602,7 @@ mod test {
writer.write_char('\n').unwrap(); writer.write_char('\n').unwrap();
writer.write_char('ệ').unwrap(); writer.write_char('ệ').unwrap();
let mut r = BufReader::new(writer.get_ref()); let mut r = BufReader::new(writer.get_ref());
assert_eq!(r.read_to_string().unwrap(), "a\n".to_string()); assert_eq!(r.read_to_string().unwrap(), "a\n");
} }
#[test] #[test]
@ -652,15 +652,15 @@ mod test {
let mut buf = [0, ..3]; let mut buf = [0, ..3];
assert!(r.read_at_least(buf.len(), &mut buf).is_ok()); assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
let b: &[_] = &[1, 2, 3]; let b: &[_] = &[1, 2, 3];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert!(r.read_at_least(0, buf[mut ..0]).is_ok()); assert!(r.read_at_least(0, buf[mut ..0]).is_ok());
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert!(r.read_at_least(buf.len(), &mut buf).is_ok()); assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
let b: &[_] = &[4, 5, 6]; let b: &[_] = &[4, 5, 6];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert!(r.read_at_least(buf.len(), &mut buf).is_err()); assert!(r.read_at_least(buf.len(), &mut buf).is_err());
let b: &[_] = &[7, 8, 6]; let b: &[_] = &[7, 8, 6];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
} }
fn do_bench_mem_writer(b: &mut Bencher, times: uint, len: uint) { fn do_bench_mem_writer(b: &mut Bencher, times: uint, len: uint) {
@ -757,7 +757,7 @@ mod test {
for _i in range(0u, 10) { for _i in range(0u, 10) {
let mut buf = [0 as u8, .. 10]; let mut buf = [0 as u8, .. 10];
rdr.read(&mut buf).unwrap(); rdr.read(&mut buf).unwrap();
assert_eq!(buf.as_slice(), [5, .. 10].as_slice()); assert_eq!(buf, [5, .. 10]);
} }
} }
}); });

View file

@ -240,8 +240,8 @@ use boxed::Box;
use result::Result; use result::Result;
use result::Result::{Ok, Err}; use result::Result::{Ok, Err};
use sys; use sys;
use slice::{AsSlice, SlicePrelude}; use slice::SlicePrelude;
use str::{Str, StrPrelude}; use str::StrPrelude;
use str; use str;
use string::String; use string::String;
use uint; use uint;
@ -318,7 +318,7 @@ impl IoError {
pub fn from_errno(errno: uint, detail: bool) -> IoError { pub fn from_errno(errno: uint, detail: bool) -> IoError {
let mut err = sys::decode_error(errno as i32); let mut err = sys::decode_error(errno as i32);
if detail && err.kind == OtherIoError { if detail && err.kind == OtherIoError {
err.detail = Some(os::error_string(errno).as_slice().chars() err.detail = Some(os::error_string(errno).chars()
.map(|c| c.to_lowercase()).collect()) .map(|c| c.to_lowercase()).collect())
} }
err err
@ -2007,14 +2007,14 @@ mod tests {
fn test_show() { fn test_show() {
use super::*; use super::*;
assert_eq!(format!("{}", USER_READ), "0400".to_string()); assert_eq!(format!("{}", USER_READ), "0400");
assert_eq!(format!("{}", USER_FILE), "0644".to_string()); assert_eq!(format!("{}", USER_FILE), "0644");
assert_eq!(format!("{}", USER_EXEC), "0755".to_string()); assert_eq!(format!("{}", USER_EXEC), "0755");
assert_eq!(format!("{}", USER_RWX), "0700".to_string()); assert_eq!(format!("{}", USER_RWX), "0700");
assert_eq!(format!("{}", GROUP_RWX), "0070".to_string()); assert_eq!(format!("{}", GROUP_RWX), "0070");
assert_eq!(format!("{}", OTHER_RWX), "0007".to_string()); assert_eq!(format!("{}", OTHER_RWX), "0007");
assert_eq!(format!("{}", ALL_PERMISSIONS), "0777".to_string()); assert_eq!(format!("{}", ALL_PERMISSIONS), "0777");
assert_eq!(format!("{}", USER_READ | USER_WRITE | OTHER_WRITE), "0602".to_string()); assert_eq!(format!("{}", USER_READ | USER_WRITE | OTHER_WRITE), "0602");
} }
fn _ensure_buffer_is_object_safe<T: Buffer>(x: &T) -> &Buffer { fn _ensure_buffer_is_object_safe<T: Buffer>(x: &T) -> &Buffer {

View file

@ -641,10 +641,10 @@ mod test {
#[test] #[test]
fn ipv6_addr_to_string() { fn ipv6_addr_to_string() {
let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280); let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280);
assert!(a1.to_string() == "::ffff:192.0.2.128".to_string() || assert!(a1.to_string() == "::ffff:192.0.2.128" ||
a1.to_string() == "::FFFF:192.0.2.128".to_string()); a1.to_string() == "::FFFF:192.0.2.128");
assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_string(), assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_string(),
"8:9:a:b:c:d:e:f".to_string()); "8:9:a:b:c:d:e:f");
} }
#[test] #[test]

View file

@ -236,8 +236,8 @@ impl Command {
// if the env is currently just inheriting from the parent's, // if the env is currently just inheriting from the parent's,
// materialize the parent's env into a hashtable. // materialize the parent's env into a hashtable.
self.env = Some(os::env_as_bytes().into_iter() self.env = Some(os::env_as_bytes().into_iter()
.map(|(k, v)| (EnvKey(k.as_slice().to_c_str()), .map(|(k, v)| (EnvKey(k.to_c_str()),
v.as_slice().to_c_str())) v.to_c_str()))
.collect()); .collect());
self.env.as_mut().unwrap() self.env.as_mut().unwrap()
} }
@ -810,7 +810,7 @@ mod tests {
fn stdout_works() { fn stdout_works() {
let mut cmd = Command::new("echo"); let mut cmd = Command::new("echo");
cmd.arg("foobar").stdout(CreatePipe(false, true)); cmd.arg("foobar").stdout(CreatePipe(false, true));
assert_eq!(run_output(cmd), "foobar\n".to_string()); assert_eq!(run_output(cmd), "foobar\n");
} }
#[cfg(all(unix, not(target_os="android")))] #[cfg(all(unix, not(target_os="android")))]
@ -820,7 +820,7 @@ mod tests {
cmd.arg("-c").arg("pwd") cmd.arg("-c").arg("pwd")
.cwd(&Path::new("/")) .cwd(&Path::new("/"))
.stdout(CreatePipe(false, true)); .stdout(CreatePipe(false, true));
assert_eq!(run_output(cmd), "/\n".to_string()); assert_eq!(run_output(cmd), "/\n");
} }
#[cfg(all(unix, not(target_os="android")))] #[cfg(all(unix, not(target_os="android")))]
@ -835,7 +835,7 @@ mod tests {
drop(p.stdin.take()); drop(p.stdin.take());
let out = read_all(p.stdout.as_mut().unwrap() as &mut Reader); let out = read_all(p.stdout.as_mut().unwrap() as &mut Reader);
assert!(p.wait().unwrap().success()); assert!(p.wait().unwrap().success());
assert_eq!(out, "foobar\n".to_string()); assert_eq!(out, "foobar\n");
} }
#[cfg(not(target_os="android"))] #[cfg(not(target_os="android"))]
@ -900,7 +900,7 @@ mod tests {
let output_str = str::from_utf8(output.as_slice()).unwrap(); let output_str = str::from_utf8(output.as_slice()).unwrap();
assert!(status.success()); assert!(status.success());
assert_eq!(output_str.trim().to_string(), "hello".to_string()); assert_eq!(output_str.trim().to_string(), "hello");
// FIXME #7224 // FIXME #7224
if !running_on_valgrind() { if !running_on_valgrind() {
assert_eq!(error, Vec::new()); assert_eq!(error, Vec::new());
@ -941,7 +941,7 @@ mod tests {
let output_str = str::from_utf8(output.as_slice()).unwrap(); let output_str = str::from_utf8(output.as_slice()).unwrap();
assert!(status.success()); assert!(status.success());
assert_eq!(output_str.trim().to_string(), "hello".to_string()); assert_eq!(output_str.trim().to_string(), "hello");
// FIXME #7224 // FIXME #7224
if !running_on_valgrind() { if !running_on_valgrind() {
assert_eq!(error, Vec::new()); assert_eq!(error, Vec::new());
@ -973,7 +973,7 @@ mod tests {
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap(); let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
let parent_dir = os::getcwd().unwrap(); let parent_dir = os::getcwd().unwrap();
let child_dir = Path::new(output.as_slice().trim()); let child_dir = Path::new(output.trim());
let parent_stat = parent_dir.stat().unwrap(); let parent_stat = parent_dir.stat().unwrap();
let child_stat = child_dir.stat().unwrap(); let child_stat = child_dir.stat().unwrap();
@ -991,7 +991,7 @@ mod tests {
let prog = pwd_cmd().cwd(&parent_dir).spawn().unwrap(); let prog = pwd_cmd().cwd(&parent_dir).spawn().unwrap();
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap(); let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
let child_dir = Path::new(output.as_slice().trim()); let child_dir = Path::new(output.trim());
let parent_stat = parent_dir.stat().unwrap(); let parent_stat = parent_dir.stat().unwrap();
let child_stat = child_dir.stat().unwrap(); let child_stat = child_dir.stat().unwrap();
@ -1031,8 +1031,7 @@ mod tests {
for &(ref k, ref v) in r.iter() { for &(ref k, ref v) in r.iter() {
// don't check windows magical empty-named variables // don't check windows magical empty-named variables
assert!(k.is_empty() || assert!(k.is_empty() ||
output.as_slice() output.contains(format!("{}={}", *k, *v).as_slice()),
.contains(format!("{}={}", *k, *v).as_slice()),
"output doesn't contain `{}={}`\n{}", "output doesn't contain `{}={}`\n{}",
k, v, output); k, v, output);
} }
@ -1050,12 +1049,10 @@ mod tests {
for &(ref k, ref v) in r.iter() { for &(ref k, ref v) in r.iter() {
// don't check android RANDOM variables // don't check android RANDOM variables
if *k != "RANDOM".to_string() { if *k != "RANDOM".to_string() {
assert!(output.as_slice() assert!(output.contains(format!("{}={}",
.contains(format!("{}={}",
*k, *k,
*v).as_slice()) || *v).as_slice()) ||
output.as_slice() output.contains(format!("{}=\'{}\'",
.contains(format!("{}=\'{}\'",
*k, *k,
*v).as_slice())); *v).as_slice()));
} }
@ -1084,7 +1081,7 @@ mod tests {
let result = prog.wait_with_output().unwrap(); let result = prog.wait_with_output().unwrap();
let output = String::from_utf8_lossy(result.output.as_slice()).into_string(); let output = String::from_utf8_lossy(result.output.as_slice()).into_string();
assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"), assert!(output.contains("RUN_TEST_NEW_ENV=123"),
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
} }
@ -1094,7 +1091,7 @@ mod tests {
let result = prog.wait_with_output().unwrap(); let result = prog.wait_with_output().unwrap();
let output = String::from_utf8_lossy(result.output.as_slice()).into_string(); let output = String::from_utf8_lossy(result.output.as_slice()).into_string();
assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"), assert!(output.contains("RUN_TEST_NEW_ENV=123"),
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
} }

View file

@ -528,7 +528,7 @@ mod tests {
set_stdout(box w); set_stdout(box w);
println!("hello!"); println!("hello!");
}); });
assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string()); assert_eq!(r.read_to_string().unwrap(), "hello!\n");
} }
#[test] #[test]
@ -543,6 +543,6 @@ mod tests {
panic!("my special message"); panic!("my special message");
}); });
let s = r.read_to_string().unwrap(); let s = r.read_to_string().unwrap();
assert!(s.as_slice().contains("my special message")); assert!(s.contains("my special message"));
} }
} }

View file

@ -428,28 +428,28 @@ mod tests {
#[test] #[test]
fn test_int_to_str_overflow() { fn test_int_to_str_overflow() {
let mut i8_val: i8 = 127_i8; let mut i8_val: i8 = 127_i8;
assert_eq!(i8_val.to_string(), "127".to_string()); assert_eq!(i8_val.to_string(), "127");
i8_val += 1 as i8; i8_val += 1 as i8;
assert_eq!(i8_val.to_string(), "-128".to_string()); assert_eq!(i8_val.to_string(), "-128");
let mut i16_val: i16 = 32_767_i16; let mut i16_val: i16 = 32_767_i16;
assert_eq!(i16_val.to_string(), "32767".to_string()); assert_eq!(i16_val.to_string(), "32767");
i16_val += 1 as i16; i16_val += 1 as i16;
assert_eq!(i16_val.to_string(), "-32768".to_string()); assert_eq!(i16_val.to_string(), "-32768");
let mut i32_val: i32 = 2_147_483_647_i32; let mut i32_val: i32 = 2_147_483_647_i32;
assert_eq!(i32_val.to_string(), "2147483647".to_string()); assert_eq!(i32_val.to_string(), "2147483647");
i32_val += 1 as i32; i32_val += 1 as i32;
assert_eq!(i32_val.to_string(), "-2147483648".to_string()); assert_eq!(i32_val.to_string(), "-2147483648");
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert_eq!(i64_val.to_string(), "9223372036854775807".to_string()); assert_eq!(i64_val.to_string(), "9223372036854775807");
i64_val += 1 as i64; i64_val += 1 as i64;
assert_eq!(i64_val.to_string(), "-9223372036854775808".to_string()); assert_eq!(i64_val.to_string(), "-9223372036854775808");
} }
} }

View file

@ -79,28 +79,28 @@ mod tests {
#[test] #[test]
fn test_uint_to_str_overflow() { fn test_uint_to_str_overflow() {
let mut u8_val: u8 = 255_u8; let mut u8_val: u8 = 255_u8;
assert_eq!(u8_val.to_string(), "255".to_string()); assert_eq!(u8_val.to_string(), "255");
u8_val += 1 as u8; u8_val += 1 as u8;
assert_eq!(u8_val.to_string(), "0".to_string()); assert_eq!(u8_val.to_string(), "0");
let mut u16_val: u16 = 65_535_u16; let mut u16_val: u16 = 65_535_u16;
assert_eq!(u16_val.to_string(), "65535".to_string()); assert_eq!(u16_val.to_string(), "65535");
u16_val += 1 as u16; u16_val += 1 as u16;
assert_eq!(u16_val.to_string(), "0".to_string()); assert_eq!(u16_val.to_string(), "0");
let mut u32_val: u32 = 4_294_967_295_u32; let mut u32_val: u32 = 4_294_967_295_u32;
assert_eq!(u32_val.to_string(), "4294967295".to_string()); assert_eq!(u32_val.to_string(), "4294967295");
u32_val += 1 as u32; u32_val += 1 as u32;
assert_eq!(u32_val.to_string(), "0".to_string()); assert_eq!(u32_val.to_string(), "0");
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert_eq!(u64_val.to_string(), "18446744073709551615".to_string()); assert_eq!(u64_val.to_string(), "18446744073709551615");
u64_val += 1 as u64; u64_val += 1 as u64;
assert_eq!(u64_val.to_string(), "0".to_string()); assert_eq!(u64_val.to_string(), "0");
} }
#[test] #[test]

View file

@ -316,7 +316,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> {
fn env_convert(input: Vec<Vec<u8>>) -> Vec<(Vec<u8>, Vec<u8>)> { fn env_convert(input: Vec<Vec<u8>>) -> Vec<(Vec<u8>, Vec<u8>)> {
let mut pairs = Vec::new(); let mut pairs = Vec::new();
for p in input.iter() { for p in input.iter() {
let mut it = p.as_slice().splitn(1, |b| *b == b'='); let mut it = p.splitn(1, |b| *b == b'=');
let key = it.next().unwrap().to_vec(); let key = it.next().unwrap().to_vec();
let default: &[u8] = &[]; let default: &[u8] = &[];
let val = it.next().unwrap_or(default).to_vec(); let val = it.next().unwrap_or(default).to_vec();
@ -2069,7 +2069,7 @@ mod tests {
#[cfg(unix)] #[cfg(unix)]
fn join_paths_unix() { fn join_paths_unix() {
fn test_eq(input: &[&str], output: &str) -> bool { fn test_eq(input: &[&str], output: &str) -> bool {
join_paths(input).unwrap().as_slice() == output.as_bytes() join_paths(input).unwrap() == output.as_bytes()
} }
assert!(test_eq(&[], "")); assert!(test_eq(&[], ""));
@ -2084,7 +2084,7 @@ mod tests {
#[cfg(windows)] #[cfg(windows)]
fn join_paths_windows() { fn join_paths_windows() {
fn test_eq(input: &[&str], output: &str) -> bool { fn test_eq(input: &[&str], output: &str) -> bool {
join_paths(input).unwrap().as_slice() == output.as_bytes() join_paths(input).unwrap() == output.as_bytes()
} }
assert!(test_eq(&[], "")); assert!(test_eq(&[], ""));

View file

@ -942,6 +942,6 @@ mod tests {
let input = r"\foo\bar\baz"; let input = r"\foo\bar\baz";
let path: WindowsPath = WindowsPath::new(input.to_c_str()); let path: WindowsPath = WindowsPath::new(input.to_c_str());
assert_eq!(path.as_str().unwrap(), input.as_slice()); assert_eq!(path.as_str().unwrap(), input);
} }
} }

View file

@ -132,7 +132,7 @@ impl GenericPathUnsafe for Path {
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) { unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) {
let filename = filename.container_as_bytes(); let filename = filename.container_as_bytes();
match self.sepidx { match self.sepidx {
None if b".." == self.repr.as_slice() => { None if b".." == self.repr => {
let mut v = Vec::with_capacity(3 + filename.len()); let mut v = Vec::with_capacity(3 + filename.len());
v.push_all(dot_dot_static); v.push_all(dot_dot_static);
v.push(SEP_BYTE); v.push(SEP_BYTE);
@ -159,7 +159,7 @@ impl GenericPathUnsafe for Path {
self.repr = Path::normalize(v.as_slice()); self.repr = Path::normalize(v.as_slice());
} }
} }
self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
} }
unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T) { unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T) {
@ -175,7 +175,7 @@ impl GenericPathUnsafe for Path {
// FIXME: this is slow // FIXME: this is slow
self.repr = Path::normalize(v.as_slice()); self.repr = Path::normalize(v.as_slice());
} }
self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
} }
} }
} }
@ -192,7 +192,7 @@ impl GenericPath for Path {
fn dirname<'a>(&'a self) -> &'a [u8] { fn dirname<'a>(&'a self) -> &'a [u8] {
match self.sepidx { match self.sepidx {
None if b".." == self.repr.as_slice() => self.repr.as_slice(), None if b".." == self.repr => self.repr.as_slice(),
None => dot_static, None => dot_static,
Some(0) => self.repr[..1], Some(0) => self.repr[..1],
Some(idx) if self.repr[idx+1..] == b".." => self.repr.as_slice(), Some(idx) if self.repr[idx+1..] == b".." => self.repr.as_slice(),
@ -202,8 +202,8 @@ impl GenericPath for Path {
fn filename<'a>(&'a self) -> Option<&'a [u8]> { fn filename<'a>(&'a self) -> Option<&'a [u8]> {
match self.sepidx { match self.sepidx {
None if b"." == self.repr.as_slice() || None if b"." == self.repr ||
b".." == self.repr.as_slice() => None, b".." == self.repr => None,
None => Some(self.repr.as_slice()), None => Some(self.repr.as_slice()),
Some(idx) if self.repr[idx+1..] == b".." => None, Some(idx) if self.repr[idx+1..] == b".." => None,
Some(0) if self.repr[1..].is_empty() => None, Some(0) if self.repr[1..].is_empty() => None,
@ -213,20 +213,20 @@ impl GenericPath for Path {
fn pop(&mut self) -> bool { fn pop(&mut self) -> bool {
match self.sepidx { match self.sepidx {
None if b"." == self.repr.as_slice() => false, None if b"." == self.repr => false,
None => { None => {
self.repr = vec![b'.']; self.repr = vec![b'.'];
self.sepidx = None; self.sepidx = None;
true true
} }
Some(0) if b"/" == self.repr.as_slice() => false, Some(0) if b"/" == self.repr => false,
Some(idx) => { Some(idx) => {
if idx == 0 { if idx == 0 {
self.repr.truncate(idx+1); self.repr.truncate(idx+1);
} else { } else {
self.repr.truncate(idx); self.repr.truncate(idx);
} }
self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
true true
} }
} }
@ -251,7 +251,7 @@ impl GenericPath for Path {
} else { } else {
let mut ita = self.components(); let mut ita = self.components();
let mut itb = other.components(); let mut itb = other.components();
if b"." == self.repr.as_slice() { if b"." == self.repr {
return match itb.next() { return match itb.next() {
None => true, None => true,
Some(b) => b != b".." Some(b) => b != b".."
@ -306,7 +306,7 @@ impl GenericPath for Path {
} }
} }
} }
Some(Path::new(comps.as_slice().connect_vec(&SEP_BYTE))) Some(Path::new(comps.connect_vec(&SEP_BYTE)))
} }
} }
@ -407,7 +407,7 @@ impl Path {
// None result means the byte vector didn't need normalizing // None result means the byte vector didn't need normalizing
fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<Vec<&'a [u8]>> { fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<Vec<&'a [u8]>> {
if is_abs && v.as_slice().is_empty() { if is_abs && v.is_empty() {
return None; return None;
} }
let mut comps: Vec<&'a [u8]> = vec![]; let mut comps: Vec<&'a [u8]> = vec![];
@ -496,8 +496,8 @@ mod tests {
t!(s: Path::new("foo/../../.."), "../.."); t!(s: Path::new("foo/../../.."), "../..");
t!(s: Path::new("foo/../../bar"), "../bar"); t!(s: Path::new("foo/../../bar"), "../bar");
assert_eq!(Path::new(b"foo/bar").into_vec().as_slice(), b"foo/bar"); assert_eq!(Path::new(b"foo/bar").into_vec(), b"foo/bar");
assert_eq!(Path::new(b"/foo/../../bar").into_vec().as_slice(), assert_eq!(Path::new(b"/foo/../../bar").into_vec(),
b"/bar"); b"/bar");
let p = Path::new(b"foo/bar\x80"); let p = Path::new(b"foo/bar\x80");
@ -537,7 +537,7 @@ mod tests {
($path:expr, $disp:ident, $exp:expr) => ( ($path:expr, $disp:ident, $exp:expr) => (
{ {
let path = Path::new($path); let path = Path::new($path);
assert!(path.$disp().to_string().as_slice() == $exp); assert!(path.$disp().to_string() == $exp);
} }
) )
) )
@ -580,9 +580,9 @@ mod tests {
{ {
let path = Path::new($path); let path = Path::new($path);
let f = format!("{}", path.display()); let f = format!("{}", path.display());
assert!(f.as_slice() == $exp); assert!(f == $exp);
let f = format!("{}", path.filename_display()); let f = format!("{}", path.filename_display());
assert!(f.as_slice() == $expf); assert!(f == $expf);
} }
) )
) )
@ -1180,7 +1180,7 @@ mod tests {
let path = Path::new($arg); let path = Path::new($arg);
let comps = path.components().collect::<Vec<&[u8]>>(); let comps = path.components().collect::<Vec<&[u8]>>();
let exp: &[&[u8]] = &[$($exp),*]; let exp: &[&[u8]] = &[$($exp),*];
assert_eq!(comps.as_slice(), exp); assert_eq!(comps, exp);
let comps = path.components().rev().collect::<Vec<&[u8]>>(); let comps = path.components().rev().collect::<Vec<&[u8]>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>(); let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
assert_eq!(comps, exp) assert_eq!(comps, exp)
@ -1212,7 +1212,7 @@ mod tests {
let path = Path::new($arg); let path = Path::new($arg);
let comps = path.str_components().collect::<Vec<Option<&str>>>(); let comps = path.str_components().collect::<Vec<Option<&str>>>();
let exp: &[Option<&str>] = &$exp; let exp: &[Option<&str>] = &$exp;
assert_eq!(comps.as_slice(), exp); assert_eq!(comps, exp);
let comps = path.str_components().rev().collect::<Vec<Option<&str>>>(); let comps = path.str_components().rev().collect::<Vec<Option<&str>>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>(); let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>();
assert_eq!(comps, exp); assert_eq!(comps, exp);

View file

@ -182,7 +182,7 @@ impl GenericPathUnsafe for Path {
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) { unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) {
let filename = filename.container_as_str().unwrap(); let filename = filename.container_as_str().unwrap();
match self.sepidx_or_prefix_len() { match self.sepidx_or_prefix_len() {
None if ".." == self.repr.as_slice() => { None if ".." == self.repr => {
let mut s = String::with_capacity(3 + filename.len()); let mut s = String::with_capacity(3 + filename.len());
s.push_str(".."); s.push_str("..");
s.push(SEP); s.push(SEP);
@ -192,22 +192,22 @@ impl GenericPathUnsafe for Path {
None => { None => {
self.update_normalized(filename); self.update_normalized(filename);
} }
Some((_,idxa,end)) if self.repr.as_slice().slice(idxa,end) == ".." => { Some((_,idxa,end)) if self.repr.slice(idxa,end) == ".." => {
let mut s = String::with_capacity(end + 1 + filename.len()); let mut s = String::with_capacity(end + 1 + filename.len());
s.push_str(self.repr.as_slice().slice_to(end)); s.push_str(self.repr.slice_to(end));
s.push(SEP); s.push(SEP);
s.push_str(filename); s.push_str(filename);
self.update_normalized(s); self.update_normalized(s);
} }
Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => { Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => {
let mut s = String::with_capacity(idxb + filename.len()); let mut s = String::with_capacity(idxb + filename.len());
s.push_str(self.repr.as_slice().slice_to(idxb)); s.push_str(self.repr.slice_to(idxb));
s.push_str(filename); s.push_str(filename);
self.update_normalized(s); self.update_normalized(s);
} }
Some((idxb,_,_)) => { Some((idxb,_,_)) => {
let mut s = String::with_capacity(idxb + 1 + filename.len()); let mut s = String::with_capacity(idxb + 1 + filename.len());
s.push_str(self.repr.as_slice().slice_to(idxb)); s.push_str(self.repr.slice_to(idxb));
s.push(SEP); s.push(SEP);
s.push_str(filename); s.push_str(filename);
self.update_normalized(s); self.update_normalized(s);
@ -356,21 +356,21 @@ impl GenericPath for Path {
/// Always returns a `Some` value. /// Always returns a `Some` value.
fn dirname_str<'a>(&'a self) -> Option<&'a str> { fn dirname_str<'a>(&'a self) -> Option<&'a str> {
Some(match self.sepidx_or_prefix_len() { Some(match self.sepidx_or_prefix_len() {
None if ".." == self.repr.as_slice() => self.repr.as_slice(), None if ".." == self.repr => self.repr.as_slice(),
None => ".", None => ".",
Some((_,idxa,end)) if self.repr.as_slice().slice(idxa, end) == ".." => { Some((_,idxa,end)) if self.repr.slice(idxa, end) == ".." => {
self.repr.as_slice() self.repr.as_slice()
} }
Some((idxb,_,end)) if self.repr.as_slice().slice(idxb, end) == "\\" => { Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => {
self.repr.as_slice() self.repr.as_slice()
} }
Some((0,idxa,_)) => self.repr.as_slice().slice_to(idxa), Some((0,idxa,_)) => self.repr.slice_to(idxa),
Some((idxb,idxa,_)) => { Some((idxb,idxa,_)) => {
match self.prefix { match self.prefix {
Some(DiskPrefix) | Some(VerbatimDiskPrefix) if idxb == self.prefix_len() => { Some(DiskPrefix) | Some(VerbatimDiskPrefix) if idxb == self.prefix_len() => {
self.repr.as_slice().slice_to(idxa) self.repr.slice_to(idxa)
} }
_ => self.repr.as_slice().slice_to(idxb) _ => self.repr.slice_to(idxb)
} }
} }
}) })
@ -415,14 +415,14 @@ impl GenericPath for Path {
#[inline] #[inline]
fn pop(&mut self) -> bool { fn pop(&mut self) -> bool {
match self.sepidx_or_prefix_len() { match self.sepidx_or_prefix_len() {
None if "." == self.repr.as_slice() => false, None if "." == self.repr => false,
None => { None => {
self.repr = String::from_str("."); self.repr = String::from_str(".");
self.sepidx = None; self.sepidx = None;
true true
} }
Some((idxb,idxa,end)) if idxb == idxa && idxb == end => false, Some((idxb,idxa,end)) if idxb == idxa && idxb == end => false,
Some((idxb,_,end)) if self.repr.as_slice().slice(idxb, end) == "\\" => false, Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => false,
Some((idxb,idxa,_)) => { Some((idxb,idxa,_)) => {
let trunc = match self.prefix { let trunc = match self.prefix {
Some(DiskPrefix) | Some(VerbatimDiskPrefix) | None => { Some(DiskPrefix) | Some(VerbatimDiskPrefix) | None => {
@ -442,15 +442,15 @@ impl GenericPath for Path {
if self.prefix.is_some() { if self.prefix.is_some() {
Some(Path::new(match self.prefix { Some(Path::new(match self.prefix {
Some(DiskPrefix) if self.is_absolute() => { Some(DiskPrefix) if self.is_absolute() => {
self.repr.as_slice().slice_to(self.prefix_len()+1) self.repr.slice_to(self.prefix_len()+1)
} }
Some(VerbatimDiskPrefix) => { Some(VerbatimDiskPrefix) => {
self.repr.as_slice().slice_to(self.prefix_len()+1) self.repr.slice_to(self.prefix_len()+1)
} }
_ => self.repr.as_slice().slice_to(self.prefix_len()) _ => self.repr.slice_to(self.prefix_len())
})) }))
} else if is_vol_relative(self) { } else if is_vol_relative(self) {
Some(Path::new(self.repr.as_slice().slice_to(1))) Some(Path::new(self.repr.slice_to(1)))
} else { } else {
None None
} }
@ -469,7 +469,7 @@ impl GenericPath for Path {
fn is_absolute(&self) -> bool { fn is_absolute(&self) -> bool {
match self.prefix { match self.prefix {
Some(DiskPrefix) => { Some(DiskPrefix) => {
let rest = self.repr.as_slice().slice_from(self.prefix_len()); let rest = self.repr.slice_from(self.prefix_len());
rest.len() > 0 && rest.as_bytes()[0] == SEP_BYTE rest.len() > 0 && rest.as_bytes()[0] == SEP_BYTE
} }
Some(_) => true, Some(_) => true,
@ -491,7 +491,7 @@ impl GenericPath for Path {
} else { } else {
let mut ita = self.str_components().map(|x|x.unwrap()); let mut ita = self.str_components().map(|x|x.unwrap());
let mut itb = other.str_components().map(|x|x.unwrap()); let mut itb = other.str_components().map(|x|x.unwrap());
if "." == self.repr.as_slice() { if "." == self.repr {
return itb.next() != Some(".."); return itb.next() != Some("..");
} }
loop { loop {
@ -827,7 +827,7 @@ impl Path {
fn update_sepidx(&mut self) { fn update_sepidx(&mut self) {
let s = if self.has_nonsemantic_trailing_slash() { let s = if self.has_nonsemantic_trailing_slash() {
self.repr.as_slice().slice_to(self.repr.len()-1) self.repr.slice_to(self.repr.len()-1)
} else { self.repr.as_slice() }; } else { self.repr.as_slice() };
let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep }
else { is_sep_verbatim }); else { is_sep_verbatim });
@ -923,7 +923,7 @@ pub fn make_non_verbatim(path: &Path) -> Option<Path> {
} }
// now ensure normalization didn't change anything // now ensure normalization didn't change anything
if repr.slice_from(path.prefix_len()) == if repr.slice_from(path.prefix_len()) ==
new_path.repr.as_slice().slice_from(new_path.prefix_len()) { new_path.repr.slice_from(new_path.prefix_len()) {
Some(new_path) Some(new_path)
} else { } else {
None None
@ -1233,8 +1233,8 @@ mod tests {
t!(s: Path::new("foo\\..\\..\\.."), "..\\.."); t!(s: Path::new("foo\\..\\..\\.."), "..\\..");
t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar"); t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar");
assert_eq!(Path::new(b"foo\\bar").into_vec().as_slice(), b"foo\\bar"); assert_eq!(Path::new(b"foo\\bar").into_vec(), b"foo\\bar");
assert_eq!(Path::new(b"\\foo\\..\\..\\bar").into_vec().as_slice(), b"\\bar"); assert_eq!(Path::new(b"\\foo\\..\\..\\bar").into_vec(), b"\\bar");
t!(s: Path::new("\\\\a"), "\\a"); t!(s: Path::new("\\\\a"), "\\a");
t!(s: Path::new("\\\\a\\"), "\\a"); t!(s: Path::new("\\\\a\\"), "\\a");
@ -1322,9 +1322,9 @@ mod tests {
#[test] #[test]
fn test_display_str() { fn test_display_str() {
let path = Path::new("foo"); let path = Path::new("foo");
assert_eq!(path.display().to_string(), "foo".to_string()); assert_eq!(path.display().to_string(), "foo");
let path = Path::new(b"\\"); let path = Path::new(b"\\");
assert_eq!(path.filename_display().to_string(), "".to_string()); assert_eq!(path.filename_display().to_string(), "");
let path = Path::new("foo"); let path = Path::new("foo");
let mo = path.display().as_cow(); let mo = path.display().as_cow();
@ -1341,9 +1341,9 @@ mod tests {
{ {
let path = Path::new($path); let path = Path::new($path);
let f = format!("{}", path.display()); let f = format!("{}", path.display());
assert_eq!(f.as_slice(), $exp); assert_eq!(f, $exp);
let f = format!("{}", path.filename_display()); let f = format!("{}", path.filename_display());
assert_eq!(f.as_slice(), $expf); assert_eq!(f, $expf);
} }
) )
) )
@ -2246,7 +2246,7 @@ mod tests {
let comps = path.str_components().map(|x|x.unwrap()) let comps = path.str_components().map(|x|x.unwrap())
.collect::<Vec<&str>>(); .collect::<Vec<&str>>();
let exp: &[&str] = &$exp; let exp: &[&str] = &$exp;
assert_eq!(comps.as_slice(), exp); assert_eq!(comps, exp);
let comps = path.str_components().rev().map(|x|x.unwrap()) let comps = path.str_components().rev().map(|x|x.unwrap())
.collect::<Vec<&str>>(); .collect::<Vec<&str>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&str>>(); let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&str>>();
@ -2303,7 +2303,7 @@ mod tests {
let path = Path::new($path); let path = Path::new($path);
let comps = path.components().collect::<Vec<&[u8]>>(); let comps = path.components().collect::<Vec<&[u8]>>();
let exp: &[&[u8]] = &$exp; let exp: &[&[u8]] = &$exp;
assert_eq!(comps.as_slice(), exp); assert_eq!(comps, exp);
let comps = path.components().rev().collect::<Vec<&[u8]>>(); let comps = path.components().rev().collect::<Vec<&[u8]>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>(); let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
assert_eq!(comps, exp); assert_eq!(comps, exp);

View file

@ -529,7 +529,7 @@ mod test {
let mut one = [1i]; let mut one = [1i];
r.shuffle(&mut one); r.shuffle(&mut one);
let b: &[_] = &[1]; let b: &[_] = &[1];
assert_eq!(one.as_slice(), b); assert_eq!(one, b);
let mut two = [1i, 2]; let mut two = [1i, 2];
r.shuffle(&mut two); r.shuffle(&mut two);
@ -538,7 +538,7 @@ mod test {
let mut x = [1i, 1, 1]; let mut x = [1i, 1, 1];
r.shuffle(&mut x); r.shuffle(&mut x);
let b: &[_] = &[1, 1, 1]; let b: &[_] = &[1, 1, 1];
assert_eq!(x.as_slice(), b); assert_eq!(x, b);
} }
#[test] #[test]
@ -548,7 +548,7 @@ mod test {
let mut v = [1i, 1, 1]; let mut v = [1i, 1, 1];
r.shuffle(&mut v); r.shuffle(&mut v);
let b: &[_] = &[1, 1, 1]; let b: &[_] = &[1, 1, 1];
assert_eq!(v.as_slice(), b); assert_eq!(v, b);
assert_eq!(r.gen_range(0u, 1u), 0u); assert_eq!(r.gen_range(0u, 1u), 0u);
} }

View file

@ -1013,7 +1013,7 @@ mod test {
macro_rules! t( ($a:expr, $b:expr) => ({ macro_rules! t( ($a:expr, $b:expr) => ({
let mut m = Vec::new(); let mut m = Vec::new();
super::demangle(&mut m, $a).unwrap(); super::demangle(&mut m, $a).unwrap();
assert_eq!(String::from_utf8(m).unwrap(), $b.to_string()); assert_eq!(String::from_utf8(m).unwrap(), $b);
}) ) }) )
#[test] #[test]

View file

@ -153,7 +153,7 @@ mod test {
#[test] #[test]
fn test_from_value() { fn test_from_value() {
let mut f = Future::from_value("snail".to_string()); let mut f = Future::from_value("snail".to_string());
assert_eq!(f.get(), "snail".to_string()); assert_eq!(f.get(), "snail");
} }
#[test] #[test]
@ -161,25 +161,25 @@ mod test {
let (tx, rx) = channel(); let (tx, rx) = channel();
tx.send("whale".to_string()); tx.send("whale".to_string());
let mut f = Future::from_receiver(rx); let mut f = Future::from_receiver(rx);
assert_eq!(f.get(), "whale".to_string()); assert_eq!(f.get(), "whale");
} }
#[test] #[test]
fn test_from_fn() { fn test_from_fn() {
let mut f = Future::from_fn(proc() "brail".to_string()); let mut f = Future::from_fn(proc() "brail".to_string());
assert_eq!(f.get(), "brail".to_string()); assert_eq!(f.get(), "brail");
} }
#[test] #[test]
fn test_interface_get() { fn test_interface_get() {
let mut f = Future::from_value("fail".to_string()); let mut f = Future::from_value("fail".to_string());
assert_eq!(f.get(), "fail".to_string()); assert_eq!(f.get(), "fail");
} }
#[test] #[test]
fn test_interface_unwrap() { fn test_interface_unwrap() {
let f = Future::from_value("fail".to_string()); let f = Future::from_value("fail".to_string());
assert_eq!(f.unwrap(), "fail".to_string()); assert_eq!(f.unwrap(), "fail");
} }
#[test] #[test]
@ -191,7 +191,7 @@ mod test {
#[test] #[test]
fn test_spawn() { fn test_spawn() {
let mut f = Future::spawn(proc() "bale".to_string()); let mut f = Future::spawn(proc() "bale".to_string());
assert_eq!(f.get(), "bale".to_string()); assert_eq!(f.get(), "bale");
} }
#[test] #[test]

View file

@ -201,7 +201,7 @@ pub fn readdir(p: &Path) -> IoResult<Vec<Path>> {
let size = unsafe { rust_dirent_t_size() }; let size = unsafe { rust_dirent_t_size() };
let mut buf = Vec::<u8>::with_capacity(size as uint); let mut buf = Vec::<u8>::with_capacity(size as uint);
let ptr = buf.as_mut_slice().as_mut_ptr() as *mut dirent_t; let ptr = buf.as_mut_ptr() as *mut dirent_t;
let p = p.to_c_str(); let p = p.to_c_str();
let dir_ptr = unsafe {opendir(p.as_ptr())}; let dir_ptr = unsafe {opendir(p.as_ptr())};

View file

@ -376,8 +376,8 @@ pub fn readlink(p: &Path) -> IoResult<Path> {
libc::VOLUME_NAME_DOS) libc::VOLUME_NAME_DOS)
}); });
let ret = match ret { let ret = match ret {
Some(ref s) if s.as_slice().starts_with(r"\\?\") => { // " Some(ref s) if s.starts_with(r"\\?\") => { // "
Ok(Path::new(s.as_slice().slice_from(4))) Ok(Path::new(s.slice_from(4)))
} }
Some(s) => Ok(Path::new(s)), Some(s) => Ok(Path::new(s)),
None => Err(super::last_error()), None => Err(super::last_error()),

View file

@ -223,7 +223,7 @@ impl Process {
with_envp(cfg.env(), |envp| { with_envp(cfg.env(), |envp| {
with_dirp(cfg.cwd(), |dirp| { with_dirp(cfg.cwd(), |dirp| {
let mut cmd_str: Vec<u16> = cmd_str.as_slice().utf16_units().collect(); let mut cmd_str: Vec<u16> = cmd_str.utf16_units().collect();
cmd_str.push(0); cmd_str.push(0);
let created = CreateProcessW(ptr::null(), let created = CreateProcessW(ptr::null(),
cmd_str.as_mut_ptr(), cmd_str.as_mut_ptr(),
@ -433,7 +433,7 @@ fn with_envp<K, V, T>(env: Option<&collections::HashMap<K, V>>,
let kv = format!("{}={}", let kv = format!("{}={}",
pair.ref0().container_as_str().unwrap(), pair.ref0().container_as_str().unwrap(),
pair.ref1().container_as_str().unwrap()); pair.ref1().container_as_str().unwrap());
blk.extend(kv.as_slice().utf16_units()); blk.extend(kv.utf16_units());
blk.push(0); blk.push(0);
} }
@ -484,24 +484,24 @@ mod tests {
assert_eq!( assert_eq!(
test_wrapper("prog", &["aaa", "bbb", "ccc"]), test_wrapper("prog", &["aaa", "bbb", "ccc"]),
"prog aaa bbb ccc".to_string() "prog aaa bbb ccc"
); );
assert_eq!( assert_eq!(
test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa"]), test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa"]),
"\"C:\\Program Files\\blah\\blah.exe\" aaa".to_string() "\"C:\\Program Files\\blah\\blah.exe\" aaa"
); );
assert_eq!( assert_eq!(
test_wrapper("C:\\Program Files\\test", &["aa\"bb"]), test_wrapper("C:\\Program Files\\test", &["aa\"bb"]),
"\"C:\\Program Files\\test\" aa\\\"bb".to_string() "\"C:\\Program Files\\test\" aa\\\"bb"
); );
assert_eq!( assert_eq!(
test_wrapper("echo", &["a b c"]), test_wrapper("echo", &["a b c"]),
"echo \"a b c\"".to_string() "echo \"a b c\""
); );
assert_eq!( assert_eq!(
test_wrapper("\u03c0\u042f\u97f3\u00e6\u221e", &[]), test_wrapper("\u03c0\u042f\u97f3\u00e6\u221e", &[]),
"\u03c0\u042f\u97f3\u00e6\u221e".to_string() "\u03c0\u042f\u97f3\u00e6\u221e"
); );
} }
} }

View file

@ -113,7 +113,7 @@ impl TTY {
pub fn write(&mut self, buf: &[u8]) -> IoResult<()> { pub fn write(&mut self, buf: &[u8]) -> IoResult<()> {
let utf16 = match from_utf8(buf) { let utf16 = match from_utf8(buf) {
Some(utf8) => { Some(utf8) => {
utf8.as_slice().utf16_units().collect::<Vec<u16>>() utf8.utf16_units().collect::<Vec<u16>>()
} }
None => return Err(invalid_encoding()), None => return Err(invalid_encoding()),
}; };

View file

@ -55,7 +55,7 @@ use result::Result;
use rustrt::local::Local; use rustrt::local::Local;
use rustrt::task::Task; use rustrt::task::Task;
use rustrt::task; use rustrt::task;
use str::{Str, SendStr}; use str::SendStr;
use string::{String, ToString}; use string::{String, ToString};
use sync::Future; use sync::Future;
@ -244,7 +244,7 @@ pub fn name() -> Option<String> {
let task = Local::borrow(None::<Task>); let task = Local::borrow(None::<Task>);
match task.name { match task.name {
Some(ref name) => Some(name.as_slice().to_string()), Some(ref name) => Some(name.to_string()),
None => None None => None
} }
} }
@ -289,21 +289,21 @@ mod test {
#[test] #[test]
fn test_owned_named_task() { fn test_owned_named_task() {
TaskBuilder::new().named("ada lovelace".to_string()).try(proc() { TaskBuilder::new().named("ada lovelace".to_string()).try(proc() {
assert!(name().unwrap() == "ada lovelace".to_string()); assert!(name().unwrap() == "ada lovelace");
}).map_err(|_| ()).unwrap(); }).map_err(|_| ()).unwrap();
} }
#[test] #[test]
fn test_static_named_task() { fn test_static_named_task() {
TaskBuilder::new().named("ada lovelace").try(proc() { TaskBuilder::new().named("ada lovelace").try(proc() {
assert!(name().unwrap() == "ada lovelace".to_string()); assert!(name().unwrap() == "ada lovelace");
}).map_err(|_| ()).unwrap(); }).map_err(|_| ()).unwrap();
} }
#[test] #[test]
fn test_send_named_task() { fn test_send_named_task() {
TaskBuilder::new().named("ada lovelace".into_cow()).try(proc() { TaskBuilder::new().named("ada lovelace".into_cow()).try(proc() {
assert!(name().unwrap() == "ada lovelace".to_string()); assert!(name().unwrap() == "ada lovelace");
}).map_err(|_| ()).unwrap(); }).map_err(|_| ()).unwrap();
} }
@ -464,7 +464,7 @@ mod test {
Err(e) => { Err(e) => {
type T = String; type T = String;
assert!(e.is::<T>()); assert!(e.is::<T>());
assert_eq!(*e.downcast::<T>().unwrap(), "owned string".to_string()); assert_eq!(*e.downcast::<T>().unwrap(), "owned string");
} }
Ok(()) => panic!() Ok(()) => panic!()
} }
@ -511,7 +511,7 @@ mod test {
assert!(r.is_ok()); assert!(r.is_ok());
let output = reader.read_to_string().unwrap(); let output = reader.read_to_string().unwrap();
assert_eq!(output, "Hello, world!".to_string()); assert_eq!(output, "Hello, world!");
} }
// NOTE: the corresponding test for stderr is in run-pass/task-stderr, due // NOTE: the corresponding test for stderr is in run-pass/task-stderr, due

Some files were not shown because too many files have changed in this diff Show more