From c1d48a85082cfe3683ad9eda5223d3259d4fa718 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 12 Jan 2015 16:59:18 -0500 Subject: [PATCH] cleanup: `&foo[0..a]` -> `&foo[..a]` --- src/libcollections/slice.rs | 12 ++++----- src/libcollections/str.rs | 2 +- src/libcollections/string.rs | 2 +- src/libcore/fmt/float.rs | 2 +- src/libcore/fmt/mod.rs | 4 +-- src/libcore/slice.rs | 12 ++++----- src/libcore/str/mod.rs | 6 ++--- src/libcoretest/char.rs | 4 +-- src/libcoretest/iter.rs | 20 +++++++-------- src/libfmt_macros/lib.rs | 4 +-- src/librand/lib.rs | 3 +-- src/librbml/io.rs | 2 +- src/librustc/middle/check_match.rs | 2 +- src/librustc/util/ppaux.rs | 2 +- src/librustc_back/sha2.rs | 4 +-- src/librustc_resolve/lib.rs | 2 +- src/librustc_trans/back/lto.rs | 2 +- src/librustc_trans/save/mod.rs | 2 +- src/librustc_trans/save/recorder.rs | 2 +- src/librustc_trans/trans/_match.rs | 2 +- src/librustc_trans/trans/builder.rs | 2 +- src/librustc_trans/trans/debuginfo.rs | 2 +- src/librustdoc/html/format.rs | 4 +-- src/libserialize/json.rs | 4 +-- src/libstd/io/buffered.rs | 6 ++--- src/libstd/io/comm_adapters.rs | 2 +- src/libstd/io/fs.rs | 2 +- src/libstd/io/mem.rs | 10 ++++---- src/libstd/io/mod.rs | 6 ++--- src/libstd/io/net/ip.rs | 2 +- src/libstd/io/util.rs | 6 ++--- src/libstd/path/mod.rs | 6 ++--- src/libstd/path/posix.rs | 6 ++--- src/libstd/path/windows.rs | 34 +++++++++++++------------- src/libstd/rt/unwind.rs | 2 +- src/libstd/rt/util.rs | 4 +-- src/libstd/sys/windows/os.rs | 2 +- src/libsyntax/ast_map/mod.rs | 2 +- src/libsyntax/codemap.rs | 2 +- src/libsyntax/diagnostic.rs | 2 +- src/test/bench/shootout-fasta-redux.rs | 4 +-- src/test/run-pass/issue-17503.rs | 2 +- src/test/run-pass/issue-8898.rs | 2 +- src/test/run-pass/slice-2.rs | 4 +-- 44 files changed, 104 insertions(+), 105 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 9a1f22ef7a6..4812ecc2c0b 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1631,7 +1631,7 @@ mod tests { #[test] fn test_slice_from() { let vec: &[int] = &[1, 2, 3, 4]; - assert_eq!(&vec[0..], vec); + assert_eq!(&vec[], vec); let b: &[int] = &[3, 4]; assert_eq!(&vec[2..], b); let b: &[int] = &[]; @@ -1641,11 +1641,11 @@ mod tests { #[test] fn test_slice_to() { let vec: &[int] = &[1, 2, 3, 4]; - assert_eq!(&vec[0..4], vec); + assert_eq!(&vec[..4], vec); let b: &[int] = &[1, 2]; - assert_eq!(&vec[0..2], b); + assert_eq!(&vec[..2], b); let b: &[int] = &[]; - assert_eq!(&vec[0..0], b); + assert_eq!(&vec[..0], b); } @@ -2538,7 +2538,7 @@ mod tests { let (left, right) = values.split_at_mut(2); { let left: &[_] = left; - assert!(left[0..left.len()] == [1, 2][]); + assert!(left[..left.len()] == [1, 2][]); } for p in left.iter_mut() { *p += 1; @@ -2546,7 +2546,7 @@ mod tests { { let right: &[_] = right; - assert!(right[0..right.len()] == [3, 4, 5][]); + assert!(right[..right.len()] == [3, 4, 5][]); } for p in right.iter_mut() { *p += 2; diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index ccf654ac0a0..96c73981e36 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -807,7 +807,7 @@ pub trait StrExt: Index { /// out of bounds. /// /// See also `slice`, `slice_from` and `slice_chars`. - #[unstable = "use slice notation [0..a] instead"] + #[unstable = "use slice notation [..a] instead"] fn slice_to(&self, end: uint) -> &str { core_str::StrExt::slice_to(&self[], end) } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index e30e7e8600d..c845d86ca0f 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -168,7 +168,7 @@ impl String { if i > 0 { unsafe { - res.as_mut_vec().push_all(&v[0..i]) + res.as_mut_vec().push_all(&v[..i]) }; } diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 0ffcb014c28..f1b9ebe6d90 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -332,5 +332,5 @@ pub fn float_to_str_bytes_common( } } - f(unsafe { str::from_utf8_unchecked(&buf[0..end]) }) + f(unsafe { str::from_utf8_unchecked(&buf[..end]) }) } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index a0ec9e5f151..20ac3e28c97 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -449,7 +449,7 @@ impl<'a> Formatter<'a> { for c in sign.into_iter() { let mut b = [0; 4]; let n = c.encode_utf8(&mut b).unwrap_or(0); - let b = unsafe { str::from_utf8_unchecked(&b[0..n]) }; + let b = unsafe { str::from_utf8_unchecked(&b[..n]) }; try!(f.buf.write_str(b)); } if prefixed { f.buf.write_str(prefix) } @@ -692,7 +692,7 @@ impl String for char { fn fmt(&self, f: &mut Formatter) -> Result { let mut utf8 = [0u8; 4]; let amt = self.encode_utf8(&mut utf8).unwrap_or(0); - let s: &str = unsafe { mem::transmute(&utf8[0..amt]) }; + let s: &str = unsafe { mem::transmute(&utf8[..amt]) }; String::fmt(s, f) } } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 7e47c5257a3..22da168911d 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -159,7 +159,7 @@ impl SliceExt for [T] { #[inline] fn split_at(&self, mid: uint) -> (&[T], &[T]) { - (&self[0..mid], &self[mid..]) + (&self[..mid], &self[mid..]) } #[inline] @@ -240,7 +240,7 @@ impl SliceExt for [T] { #[inline] fn init(&self) -> &[T] { - &self[0..(self.len() - 1)] + &self[..(self.len() - 1)] } #[inline] @@ -443,7 +443,7 @@ impl SliceExt for [T] { #[inline] fn starts_with(&self, needle: &[T]) -> bool where T: PartialEq { let n = needle.len(); - self.len() >= n && needle == &self[0..n] + self.len() >= n && needle == &self[..n] } #[inline] @@ -972,7 +972,7 @@ impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool { match self.v.iter().position(|x| (self.pred)(x)) { None => self.finish(), Some(idx) => { - let ret = Some(&self.v[0..idx]); + let ret = Some(&self.v[..idx]); self.v = &self.v[(idx + 1)..]; ret } @@ -999,7 +999,7 @@ impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> boo None => self.finish(), Some(idx) => { let ret = Some(&self.v[(idx + 1)..]); - self.v = &self.v[0..idx]; + self.v = &self.v[..idx]; ret } } @@ -1195,7 +1195,7 @@ impl<'a, T> Iterator for Windows<'a, T> { if self.size > self.v.len() { None } else { - let ret = Some(&self.v[0..self.size]); + let ret = Some(&self.v[..self.size]); self.v = &self.v[1..]; ret } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 94ee9b7dcf6..d9cf6dc086d 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -701,10 +701,10 @@ impl TwoWaySearcher { // // What's going on is we have some critical factorization (u, v) of the // needle, and we want to determine whether u is a suffix of - // &v[0..period]. If it is, we use "Algorithm CP1". Otherwise we use + // &v[..period]. If it is, we use "Algorithm CP1". Otherwise we use // "Algorithm CP2", which is optimized for when the period of the needle // is large. - if &needle[0..crit_pos] == &needle[period.. period + crit_pos] { + if &needle[..crit_pos] == &needle[period.. period + crit_pos] { TwoWaySearcher { crit_pos: crit_pos, period: period, @@ -1412,7 +1412,7 @@ impl StrExt for str { #[inline] fn starts_with(&self, needle: &str) -> bool { let n = needle.len(); - self.len() >= n && needle.as_bytes() == &self.as_bytes()[0..n] + self.len() >= n && needle.as_bytes() == &self.as_bytes()[..n] } #[inline] diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index 7b6b4f84808..2e29b1c41c4 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -167,7 +167,7 @@ fn test_encode_utf8() { fn check(input: char, expect: &[u8]) { let mut buf = [0u8; 4]; let n = input.encode_utf8(buf.as_mut_slice()).unwrap_or(0); - assert_eq!(&buf[0..n], expect); + assert_eq!(&buf[..n], expect); } check('x', &[0x78]); @@ -181,7 +181,7 @@ fn test_encode_utf16() { fn check(input: char, expect: &[u16]) { let mut buf = [0u16; 2]; let n = input.encode_utf16(buf.as_mut_slice()).unwrap_or(0); - assert_eq!(&buf[0..n], expect); + assert_eq!(&buf[..n], expect); } check('x', &[0x0078]); diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 61266a92649..26819bf9209 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -288,7 +288,7 @@ fn test_iterator_len() { let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().count(), 4); assert_eq!(v[..10].iter().count(), 10); - assert_eq!(v[0..0].iter().count(), 0); + assert_eq!(v[..0].iter().count(), 0); } #[test] @@ -296,31 +296,31 @@ fn test_iterator_sum() { let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().map(|&x| x).sum(), 6); assert_eq!(v.iter().map(|&x| x).sum(), 55); - assert_eq!(v[0..0].iter().map(|&x| x).sum(), 0); + assert_eq!(v[..0].iter().map(|&x| x).sum(), 0); } #[test] fn test_iterator_product() { let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - assert_eq!(v[0..4].iter().map(|&x| x).product(), 0); + assert_eq!(v[..4].iter().map(|&x| x).product(), 0); assert_eq!(v[1..5].iter().map(|&x| x).product(), 24); - assert_eq!(v[0..0].iter().map(|&x| x).product(), 1); + assert_eq!(v[..0].iter().map(|&x| x).product(), 1); } #[test] fn test_iterator_max() { let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - assert_eq!(v[0..4].iter().map(|&x| x).max(), Some(3)); + assert_eq!(v[..4].iter().map(|&x| x).max(), Some(3)); assert_eq!(v.iter().map(|&x| x).max(), Some(10)); - assert_eq!(v[0..0].iter().map(|&x| x).max(), None); + assert_eq!(v[..0].iter().map(|&x| x).max(), None); } #[test] fn test_iterator_min() { let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - assert_eq!(v[0..4].iter().map(|&x| x).min(), Some(0)); + assert_eq!(v[..4].iter().map(|&x| x).min(), Some(0)); assert_eq!(v.iter().map(|&x| x).min(), Some(0)); - assert_eq!(v[0..0].iter().map(|&x| x).min(), None); + assert_eq!(v[..0].iter().map(|&x| x).min(), None); } #[test] @@ -373,7 +373,7 @@ fn test_all() { assert!(v.iter().all(|&x| x < 10)); assert!(!v.iter().all(|&x| x % 2 == 0)); assert!(!v.iter().all(|&x| x > 100)); - assert!(v[0..0].iter().all(|_| panic!())); + assert!(v[..0].iter().all(|_| panic!())); } #[test] @@ -382,7 +382,7 @@ fn test_any() { assert!(v.iter().any(|&x| x < 10)); assert!(v.iter().any(|&x| x % 2 == 0)); assert!(!v.iter().any(|&x| x > 100)); - assert!(!v[0..0].iter().any(|_| panic!())); + assert!(!v[..0].iter().any(|_| panic!())); } #[test] diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 70ad8d28d27..85944ccc551 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -286,7 +286,7 @@ impl<'a> Parser<'a> { flags: 0, precision: CountImplied, width: CountImplied, - ty: &self.input[0..0], + ty: &self.input[..0], }; if !self.consume(':') { return spec } @@ -395,7 +395,7 @@ impl<'a> Parser<'a> { self.cur.next(); pos } - Some(..) | None => { return &self.input[0..0]; } + Some(..) | None => { return &self.input[..0]; } }; let mut end; loop { diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 4d605253ab0..8430ee81c32 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -270,8 +270,7 @@ pub trait Rng : Sized { /// let choices = [1i, 2, 4, 8, 16, 32]; /// let mut rng = thread_rng(); /// println!("{:?}", rng.choose(&choices)); - /// # // uncomment when slicing syntax is stable - /// //assert_eq!(rng.choose(&choices[0..0]), None); + /// assert_eq!(rng.choose(&choices[..0]), None); /// ``` fn choose<'a, T>(&mut self, values: &'a [T]) -> Option<&'a T> { if values.is_empty() { diff --git a/src/librbml/io.rs b/src/librbml/io.rs index bdc00d7db97..f39860c8695 100644 --- a/src/librbml/io.rs +++ b/src/librbml/io.rs @@ -95,7 +95,7 @@ impl Writer for SeekableMemWriter { // there (left), and what will be appended on the end (right) let cap = self.buf.len() - self.pos; let (left, right) = if cap <= buf.len() { - (&buf[0..cap], &buf[cap..]) + (&buf[..cap], &buf[cap..]) } else { let result: (_, &[_]) = (buf, &[]); result diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 43f39a67f5c..a1a90395b3b 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -926,7 +926,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], } }; head.map(|mut head| { - head.push_all(&r[0..col]); + head.push_all(&r[..col]); head.push_all(&r[(col + 1)..]); head }) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 559ec533baa..1a1ad899d4e 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -542,7 +542,7 @@ pub fn parameterized<'tcx>(cx: &ctxt<'tcx>, 0 }; - for t in tps[0..(tps.len() - num_defaults)].iter() { + for t in tps[..(tps.len() - num_defaults)].iter() { strs.push(ty_to_string(cx, *t)) } diff --git a/src/librustc_back/sha2.rs b/src/librustc_back/sha2.rs index ac5662f534c..e376ac50dcd 100644 --- a/src/librustc_back/sha2.rs +++ b/src/librustc_back/sha2.rs @@ -140,7 +140,7 @@ impl FixedBuffer for FixedBuffer64 { if input.len() >= buffer_remaining { copy_memory( self.buffer.slice_mut(self.buffer_idx, size), - &input[0..buffer_remaining]); + &input[..buffer_remaining]); self.buffer_idx = 0; func(&self.buffer); i += buffer_remaining; @@ -188,7 +188,7 @@ impl FixedBuffer for FixedBuffer64 { fn full_buffer<'s>(&'s mut self) -> &'s [u8] { assert!(self.buffer_idx == 64); self.buffer_idx = 0; - return &self.buffer[0..64]; + return &self.buffer[..64]; } fn position(&self) -> uint { self.buffer_idx } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ea6ecfbb92b..ae55f8fb3aa 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2081,7 +2081,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // idx +- 1 to account for the // colons on either side &mpath[(idx + 1)..], - &mpath[0..(idx - 1)]); + &mpath[..(idx - 1)]); return Failed(Some((span, msg))); }, None => { diff --git a/src/librustc_trans/back/lto.rs b/src/librustc_trans/back/lto.rs index b6a6b526fac..d7148bdaa1f 100644 --- a/src/librustc_trans/back/lto.rs +++ b/src/librustc_trans/back/lto.rs @@ -186,7 +186,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef, fn is_versioned_bytecode_format(bc: &[u8]) -> bool { let magic_id_byte_count = link::RLIB_BYTECODE_OBJECT_MAGIC.len(); return bc.len() > magic_id_byte_count && - &bc[0..magic_id_byte_count] == link::RLIB_BYTECODE_OBJECT_MAGIC; + &bc[..magic_id_byte_count] == link::RLIB_BYTECODE_OBJECT_MAGIC; } fn extract_bytecode_format_version(bc: &[u8]) -> u32 { diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 1bd8e018174..815a6fe846d 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -186,7 +186,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { if len <= 2 { return; } - let sub_paths = &sub_paths[0..(len-2)]; + let sub_paths = &sub_paths[..(len-2)]; for &(ref span, ref qualname) in sub_paths.iter() { self.fmt.sub_mod_ref_str(path.span, *span, diff --git a/src/librustc_trans/save/recorder.rs b/src/librustc_trans/save/recorder.rs index 23598751c08..11f8fbbaf11 100644 --- a/src/librustc_trans/save/recorder.rs +++ b/src/librustc_trans/save/recorder.rs @@ -166,7 +166,7 @@ impl<'a> FmtStrs<'a> { let values = values.iter().map(|s| { // Never take more than 1020 chars if s.len() > 1020 { - &s[0..1020] + &s[..1020] } else { &s[] } diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index fc19a582db2..f182045efd2 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -471,7 +471,7 @@ fn enter_default<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Collect all of the matches that can match against anything. enter_match(bcx, dm, m, col, val, |pats| { if pat_is_binding_or_wild(dm, &*pats[col]) { - let mut r = pats[0..col].to_vec(); + let mut r = pats[..col].to_vec(); r.push_all(&pats[(col + 1)..]); Some(r) } else { diff --git a/src/librustc_trans/trans/builder.rs b/src/librustc_trans/trans/builder.rs index b80088e4690..75194e3d21f 100644 --- a/src/librustc_trans/trans/builder.rs +++ b/src/librustc_trans/trans/builder.rs @@ -552,7 +552,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { for (small_vec_e, &ix) in small_vec.iter_mut().zip(ixs.iter()) { *small_vec_e = C_i32(self.ccx, ix as i32); } - self.inbounds_gep(base, &small_vec[0..ixs.len()]) + self.inbounds_gep(base, &small_vec[..ixs.len()]) } else { let v = ixs.iter().map(|i| C_i32(self.ccx, *i as i32)).collect::>(); self.count_insn("gepi"); diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 2f58baab7fc..f2fb0863b5a 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -962,7 +962,7 @@ pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let variable_access = IndirectVariable { alloca: env_pointer, - address_operations: &address_operations[0..address_op_count] + address_operations: &address_operations[..address_op_count] }; declare_local(bcx, diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 00f7c570b5d..bfa35448028 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -332,7 +332,7 @@ fn path(w: &mut fmt::Formatter, match rel_root { Some(root) => { let mut root = String::from_str(root.as_slice()); - for seg in path.segments[0..amt].iter() { + for seg in path.segments[..amt].iter() { if "super" == seg.name || "self" == seg.name { try!(write!(w, "{}::", seg.name)); @@ -347,7 +347,7 @@ fn path(w: &mut fmt::Formatter, } } None => { - for seg in path.segments[0..amt].iter() { + for seg in path.segments[..amt].iter() { try!(write!(w, "{}::", seg.name)); } } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 62acef2ca1c..41499b5ae0e 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -401,7 +401,7 @@ fn escape_str(wr: &mut fmt::Writer, v: &str) -> fmt::Result { fn escape_char(writer: &mut fmt::Writer, v: char) -> fmt::Result { let mut buf = [0; 4]; let n = v.encode_utf8(&mut buf).unwrap(); - let buf = unsafe { str::from_utf8_unchecked(&buf[0..n]) }; + let buf = unsafe { str::from_utf8_unchecked(&buf[..n]) }; escape_str(writer, buf) } @@ -414,7 +414,7 @@ fn spaces(wr: &mut fmt::Writer, mut n: uint) -> fmt::Result { } if n > 0 { - wr.write_str(&BUF[0..n]) + wr.write_str(&BUF[..n]) } else { Ok(()) } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 36def48b88b..60e2641ed8c 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -122,7 +122,7 @@ impl Reader for BufferedReader { let nread = { let available = try!(self.fill_buf()); let nread = cmp::min(available.len(), buf.len()); - slice::bytes::copy_memory(buf, &available[0..nread]); + slice::bytes::copy_memory(buf, &available[..nread]); nread }; self.pos += nread; @@ -183,7 +183,7 @@ impl BufferedWriter { fn flush_buf(&mut self) -> IoResult<()> { if self.pos != 0 { - let ret = self.inner.as_mut().unwrap().write(&self.buf[0..self.pos]); + let ret = self.inner.as_mut().unwrap().write(&self.buf[..self.pos]); self.pos = 0; ret } else { @@ -282,7 +282,7 @@ impl Writer for LineBufferedWriter { fn write(&mut self, buf: &[u8]) -> IoResult<()> { match buf.iter().rposition(|&b| b == b'\n') { Some(i) => { - try!(self.inner.write(&buf[0..(i + 1)])); + try!(self.inner.write(&buf[..(i + 1)])); try!(self.inner.flush()); try!(self.inner.write(&buf[(i + 1)..])); Ok(()) diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index b578f4d5adc..4b0014c68f7 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -90,7 +90,7 @@ impl Reader for ChanReader { Some(src) => { let dst = buf.slice_from_mut(num_read); let count = cmp::min(src.len(), dst.len()); - bytes::copy_memory(dst, &src[0..count]); + bytes::copy_memory(dst, &src[..count]); count }, None => 0, diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index dbccc81c4cc..64406d88253 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -889,7 +889,7 @@ mod test { let mut read_buf = [0; 1028]; let read_str = match check!(read_stream.read(&mut read_buf)) { -1|0 => panic!("shouldn't happen"), - n => str::from_utf8(&read_buf[0..n]).unwrap().to_string() + n => str::from_utf8(&read_buf[..n]).unwrap().to_string() }; assert_eq!(read_str.as_slice(), message); } diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index c5e289398e0..ee05a9e5596 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -204,7 +204,7 @@ impl<'a> Reader for &'a [u8] { let write_len = min(buf.len(), self.len()); { - let input = &self[0..write_len]; + let input = &self[..write_len]; let output = buf.slice_to_mut(write_len); slice::bytes::copy_memory(output, input); } @@ -286,7 +286,7 @@ impl<'a> Writer for BufWriter<'a> { Ok(()) } else { - slice::bytes::copy_memory(dst, &src[0..dst_len]); + slice::bytes::copy_memory(dst, &src[..dst_len]); self.pos += dst_len; @@ -498,7 +498,7 @@ mod test { assert_eq!(buf, b); assert_eq!(reader.read(&mut buf), Ok(3)); let b: &[_] = &[5, 6, 7]; - assert_eq!(&buf[0..3], b); + assert_eq!(&buf[..3], b); assert!(reader.read(&mut buf).is_err()); let mut reader = MemReader::new(vec!(0, 1, 2, 3, 4, 5, 6, 7)); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); @@ -524,7 +524,7 @@ mod test { assert_eq!(buf.as_slice(), b); assert_eq!(reader.read(&mut buf), Ok(3)); let b: &[_] = &[5, 6, 7]; - assert_eq!(&buf[0..3], b); + assert_eq!(&buf[..3], b); assert!(reader.read(&mut buf).is_err()); let mut reader = &mut in_buf.as_slice(); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); @@ -551,7 +551,7 @@ mod test { assert_eq!(buf, b); assert_eq!(reader.read(&mut buf), Ok(3)); let b: &[_] = &[5, 6, 7]; - assert_eq!(&buf[0..3], b); + assert_eq!(&buf[..3], b); assert!(reader.read(&mut buf).is_err()); let mut reader = BufReader::new(in_buf.as_slice()); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 3968dda2a82..bab4dafd090 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1069,7 +1069,7 @@ pub trait Writer { fn write_char(&mut self, c: char) -> IoResult<()> { let mut buf = [0u8; 4]; let n = c.encode_utf8(buf.as_mut_slice()).unwrap_or(0); - self.write(&buf[0..n]) + self.write(&buf[..n]) } /// Write the result of passing n through `int::to_str_bytes`. @@ -1454,7 +1454,7 @@ pub trait Buffer: Reader { }; match available.iter().position(|&b| b == byte) { Some(i) => { - res.push_all(&available[0..(i + 1)]); + res.push_all(&available[..(i + 1)]); used = i + 1; break } @@ -1493,7 +1493,7 @@ pub trait Buffer: Reader { } } } - match str::from_utf8(&buf[0..width]).ok() { + match str::from_utf8(&buf[..width]).ok() { Some(s) => Ok(s.char_at(0)), None => Err(standard_error(InvalidInput)) } diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index d09afea94dc..adc122ff447 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -313,7 +313,7 @@ impl<'a> Parser<'a> { let mut tail = [0u16; 8]; let (tail_size, _) = read_groups(self, &mut tail, 8 - head_size); - Some(ipv6_addr_from_head_tail(&head[0..head_size], &tail[0..tail_size])) + Some(ipv6_addr_from_head_tail(&head[..head_size], &tail[..tail_size])) } fn read_ipv6_addr(&mut self) -> Option { diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index ac7fb3f9cdb..adfd88644cc 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -60,7 +60,7 @@ impl Reader for LimitReader { impl Buffer for LimitReader { fn fill_buf<'a>(&'a mut self) -> io::IoResult<&'a [u8]> { let amt = try!(self.inner.fill_buf()); - let buf = &amt[0..cmp::min(amt.len(), self.limit)]; + let buf = &amt[..cmp::min(amt.len(), self.limit)]; if buf.len() == 0 { Err(io::standard_error(io::EndOfFile)) } else { @@ -223,7 +223,7 @@ impl TeeReader { impl Reader for TeeReader { fn read(&mut self, buf: &mut [u8]) -> io::IoResult { self.reader.read(buf).and_then(|len| { - self.writer.write(&mut buf[0..len]).map(|()| len) + self.writer.write(&mut buf[..len]).map(|()| len) }) } } @@ -237,7 +237,7 @@ pub fn copy(r: &mut R, w: &mut W) -> io::IoResult<()> { Err(ref e) if e.kind == io::EndOfFile => return Ok(()), Err(e) => return Err(e), }; - try!(w.write(&buf[0..len])); + try!(w.write(&buf[..len])); } } diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 1ec7b6b3edc..541f1e77140 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -352,7 +352,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { match name.rposition_elem(&dot) { None | Some(0) => name, Some(1) if name == b".." => name, - Some(pos) => &name[0..pos] + Some(pos) => &name[..pos] } }) } @@ -475,7 +475,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let extlen = extension.container_as_bytes().len(); match (name.rposition_elem(&dot), extlen) { (None, 0) | (Some(0), 0) => None, - (Some(idx), 0) => Some(name[0..idx].to_vec()), + (Some(idx), 0) => Some(name[..idx].to_vec()), (idx, extlen) => { let idx = match idx { None | Some(0) => name.len(), @@ -484,7 +484,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let mut v; v = Vec::with_capacity(idx + extlen + 1); - v.push_all(&name[0..idx]); + v.push_all(&name[..idx]); v.push(dot); v.push_all(extension.container_as_bytes()); Some(v) diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 293696d5cca..aab64639ab5 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -136,7 +136,7 @@ impl GenericPathUnsafe for Path { } Some(idx) => { let mut v = Vec::with_capacity(idx + 1 + filename.len()); - v.push_all(&self.repr[0..(idx+1)]); + v.push_all(&self.repr[..(idx+1)]); v.push_all(filename); // FIXME: this is slow self.repr = Path::normalize(v.as_slice()); @@ -177,9 +177,9 @@ impl GenericPath for Path { match self.sepidx { None if b".." == self.repr => self.repr.as_slice(), None => dot_static, - Some(0) => &self.repr[0..1], + Some(0) => &self.repr[..1], Some(idx) if &self.repr[(idx+1)..] == b".." => self.repr.as_slice(), - Some(idx) => &self.repr[0..idx] + Some(idx) => &self.repr[..idx] } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 2a1f1794e49..3cff1c67be3 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -180,20 +180,20 @@ impl GenericPathUnsafe for Path { } Some((_,idxa,end)) if &self.repr[idxa..end] == ".." => { let mut s = String::with_capacity(end + 1 + filename.len()); - s.push_str(&self.repr[0..end]); + s.push_str(&self.repr[..end]); s.push(SEP); s.push_str(filename); self.update_normalized(&s[]); } Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => { let mut s = String::with_capacity(idxb + filename.len()); - s.push_str(&self.repr[0..idxb]); + s.push_str(&self.repr[..idxb]); s.push_str(filename); self.update_normalized(&s[]); } Some((idxb,_,_)) => { let mut s = String::with_capacity(idxb + 1 + filename.len()); - s.push_str(&self.repr[0..idxb]); + s.push_str(&self.repr[..idxb]); s.push(SEP); s.push_str(filename); self.update_normalized(&s[]); @@ -350,13 +350,13 @@ impl GenericPath for Path { Some((idxb,_,end)) if &self.repr[idxb..end] == "\\" => { &self.repr[] } - Some((0,idxa,_)) => &self.repr[0..idxa], + Some((0,idxa,_)) => &self.repr[..idxa], Some((idxb,idxa,_)) => { match self.prefix { Some(DiskPrefix) | Some(VerbatimDiskPrefix) if idxb == self.prefix_len() => { - &self.repr[0..idxa] + &self.repr[..idxa] } - _ => &self.repr[0..idxb] + _ => &self.repr[..idxb] } } }) @@ -428,15 +428,15 @@ impl GenericPath for Path { if self.prefix.is_some() { Some(Path::new(match self.prefix { Some(DiskPrefix) if self.is_absolute() => { - &self.repr[0..(self.prefix_len()+1)] + &self.repr[..(self.prefix_len()+1)] } Some(VerbatimDiskPrefix) => { - &self.repr[0..(self.prefix_len()+1)] + &self.repr[..(self.prefix_len()+1)] } - _ => &self.repr[0..self.prefix_len()] + _ => &self.repr[..self.prefix_len()] })) } else if is_vol_relative(self) { - Some(Path::new(&self.repr[0..1])) + Some(Path::new(&self.repr[..1])) } else { None } @@ -683,7 +683,7 @@ impl Path { } (None, None) => true, (a, b) if a == b => { - &s_repr[0..self.prefix_len()] == &o_repr[0..other.prefix_len()] + &s_repr[..self.prefix_len()] == &o_repr[..other.prefix_len()] } _ => false } @@ -737,7 +737,7 @@ impl Path { match prefix.unwrap() { DiskPrefix => { let len = prefix_len(prefix) + is_abs as uint; - let mut s = String::from_str(&s[0..len]); + let mut s = String::from_str(&s[..len]); unsafe { let v = s.as_mut_vec(); v[0] = (*v)[0].to_ascii_uppercase(); @@ -752,7 +752,7 @@ impl Path { } VerbatimDiskPrefix => { let len = prefix_len(prefix) + is_abs as uint; - let mut s = String::from_str(&s[0..len]); + let mut s = String::from_str(&s[..len]); unsafe { let v = s.as_mut_vec(); v[4] = (*v)[4].to_ascii_uppercase(); @@ -762,14 +762,14 @@ impl Path { _ => { let plen = prefix_len(prefix); if s.len() > plen { - Some(String::from_str(&s[0..plen])) + Some(String::from_str(&s[..plen])) } else { None } } } } else if is_abs && comps.is_empty() { Some(repeat(SEP).take(1).collect()) } else { - let prefix_ = &s[0..prefix_len(prefix)]; + let prefix_ = &s[..prefix_len(prefix)]; let n = prefix_.len() + if is_abs { comps.len() } else { comps.len() - 1} + comps.iter().map(|v| v.len()).sum(); @@ -780,7 +780,7 @@ impl Path { s.push(':'); } Some(VerbatimDiskPrefix) => { - s.push_str(&prefix_[0..4]); + s.push_str(&prefix_[..4]); s.push(prefix_.as_bytes()[4].to_ascii_uppercase() as char); s.push_str(&prefix_[5..]); } @@ -813,7 +813,7 @@ impl Path { fn update_sepidx(&mut self) { let s = if self.has_nonsemantic_trailing_slash() { - &self.repr[0..(self.repr.len()-1)] + &self.repr[..(self.repr.len()-1)] } else { &self.repr[] }; let sep_test: fn(char) -> bool = if !prefix_is_verbatim(self.prefix) { is_sep diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 4cd0b29688a..79a70b50bcf 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -544,7 +544,7 @@ fn begin_unwind_inner(msg: Box, file_line: &(&'static str, uint)) -> // MAX_CALLBACKS, so we're sure to clamp it as necessary. let callbacks = { let amt = CALLBACK_CNT.load(Ordering::SeqCst); - &CALLBACKS[0..cmp::min(amt, MAX_CALLBACKS)] + &CALLBACKS[..cmp::min(amt, MAX_CALLBACKS)] }; for cb in callbacks.iter() { match cb.load(Ordering::SeqCst) { diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index c076f0a7c6c..aebf1b1179e 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -131,7 +131,7 @@ pub fn abort(args: fmt::Arguments) -> ! { impl<'a> fmt::Writer for BufWriter<'a> { fn write_str(&mut self, bytes: &str) -> fmt::Result { let left = self.buf.slice_from_mut(self.pos); - let to_write = &bytes.as_bytes()[0..cmp::min(bytes.len(), left.len())]; + let to_write = &bytes.as_bytes()[..cmp::min(bytes.len(), left.len())]; slice::bytes::copy_memory(left, to_write); self.pos += to_write.len(); Ok(()) @@ -142,7 +142,7 @@ pub fn abort(args: fmt::Arguments) -> ! { let mut msg = [0u8; 512]; let mut w = BufWriter { buf: &mut msg, pos: 0 }; let _ = write!(&mut w, "{}", args); - let msg = str::from_utf8(&w.buf[0..w.pos]).unwrap_or("aborted"); + let msg = str::from_utf8(&w.buf[..w.pos]).unwrap_or("aborted"); let msg = if msg.is_empty() {"aborted"} else {msg}; // Give some context to the message diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 064633f321c..4540068133b 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -36,7 +36,7 @@ const BUF_BYTES : uint = 2048u; pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { match v.iter().position(|c| *c == 0) { // don't include the 0 - Some(i) => &v[0..i], + Some(i) => &v[..i], None => v } } diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 3ef57279175..d4fc5f2dd1a 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -513,7 +513,7 @@ impl<'ast> Map<'ast> { NodesMatchingSuffix { map: self, item_name: parts.last().unwrap(), - in_which: &parts[0..(parts.len() - 1)], + in_which: &parts[..(parts.len() - 1)], idx: 0, } } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 9a422e17bb4..bf26687deed 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -313,7 +313,7 @@ impl FileMap { let begin = begin.to_uint(); let slice = &self.src[begin..]; match slice.find('\n') { - Some(e) => &slice[0..e], + Some(e) => &slice[..e], None => slice }.to_string() }) diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 3f81dac2b0d..dfef5287260 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -277,7 +277,7 @@ fn print_maybe_styled(w: &mut EmitterWriter, // to be miscolored. We assume this is rare enough that we don't // have to worry about it. if msg.ends_with("\n") { - try!(t.write_str(&msg[0..(msg.len()-1)])); + try!(t.write_str(&msg[..(msg.len()-1)])); try!(t.reset()); try!(t.write_str("\n")); } else { diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 5a47f9fbc57..9e5618579e4 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -128,7 +128,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), - &alu[0..LINE_LEN]); + &alu[..LINE_LEN]); let mut pos = 0; let mut bytes; @@ -204,7 +204,7 @@ impl<'a, W: Writer> RandomFasta<'a, W> { for i in range(0u, chars_left) { buf[i] = self.nextc(); } - self.out.write(&buf[0..chars_left]) + self.out.write(&buf[..chars_left]) } } diff --git a/src/test/run-pass/issue-17503.rs b/src/test/run-pass/issue-17503.rs index 65bf088786e..a071224999b 100644 --- a/src/test/run-pass/issue-17503.rs +++ b/src/test/run-pass/issue-17503.rs @@ -13,7 +13,7 @@ fn main() { let ss: &&[int] = &s; let sss: &&&[int] = &ss; - println!("{:?}", &s[0..3]); + println!("{:?}", &s[..3]); println!("{:?}", &ss[3..]); println!("{:?}", &sss[2..4]); } diff --git a/src/test/run-pass/issue-8898.rs b/src/test/run-pass/issue-8898.rs index 42739628eed..f845db9c421 100644 --- a/src/test/run-pass/issue-8898.rs +++ b/src/test/run-pass/issue-8898.rs @@ -16,7 +16,7 @@ pub fn main() { let abc = [1i, 2, 3]; let tf = [true, false]; let x = [(), ()]; - let slice = &x[0..1]; + let slice = &x[..1]; assert_repr_eq(&abc[], "[1i, 2i, 3i]".to_string()); assert_repr_eq(&tf[], "[true, false]".to_string()); diff --git a/src/test/run-pass/slice-2.rs b/src/test/run-pass/slice-2.rs index 8f031d2e97e..43e517404cb 100644 --- a/src/test/run-pass/slice-2.rs +++ b/src/test/run-pass/slice-2.rs @@ -17,7 +17,7 @@ fn main() { let cmp: &[int] = &[3, 4, 5]; assert!(&x[2..] == cmp); let cmp: &[int] = &[1, 2, 3]; - assert!(&x[0..3] == cmp); + assert!(&x[..3] == cmp); let cmp: &[int] = &[2, 3, 4]; assert!(&x[1..4] == cmp); @@ -27,7 +27,7 @@ fn main() { let cmp: &[int] = &[3, 4, 5]; assert!(&x[2..] == cmp); let cmp: &[int] = &[1, 2, 3]; - assert!(&x[0..3] == cmp); + assert!(&x[..3] == cmp); let cmp: &[int] = &[2, 3, 4]; assert!(&x[1..4] == cmp);