libstd: remove unnecessary as_slice() calls

This commit is contained in:
Jorge Aparicio 2014-11-27 14:43:55 -05:00
parent 09f7713dd4
commit 60338d91c4
19 changed files with 118 additions and 121 deletions

View file

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

View file

@ -176,28 +176,28 @@ mod test {
assert_eq!(Ok(3), reader.read(&mut buf));
let a: &[u8] = &[1,2,3];
assert_eq!(a, buf.as_slice());
assert_eq!(a, buf);
assert_eq!(Ok(3), reader.read(&mut buf));
let a: &[u8] = &[4,5,6];
assert_eq!(a, buf.as_slice());
assert_eq!(a, buf);
assert_eq!(Ok(2), reader.read(&mut buf));
let a: &[u8] = &[7,8,6];
assert_eq!(a, buf.as_slice());
assert_eq!(a, buf);
match reader.read(buf.as_mut_slice()) {
Ok(..) => panic!(),
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.
match reader.read(buf.as_mut_slice()) {
Ok(..) => panic!(),
Err(e) => assert_eq!(e.kind, io::EndOfFile),
}
assert_eq!(a, buf.as_slice());
assert_eq!(a, buf);
}
#[test]

View file

@ -837,7 +837,7 @@ mod test {
macro_rules! error( ($e:expr, $s:expr) => (
match $e {
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))
}
) )
@ -995,7 +995,7 @@ mod test {
}
check!(unlink(filename));
let read_str = str::from_utf8(&read_mem).unwrap();
assert!(read_str.as_slice() == final_msg.as_slice());
assert!(read_str == final_msg);
}
#[test]
@ -1103,7 +1103,7 @@ mod test {
let f = dir.join(format!("{}.txt", n));
let mut w = check!(File::create(&f));
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));
}
let files = check!(readdir(dir));

View file

@ -444,7 +444,7 @@ mod test {
assert_eq!(writer.write(&[10]).unwrap_err().kind, io::EndOfFile);
}
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
assert_eq!(buf.as_slice(), b);
assert_eq!(buf, b);
}
#[test]
@ -473,7 +473,7 @@ mod test {
}
let b: &[_] = &[1, 3, 2, 0, 0, 0, 0, 4];
assert_eq!(buf.as_slice(), b);
assert_eq!(buf, b);
}
#[test]
@ -498,12 +498,12 @@ mod test {
assert_eq!(reader.read(&mut buf), Ok(1));
assert_eq!(reader.tell(), Ok(1));
let b: &[_] = &[0];
assert_eq!(buf.as_slice(), b);
assert_eq!(buf, b);
let mut buf = [0, ..4];
assert_eq!(reader.read(&mut buf), Ok(4));
assert_eq!(reader.tell(), Ok(5));
let b: &[_] = &[1, 2, 3, 4];
assert_eq!(buf.as_slice(), b);
assert_eq!(buf, b);
assert_eq!(reader.read(&mut buf), Ok(3));
let b: &[_] = &[5, 6, 7];
assert_eq!(buf[0..3], b);
@ -551,12 +551,12 @@ mod test {
assert_eq!(reader.read(&mut buf), Ok(1));
assert_eq!(reader.tell(), Ok(1));
let b: &[_] = &[0];
assert_eq!(buf.as_slice(), b);
assert_eq!(buf, b);
let mut buf = [0, ..4];
assert_eq!(reader.read(&mut buf), Ok(4));
assert_eq!(reader.tell(), Ok(5));
let b: &[_] = &[1, 2, 3, 4];
assert_eq!(buf.as_slice(), b);
assert_eq!(buf, b);
assert_eq!(reader.read(&mut buf), Ok(3));
let b: &[_] = &[5, 6, 7];
assert_eq!(buf[0..3], b);
@ -652,15 +652,15 @@ mod test {
let mut buf = [0, ..3];
assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
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_eq!(buf.as_slice(), b);
assert_eq!(buf, b);
assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
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());
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) {
@ -757,7 +757,7 @@ mod test {
for _i in range(0u, 10) {
let mut buf = [0 as u8, .. 10];
rdr.read(&mut buf).unwrap();
assert_eq!(buf.as_slice(), [5, .. 10].as_slice());
assert_eq!(buf, [5, .. 10]);
}
}
});

View file

@ -238,8 +238,8 @@ use os;
use boxed::Box;
use result::{Ok, Err, Result};
use sys;
use slice::{AsSlice, SlicePrelude};
use str::{Str, StrPrelude};
use slice::SlicePrelude;
use str::StrPrelude;
use str;
use string::String;
use uint;
@ -316,7 +316,7 @@ impl IoError {
pub fn from_errno(errno: uint, detail: bool) -> IoError {
let mut err = sys::decode_error(errno as i32);
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())
}
err

View file

@ -236,8 +236,8 @@ impl Command {
// if the env is currently just inheriting from the parent's,
// materialize the parent's env into a hashtable.
self.env = Some(os::env_as_bytes().into_iter()
.map(|(k, v)| (EnvKey(k.as_slice().to_c_str()),
v.as_slice().to_c_str()))
.map(|(k, v)| (EnvKey(k.to_c_str()),
v.to_c_str()))
.collect());
self.env.as_mut().unwrap()
}
@ -973,7 +973,7 @@ mod tests {
let output = String::from_utf8(prog.wait_with_output().unwrap().output).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 child_stat = child_dir.stat().unwrap();
@ -991,7 +991,7 @@ mod tests {
let prog = pwd_cmd().cwd(&parent_dir).spawn().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 child_stat = child_dir.stat().unwrap();
@ -1031,8 +1031,7 @@ mod tests {
for &(ref k, ref v) in r.iter() {
// don't check windows magical empty-named variables
assert!(k.is_empty() ||
output.as_slice()
.contains(format!("{}={}", *k, *v).as_slice()),
output.contains(format!("{}={}", *k, *v).as_slice()),
"output doesn't contain `{}={}`\n{}",
k, v, output);
}
@ -1050,12 +1049,10 @@ mod tests {
for &(ref k, ref v) in r.iter() {
// don't check android RANDOM variables
if *k != "RANDOM".to_string() {
assert!(output.as_slice()
.contains(format!("{}={}",
assert!(output..contains(format!("{}={}",
*k,
*v).as_slice()) ||
output.as_slice()
.contains(format!("{}=\'{}\'",
output..contains(format!("{}=\'{}\'",
*k,
*v).as_slice()));
}
@ -1084,7 +1081,7 @@ mod tests {
let result = prog.wait_with_output().unwrap();
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);
}
@ -1094,7 +1091,7 @@ mod tests {
let result = prog.wait_with_output().unwrap();
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);
}

View file

@ -542,6 +542,6 @@ mod tests {
panic!("my special message");
});
let s = r.read_to_string().unwrap();
assert!(s.as_slice().contains("my special message"));
assert!(s.contains("my special message"));
}
}