Auto merge of #21680 - japaric:slice, r=alexcrichton

Replaces `slice_*` method calls with slicing syntax, and removes `as_slice()` calls that are redundant due to `Deref`.
This commit is contained in:
bors 2015-01-29 05:47:21 +00:00
commit bedd8108dc
59 changed files with 156 additions and 160 deletions

View file

@ -52,7 +52,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) {
Some(&(rn, val)) => {
total += val;
text = text.slice_from(rn.len());
text = &text[rn.len()..];
}
None => {
cx.span_err(sp, "invalid Roman numeral");

View file

@ -25,7 +25,7 @@ use std::vec;
fn main() {
let argv = os::args();
let _tests = argv.slice(1, argv.len());
let _tests = &argv[1..argv.len()];
macro_rules! bench {
($id:ident) =>

View file

@ -50,7 +50,7 @@ fn rotate(x: &mut [i32]) {
fn next_permutation(perm: &mut [i32], count: &mut [i32]) {
for i in range(1, perm.len()) {
rotate(perm.slice_to_mut(i + 1));
rotate(&mut perm[..i + 1]);
let count_i = &mut count[i];
if *count_i >= i as i32 {
*count_i = 0;
@ -127,7 +127,7 @@ impl Perm {
fn reverse(tperm: &mut [i32], k: uint) {
tperm.slice_to_mut(k).reverse()
tperm[..k].reverse()
}
fn work(mut perm: Perm, n: uint, max: uint) -> (i32, i32) {

View file

@ -126,7 +126,7 @@ impl<'a, W: Writer> RepeatFasta<'a, W> {
copy_memory(buf.as_mut_slice(), alu);
let buf_len = buf.len();
copy_memory(buf.slice_mut(alu_len, buf_len),
copy_memory(&mut buf[alu_len..buf_len],
&alu[..LINE_LEN]);
let mut pos = 0;
@ -134,7 +134,7 @@ impl<'a, W: Writer> RepeatFasta<'a, W> {
let mut n = n;
while n > 0 {
bytes = min(LINE_LEN, n);
try!(self.out.write(buf.slice(pos, pos + bytes)));
try!(self.out.write(&buf[pos..pos + bytes]));
try!(self.out.write_u8('\n' as u8));
pos += bytes;
if pos > alu_len {

View file

@ -184,7 +184,7 @@ fn main() {
let mut proc_mode = false;
for line in rdr.lines() {
let line = line.unwrap().as_slice().trim().to_string();
let line = line.unwrap().trim().to_string();
if line.len() == 0u { continue; }
@ -192,7 +192,7 @@ fn main() {
// start processing if this is the one
('>', false) => {
match line.as_slice().slice_from(1).find_str("THREE") {
match line[1..].find_str("THREE") {
Some(_) => { proc_mode = true; }
None => { }
}

View file

@ -283,9 +283,9 @@ fn print_occurrences(frequencies: &mut Table, occurrence: &'static str) {
fn get_sequence<R: Buffer>(r: &mut R, key: &str) -> Vec<u8> {
let mut res = Vec::new();
for l in r.lines().map(|l| l.ok().unwrap())
.skip_while(|l| key != l.as_slice().slice_to(key.len())).skip(1)
.skip_while(|l| key != &l[..key.len()]).skip(1)
{
res.push_all(l.as_slice().trim().as_bytes());
res.push_all(l.trim().as_bytes());
}
res.into_ascii_uppercase()
}

View file

@ -133,7 +133,7 @@ fn mandelbrot<W: old_io::Writer>(w: uint, mut out: W) -> old_io::IoResult<()> {
(i + 1) * chunk_size
};
for &init_i in vec_init_i.slice(start, end).iter() {
for &init_i in vec_init_i[start..end].iter() {
write_line(init_i, init_r_slice, &mut res);
}

View file

@ -173,7 +173,7 @@ fn main() {
let n = if std::os::getenv("RUST_BENCH").is_some() {
5000000
} else {
std::os::args().as_slice().get(1)
std::os::args().get(1)
.and_then(|arg| arg.parse())
.unwrap_or(1000)
};

View file

@ -55,7 +55,7 @@ fn parse_opts(argv: Vec<String> ) -> Config {
let opts = vec!(getopts::optflag("", "stress", ""));
let argv = argv.iter().map(|x| x.to_string()).collect::<Vec<_>>();
let opt_args = argv.slice(1, argv.len());
let opt_args = &argv[1..argv.len()];
match getopts::getopts(opt_args, opts.as_slice()) {
Ok(ref m) => {

View file

@ -155,7 +155,7 @@ impl<'a> Iterator for MutDnaSeqs<'a> {
fn next(&mut self) -> Option<&'a mut [u8]> {
let tmp = std::mem::replace(&mut self.s, &mut []);
let tmp = match memchr(tmp, b'\n') {
Some(i) => tmp.slice_from_mut(i + 1),
Some(i) => &mut tmp[i + 1..],
None => return None,
};
let (seq, tmp) = match memchr(tmp, b'>') {

View file

@ -10,7 +10,7 @@
fn main() {
let a = "".to_string();
let b: Vec<&str> = a.as_slice().lines().collect();
let b: Vec<&str> = a.lines().collect();
drop(a); //~ ERROR cannot move out of `a` because it is borrowed
for s in b.iter() {
println!("{}", *s);

View file

@ -10,7 +10,7 @@
fn read_lines_borrowed<'a>() -> Vec<&'a str> {
let raw_lines: Vec<String> = vec!("foo ".to_string(), " bar".to_string());
raw_lines.iter().map(|l| l.as_slice().trim()).collect()
raw_lines.iter().map(|l| l.trim()).collect()
//~^ ERROR `raw_lines` does not live long enough
}

View file

@ -11,7 +11,7 @@
fn read_lines_borrowed<'a>() -> Vec<&'a str> {
let rawLines: Vec<String> = vec!["foo ".to_string(), " bar".to_string()];
rawLines //~ ERROR `rawLines` does not live long enough
.iter().map(|l| l.as_slice().trim()).collect()
.iter().map(|l| l.trim()).collect()
}
fn main() {}

View file

@ -12,7 +12,7 @@ fn read_lines_borrowed1() -> Vec<
&str //~ ERROR missing lifetime specifier
> {
let rawLines: Vec<String> = vec!["foo ".to_string(), " bar".to_string()];
rawLines.iter().map(|l| l.as_slice().trim()).collect()
rawLines.iter().map(|l| l.trim()).collect()
}
fn main() {}

View file

@ -14,7 +14,7 @@ fn main() {
for
[x,y,z]
//~^ ERROR refutable pattern in `for` loop binding: `[]` not covered
in values.as_slice().chunks(3).filter(|&xs| xs.len() == 3) {
in values.chunks(3).filter(|&xs| xs.len() == 3) {
println!("y={}", y);
}
}

View file

@ -40,5 +40,5 @@ fn main() {
// positive test so that this test will be updated when the
// compiler changes.
assert!(err.as_slice().contains("unknown start of token"))
assert!(err.contains("unknown start of token"))
}

View file

@ -65,6 +65,6 @@ fn main() {
// positive test so that this test will be updated when the
// compiler changes.
assert!(err.as_slice().contains("expected item, found"))
assert!(err.contains("expected item, found"))
}
}

View file

@ -63,6 +63,6 @@ fn main() {
// the span should end the line (e.g no extra ~'s)
let expected_span = format!("^{}\n", repeat("~").take(n - 1)
.collect::<String>());
assert!(err.as_slice().contains(expected_span.as_slice()));
assert!(err.contains(expected_span.as_slice()));
}
}

View file

@ -78,9 +78,9 @@ fn runtest(me: &str) {
let s = str::from_utf8(out.error.as_slice()).unwrap();
let mut i = 0;
for _ in range(0i, 2) {
i += s.slice_from(i + 10).find_str("stack backtrace").unwrap() + 10;
i += s[i + 10..].find_str("stack backtrace").unwrap() + 10;
}
assert!(s.slice_from(i + 10).find_str("stack backtrace").is_none(),
assert!(s[i + 10..].find_str("stack backtrace").is_none(),
"bad output4: {}", s);
}

View file

@ -19,5 +19,5 @@ impl<'a> Foo for &'a [int] {
pub fn main() {
let items = vec!( 3, 5, 1, 2, 4 );
items.as_slice().foo();
items.foo();
}

View file

@ -52,7 +52,7 @@ pub fn main() {
}
let buf = vec!(97u8, 98, 99, 100);
assert_eq!(match buf.slice(0, 3) {
assert_eq!(match &buf[0..3] {
b"def" => 1u,
b"abc" => 2u,
_ => 3u

View file

@ -41,6 +41,6 @@ fn main() {
info!("info");
});
let s = r.read_to_string().unwrap();
assert!(s.as_slice().contains("info"));
assert!(!s.as_slice().contains("debug"));
assert!(s.contains("info"));
assert!(!s.contains("debug"));
}

View file

@ -10,7 +10,7 @@
fn main() {
let foo = "hello".to_string();
let foo: Vec<&str> = foo.as_slice().words().collect();
let foo: Vec<&str> = foo.words().collect();
let invalid_string = &foo[0];
assert_eq!(*invalid_string, "hello");
}

View file

@ -10,7 +10,7 @@
fn main() {
let args = vec!("foobie", "asdf::asdf");
let arr: Vec<&str> = args[1].as_slice().split_str("::").collect();
let arr: Vec<&str> = args[1].split_str("::").collect();
assert_eq!(arr[0], "asdf");
assert_eq!(arr[0], "asdf");
}

View file

@ -13,5 +13,5 @@
pub fn main() {
let s: String = "foobar".to_string();
let mut t: &str = s.as_slice();
t = t.slice(0, 3); // for master: str::view(t, 0, 3) maybe
t = &t[0..3]; // for master: str::view(t, 0, 3) maybe
}

View file

@ -18,7 +18,7 @@ pub fn main() {
assert_eq!(y, 6);
let s = "hello there".to_string();
let mut i: int = 0;
for c in s.as_slice().bytes() {
for c in s.bytes() {
if i == 0 { assert!((c == 'h' as u8)); }
if i == 1 { assert!((c == 'e' as u8)); }
if i == 2 { assert!((c == 'l' as u8)); }

View file

@ -44,6 +44,6 @@ fn main() {
let error = String::from_utf8_lossy(recurse.error.as_slice());
println!("wut");
println!("`{}`", error);
assert!(error.as_slice().contains("has overflowed its stack"));
assert!(error.contains("has overflowed its stack"));
}
}

View file

@ -42,6 +42,6 @@ fn main() {
let recurse = Command::new(args[0].as_slice()).arg("recurse").output().unwrap();
assert!(!recurse.status.success());
let error = String::from_utf8_lossy(recurse.error.as_slice());
assert!(error.as_slice().contains("has overflowed its stack"));
assert!(error.contains("has overflowed its stack"));
}
}

View file

@ -44,11 +44,11 @@ fn main() {
let silent = Command::new(args[0].as_slice()).arg("silent").output().unwrap();
assert!(!silent.status.success());
let error = String::from_utf8_lossy(silent.error.as_slice());
assert!(error.as_slice().contains("has overflowed its stack"));
assert!(error.contains("has overflowed its stack"));
let loud = Command::new(args[0].as_slice()).arg("loud").output().unwrap();
assert!(!loud.status.success());
let error = String::from_utf8_lossy(silent.error.as_slice());
assert!(error.as_slice().contains("has overflowed its stack"));
assert!(error.contains("has overflowed its stack"));
}
}

View file

@ -48,6 +48,6 @@ fn main() {
let result = prog.wait_with_output().unwrap();
let output = String::from_utf8_lossy(result.output.as_slice());
assert!(!output.as_slice().contains("RUN_TEST_NEW_ENV"),
assert!(!output.contains("RUN_TEST_NEW_ENV"),
"found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
}

View file

@ -29,12 +29,12 @@ pub fn main() {
assert_eq!(y, 6);
let x = vec!(1, 2, 3);
let y = x.as_slice().sum_();
let y = x.sum_();
println!("y=={}", y);
assert_eq!(y, 6);
let x = vec!(1, 2, 3);
let y = x.as_slice().sum_();
let y = x.sum_();
println!("y=={}", y);
assert_eq!(y, 6);
}

View file

@ -20,6 +20,6 @@ fn main() {
let segfault = Command::new(args[0].as_slice()).arg("segfault").output().unwrap();
assert!(!segfault.status.success());
let error = String::from_utf8_lossy(segfault.error.as_slice());
assert!(!error.as_slice().contains("has overflowed its stack"));
assert!(!error.contains("has overflowed its stack"));
}
}

View file

@ -40,7 +40,7 @@ pub fn main() {
include_bytes!("syntax-extension-source-utils-files/includeme.fragment")
[1] == (42 as u8)); // '*'
// The Windows tests are wrapped in an extra module for some reason
assert!((m1::m2::where_am_i().as_slice().ends_with("m1::m2")));
assert!((m1::m2::where_am_i().ends_with("m1::m2")));
assert!(match (45, "( 2 * 3 ) + 5") {
(line!(), stringify!((2*3) + 5)) => true,

View file

@ -26,5 +26,5 @@ fn main() {
assert!(res.is_err());
let output = reader.read_to_string().unwrap();
assert!(output.as_slice().contains("Hello, world!"));
assert!(output.contains("Hello, world!"));
}

View file

@ -44,7 +44,7 @@ pub fn main() {
fn check_str_eq(a: String, b: String) {
let mut i: int = 0;
for ab in a.as_slice().bytes() {
for ab in a.bytes() {
println!("{}", i);
println!("{}", ab);
let bb: u8 = b.as_bytes()[i as uint];

View file

@ -10,7 +10,7 @@
pub fn main() {
let v = vec!(1i,2,3,4,5);
let v2 = v.slice(1, 3);
let v2 = &v[1..3];
assert_eq!(v2[0], 2);
assert_eq!(v2[1], 3);
}

View file

@ -31,8 +31,8 @@ pub fn main() {
unreachable!();
}
[Foo { string: ref a }, Foo { string: ref b }] => {
assert_eq!("bar", a.as_slice().slice(0, a.len()));
assert_eq!("baz", b.as_slice().slice(0, b.len()));
assert_eq!("bar", &a[0..a.len()]);
assert_eq!("baz", &b[0..b.len()]);
}
_ => {
unreachable!();