diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index c8ee40f3d27..c0adeca4eb5 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -2795,7 +2795,7 @@ fn test_remove() { // 0, 1, 2, .., len - 1 let expected = (0..).take(len).collect::>(); 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 { @@ -2821,10 +2821,10 @@ fn test_drain() { let mut tester: VecDeque = 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 { @@ -2866,10 +2866,10 @@ fn test_shrink_to_fit() { 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::>(); - 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); @@ -2899,7 +2899,7 @@ fn test_split_off() { // 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::>(); // at, at + 1, .., len - 1 (may be empty) @@ -2927,7 +2927,7 @@ fn test_split_off() { 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); diff --git a/src/liballoc/tests/binary_heap.rs b/src/liballoc/tests/binary_heap.rs index 8494463463c..b0d8fa6bd69 100644 --- a/src/liballoc/tests/binary_heap.rs +++ b/src/liballoc/tests/binary_heap.rs @@ -318,11 +318,11 @@ fn partial_cmp(&self, other: &Self) -> Option { 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::>(); + let data = (1..=DATASZ).collect::>(); // 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() diff --git a/src/liballoc/tests/btree/map.rs b/src/liballoc/tests/btree/map.rs index 6ebdb86cc4a..33ef13ab811 100644 --- a/src/liballoc/tests/btree/map.rs +++ b/src/liballoc/tests/btree/map.rs @@ -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); @@ -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); diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index a5fa7f0c4d9..494b36f8541 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -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])); } } diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index 3ea6c87a651..1f2a7211c65 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -861,7 +861,7 @@ 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, []); } @@ -869,7 +869,7 @@ fn test_as_slices() { 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[..]); @@ -889,7 +889,7 @@ 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, []); } @@ -897,7 +897,7 @@ fn test_as_mut_slices() { 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[..]); diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index ac4119dc372..58d1a780f12 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -100,7 +100,7 @@ fn check)>(&mut self, 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(); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 91663557409..7259bbfb780 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -339,7 +339,7 @@ pub fn mut_vars_and_args_iter<'a>(&'a self) -> impl Iterator + 'a #[inline] pub fn args_iter(&self) -> impl Iterator { 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 diff --git a/src/librustc_apfloat/ieee.rs b/src/librustc_apfloat/ieee.rs index adcb9857ee3..2ad83fc93ef 100644 --- a/src/librustc_apfloat/ieee.rs +++ b/src/librustc_apfloat/ieee.rs @@ -571,7 +571,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } // 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')?; } } @@ -1969,7 +1969,7 @@ fn from_decimal_string(s: &str, round: Round) -> Result, ParseEr // 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; diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index ab2ab25c91a..ae9f6a5e140 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -549,7 +549,7 @@ fn render_source_line(&self, // 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, @@ -617,7 +617,7 @@ fn render_source_line(&self, 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, '|', @@ -634,7 +634,7 @@ fn render_source_line(&self, } } 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, '|', diff --git a/src/librustc_incremental/persist/fs.rs b/src/librustc_incremental/persist/fs.rs index bc98798f772..11ce10fd4a7 100644 --- a/src/librustc_incremental/persist/fs.rs +++ b/src/librustc_incremental/persist/fs.rs @@ -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); diff --git a/src/librustc_mir/borrow_check/nll/region_infer/values.rs b/src/librustc_mir/borrow_check/nll/region_infer/values.rs index 69e2c896d33..c7512f4b67f 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/values.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/values.rs @@ -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 { diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 342aaf9039d..172ff95ed10 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -101,7 +101,7 @@ pub fn match_expr( // 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(); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 4fa6dd7409f..389be3f758e 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3617,7 +3617,7 @@ fn resolve_qpath(&mut self, let res = self.smart_resolve_path_fragment( id, None, - &path[..qself.position + 1], + &path[..=qself.position], span, PathSource::TraitItem(ns), CrateLint::QPathTrait { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 6158815fb9a..30054f66e2f 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -4798,7 +4798,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { tmp /= 10; } write!(fmt, "
")?;
-        for i in 1..lines + 1 {
+        for i in 1..=lines {
             write!(fmt, "{0:1$}\n", i, cols)?;
         }
         write!(fmt, "
")?; diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 536ce2e16a0..1eea920c623 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -3610,7 +3610,7 @@ fn test_lots_of_insertions() { 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)); } @@ -3629,7 +3629,7 @@ fn test_lots_of_insertions() { 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)); } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 476ee3f71ca..7ede050da6c 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -918,7 +918,7 @@ fn write(&mut self, buf: &[u8]) -> io::Result { // 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) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 076524e624a..dc97701d889 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1261,7 +1261,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) }; match memchr::memchr(delim, available) { Some(i) => { - buf.extend_from_slice(&available[..i + 1]); + buf.extend_from_slice(&available[..=i]); (true, i + 1) } None => { diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index ff1ee0d26fe..03c1bb54af8 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -487,7 +487,7 @@ fn append_arg(cmd: &mut Vec, arg: &OsStr, force_quotes: bool) -> io::Result } 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; } diff --git a/src/libsyntax/util/lev_distance.rs b/src/libsyntax/util/lev_distance.rs index fb281154be0..e6b81a59d86 100644 --- a/src/libsyntax/util/lev_distance.rs +++ b/src/libsyntax/util/lev_distance.rs @@ -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() {