Skip to content

Commit

Permalink
Replace usages of ..i + 1 ranges with ..=i.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Dec 4, 2018
1 parent 431e0ab commit c025d61
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 36 deletions.
18 changes: 9 additions & 9 deletions src/liballoc/collections/vec_deque.rs
Expand Up @@ -2795,7 +2795,7 @@ mod tests {
// 0, 1, 2, .., len - 1
let expected = (0..).take(len).collect::<VecDeque<_>>();
for tail_pos in 0..cap {
for to_remove in 0..len + 1 {
for to_remove in 0..=len {
tester.tail = tail_pos;
tester.head = tail_pos;
for i in 0..len {
Expand All @@ -2821,10 +2821,10 @@ mod tests {
let mut tester: VecDeque<usize> = VecDeque::with_capacity(7);

let cap = tester.capacity();
for len in 0..cap + 1 {
for tail in 0..cap + 1 {
for drain_start in 0..len + 1 {
for drain_end in drain_start..len + 1 {
for len in 0..=cap {
for tail in 0..=cap {
for drain_start in 0..=len {
for drain_end in drain_start..=len {
tester.tail = tail;
tester.head = tail;
for i in 0..len {
Expand Down Expand Up @@ -2866,10 +2866,10 @@ mod tests {
tester.reserve(63);
let max_cap = tester.capacity();

for len in 0..cap + 1 {
for len in 0..=cap {
// 0, 1, 2, .., len - 1
let expected = (0..).take(len).collect::<VecDeque<_>>();
for tail_pos in 0..max_cap + 1 {
for tail_pos in 0..=max_cap {
tester.tail = tail_pos;
tester.head = tail_pos;
tester.reserve(63);
Expand Down Expand Up @@ -2899,7 +2899,7 @@ mod tests {
// len is the length *before* splitting
for len in 0..cap {
// index to split at
for at in 0..len + 1 {
for at in 0..=len {
// 0, 1, 2, .., at - 1 (may be empty)
let expected_self = (0..).take(at).collect::<VecDeque<_>>();
// at, at + 1, .., len - 1 (may be empty)
Expand Down Expand Up @@ -2927,7 +2927,7 @@ mod tests {
fn test_from_vec() {
use vec::Vec;
for cap in 0..35 {
for len in 0..cap + 1 {
for len in 0..=cap {
let mut vec = Vec::with_capacity(cap);
vec.extend(0..len);

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/tests/binary_heap.rs
Expand Up @@ -318,11 +318,11 @@ fn panic_safe() {
const NTEST: usize = 10;

// don't use 0 in the data -- we want to catch the zeroed-out case.
let data = (1..DATASZ + 1).collect::<Vec<_>>();
let data = (1..=DATASZ).collect::<Vec<_>>();

// since it's a fuzzy test, run several tries.
for _ in 0..NTEST {
for i in 1..DATASZ + 1 {
for i in 1..=DATASZ {
DROP_COUNTER.store(0, Ordering::SeqCst);

let mut panic_ords: Vec<_> = data.iter()
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/tests/btree/map.rs
Expand Up @@ -302,7 +302,7 @@ fn test_range() {
for i in 0..size {
for j in i..size {
let mut kvs = map.range((Included(&i), Included(&j))).map(|(&k, &v)| (k, v));
let mut pairs = (i..j + 1).map(|i| (i, i));
let mut pairs = (i..=j).map(|i| (i, i));

for (kv, pair) in kvs.by_ref().zip(pairs.by_ref()) {
assert_eq!(kv, pair);
Expand All @@ -321,7 +321,7 @@ fn test_range_mut() {
for i in 0..size {
for j in i..size {
let mut kvs = map.range_mut((Included(&i), Included(&j))).map(|(&k, &mut v)| (k, v));
let mut pairs = (i..j + 1).map(|i| (i, i));
let mut pairs = (i..=j).map(|i| (i, i));

for (kv, pair) in kvs.by_ref().zip(pairs.by_ref()) {
assert_eq!(kv, pair);
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/tests/str.rs
Expand Up @@ -1378,7 +1378,7 @@ fn test_bool_from_str() {
fn check_contains_all_substrings(s: &str) {
assert!(s.contains(""));
for i in 0..s.len() {
for j in i+1..s.len() + 1 {
for j in i+1..=s.len() {
assert!(s.contains(&s[i..j]));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/liballoc/tests/vec_deque.rs
Expand Up @@ -861,15 +861,15 @@ fn test_as_slices() {
ring.push_back(i);

let (left, right) = ring.as_slices();
let expected: Vec<_> = (0..i + 1).collect();
let expected: Vec<_> = (0..=i).collect();
assert_eq!(left, &expected[..]);
assert_eq!(right, []);
}

for j in -last..0 {
ring.push_front(j);
let (left, right) = ring.as_slices();
let expected_left: Vec<_> = (-last..j + 1).rev().collect();
let expected_left: Vec<_> = (-last..=j).rev().collect();
let expected_right: Vec<_> = (0..first).collect();
assert_eq!(left, &expected_left[..]);
assert_eq!(right, &expected_right[..]);
Expand All @@ -889,15 +889,15 @@ fn test_as_mut_slices() {
ring.push_back(i);

let (left, right) = ring.as_mut_slices();
let expected: Vec<_> = (0..i + 1).collect();
let expected: Vec<_> = (0..=i).collect();
assert_eq!(left, &expected[..]);
assert_eq!(right, []);
}

for j in -last..0 {
ring.push_front(j);
let (left, right) = ring.as_mut_slices();
let expected_left: Vec<_> = (-last..j + 1).rev().collect();
let expected_left: Vec<_> = (-last..=j).rev().collect();
let expected_right: Vec<_> = (0..first).collect();
assert_eq!(left, &expected_left[..]);
assert_eq!(right, &expected_right[..]);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/hir_id_validator.rs
Expand Up @@ -100,7 +100,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {

if max != self.hir_ids_seen.len() - 1 {
// Collect the missing ItemLocalIds
let missing: Vec<_> = (0 .. max as u32 + 1)
let missing: Vec<_> = (0 ..= max as u32)
.filter(|&i| !self.hir_ids_seen.contains_key(&ItemLocalId::from_u32(i)))
.collect();

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Expand Up @@ -339,7 +339,7 @@ impl<'tcx> Mir<'tcx> {
#[inline]
pub fn args_iter(&self) -> impl Iterator<Item = Local> {
let arg_count = self.arg_count;
(1..arg_count + 1).map(Local::new)
(1..=arg_count).map(Local::new)
}

/// Returns an iterator over all user-defined variables and compiler-generated temporaries (all
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_apfloat/ieee.rs
Expand Up @@ -571,7 +571,7 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {
}
// Fill with zeros up to precision.
if !truncate_zero && precision > digits - 1 {
for _ in 0..precision - digits + 1 {
for _ in 0..=precision - digits {
f.write_char('0')?;
}
}
Expand Down Expand Up @@ -1969,7 +1969,7 @@ impl<S: Semantics> IeeeFloat<S> {
// in a Limb. When this would overflow do we do a single
// bignum multiplication, and then revert again to multiplication
// in a Limb.
let mut chars = s[first_sig_digit..last_sig_digit + 1].chars();
let mut chars = s[first_sig_digit..=last_sig_digit].chars();
loop {
let mut val = 0;
let mut multiplier = 1;
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_errors/emitter.rs
Expand Up @@ -549,7 +549,7 @@ impl EmitterWriter {
// 3 |
// 4 | }
// |
for pos in 0..line_len + 1 {
for pos in 0..=line_len {
draw_col_separator(buffer, line_offset + pos + 1, width_offset - 2);
buffer.putc(line_offset + pos + 1,
width_offset - 2,
Expand Down Expand Up @@ -617,7 +617,7 @@ impl EmitterWriter {
let pos = pos + 1;

if pos > 1 && (annotation.has_label() || annotation.takes_space()) {
for p in line_offset + 1..line_offset + pos + 1 {
for p in line_offset + 1..=line_offset + pos {
buffer.putc(p,
code_offset + annotation.start_col,
'|',
Expand All @@ -634,7 +634,7 @@ impl EmitterWriter {
}
}
AnnotationType::MultilineEnd(depth) => {
for p in line_offset..line_offset + pos + 1 {
for p in line_offset..=line_offset + pos {
buffer.putc(p,
width_offset + depth - 1,
'|',
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/fs.rs
Expand Up @@ -354,7 +354,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Svh) {
}

// State: "s-{timestamp}-{random-number}-"
let mut new_sub_dir_name = String::from(&old_sub_dir_name[.. dash_indices[2] + 1]);
let mut new_sub_dir_name = String::from(&old_sub_dir_name[..= dash_indices[2]]);

// Append the svh
base_n::push_str(svh.as_u64() as u128, INT_ENCODE_BASE, &mut new_sub_dir_name);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/region_infer/values.rs
Expand Up @@ -48,7 +48,7 @@ impl RegionValueElements {

let mut basic_blocks = IndexVec::with_capacity(num_points);
for (bb, bb_data) in mir.basic_blocks().iter_enumerated() {
basic_blocks.extend((0..bb_data.statements.len() + 1).map(|_| bb));
basic_blocks.extend((0..=bb_data.statements.len()).map(|_| bb));
}

Self {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/mod.rs
Expand Up @@ -101,7 +101,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {

// create binding start block for link them by false edges
let candidate_count = arms.iter().fold(0, |ac, c| ac + c.patterns.len());
let pre_binding_blocks: Vec<_> = (0..candidate_count + 1)
let pre_binding_blocks: Vec<_> = (0..=candidate_count)
.map(|_| self.cfg.start_new_block())
.collect();

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -3614,7 +3614,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
let res = self.smart_resolve_path_fragment(
id,
None,
&path[..qself.position + 1],
&path[..=qself.position],
span,
PathSource::TraitItem(ns),
CrateLint::QPathTrait {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Expand Up @@ -4796,7 +4796,7 @@ impl<'a> fmt::Display for Source<'a> {
tmp /= 10;
}
write!(fmt, "<pre class=\"line-numbers\">")?;
for i in 1..lines + 1 {
for i in 1..=lines {
write!(fmt, "<span id=\"{0}\">{0:1$}</span>\n", i, cols)?;
}
write!(fmt, "</pre>")?;
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/collections/hash/map.rs
Expand Up @@ -3610,7 +3610,7 @@ mod test_map {
for i in 1..1001 {
assert!(m.insert(i, i).is_none());

for j in 1..i + 1 {
for j in 1..=i {
let r = m.get(&j);
assert_eq!(r, Some(&j));
}
Expand All @@ -3629,7 +3629,7 @@ mod test_map {
for i in 1..1001 {
assert!(m.remove(&i).is_some());

for j in 1..i + 1 {
for j in 1..=i {
assert!(!m.contains_key(&j));
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/buffered.rs
Expand Up @@ -918,7 +918,7 @@ impl<W: Write> Write for LineWriter<W> {
// some data then we *must* report that we wrote that data, so future
// errors are ignored. We set our internal `need_flush` flag, though, in
// case flushing fails and we need to try it first next time.
let n = self.inner.write(&buf[..i + 1])?;
let n = self.inner.write(&buf[..=i])?;
self.need_flush = true;
if self.flush().is_err() || n != i + 1 {
return Ok(n)
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/mod.rs
Expand Up @@ -1261,7 +1261,7 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
};
match memchr::memchr(delim, available) {
Some(i) => {
buf.extend_from_slice(&available[..i + 1]);
buf.extend_from_slice(&available[..=i]);
(true, i + 1)
}
None => {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/process.rs
Expand Up @@ -487,7 +487,7 @@ fn make_command_line(prog: &OsStr, args: &[OsString]) -> io::Result<Vec<u16>> {
} else {
if x == '"' as u16 {
// Add n+1 backslashes to total 2n+1 before internal '"'.
cmd.extend((0..(backslashes + 1)).map(|_| '\\' as u16));
cmd.extend((0..=backslashes).map(|_| '\\' as u16));
}
backslashes = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/util/lev_distance.rs
Expand Up @@ -20,7 +20,7 @@ pub fn lev_distance(a: &str, b: &str) -> usize {
return a.chars().count();
}

let mut dcol: Vec<_> = (0..b.len() + 1).collect();
let mut dcol: Vec<_> = (0..=b.len()).collect();
let mut t_last = 0;

for (i, sc) in a.chars().enumerate() {
Expand Down

0 comments on commit c025d61

Please sign in to comment.