Skip to content

cleanup: &foo[0..a] -> &foo[..a] #21061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = &[];
Expand All @@ -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);
}


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

{
let right: &[_] = right;
assert!(right[0..right.len()] == [3, 4, 5][]);
assert!(right[..right.len()] == [3, 4, 5][]);
}
for p in right.iter_mut() {
*p += 2;
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ pub trait StrExt: Index<FullRange, Output = str> {
/// 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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,5 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
}
}

f(unsafe { str::from_utf8_unchecked(&buf[0..end]) })
f(unsafe { str::from_utf8_unchecked(&buf[..end]) })
}
4 changes: 2 additions & 2 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<T> SliceExt for [T] {

#[inline]
fn split_at(&self, mid: uint) -> (&[T], &[T]) {
(&self[0..mid], &self[mid..])
(&self[..mid], &self[mid..])
}

#[inline]
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<T> SliceExt for [T] {

#[inline]
fn init(&self) -> &[T] {
&self[0..(self.len() - 1)]
&self[..(self.len() - 1)]
}

#[inline]
Expand Down Expand Up @@ -443,7 +443,7 @@ impl<T> 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]
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/libcoretest/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down
20 changes: 10 additions & 10 deletions src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,39 +288,39 @@ 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]
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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/librbml/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_back/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/save/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/save/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<ValueRef>>();
self.count_insn("gepi");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fn path<F, G>(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));
Expand All @@ -347,7 +347,7 @@ fn path<F, G>(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));
}
}
Expand Down
Loading