Skip to content

Commit 941e2d7

Browse files
committed
Auto merge of #56516 - frewsxcv:frewsxcv-eq, r=<try>
Replace usages of `..i + 1` ranges with `..=i`. Before this change we were using old computer code techniques. After this change we use the new and improved computer code techniques.
2 parents 77a6a61 + c025d61 commit 941e2d7

File tree

19 files changed

+36
-36
lines changed

19 files changed

+36
-36
lines changed

src/liballoc/collections/vec_deque.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,7 @@ mod tests {
27952795
// 0, 1, 2, .., len - 1
27962796
let expected = (0..).take(len).collect::<VecDeque<_>>();
27972797
for tail_pos in 0..cap {
2798-
for to_remove in 0..len + 1 {
2798+
for to_remove in 0..=len {
27992799
tester.tail = tail_pos;
28002800
tester.head = tail_pos;
28012801
for i in 0..len {
@@ -2821,10 +2821,10 @@ mod tests {
28212821
let mut tester: VecDeque<usize> = VecDeque::with_capacity(7);
28222822

28232823
let cap = tester.capacity();
2824-
for len in 0..cap + 1 {
2825-
for tail in 0..cap + 1 {
2826-
for drain_start in 0..len + 1 {
2827-
for drain_end in drain_start..len + 1 {
2824+
for len in 0..=cap {
2825+
for tail in 0..=cap {
2826+
for drain_start in 0..=len {
2827+
for drain_end in drain_start..=len {
28282828
tester.tail = tail;
28292829
tester.head = tail;
28302830
for i in 0..len {
@@ -2866,10 +2866,10 @@ mod tests {
28662866
tester.reserve(63);
28672867
let max_cap = tester.capacity();
28682868

2869-
for len in 0..cap + 1 {
2869+
for len in 0..=cap {
28702870
// 0, 1, 2, .., len - 1
28712871
let expected = (0..).take(len).collect::<VecDeque<_>>();
2872-
for tail_pos in 0..max_cap + 1 {
2872+
for tail_pos in 0..=max_cap {
28732873
tester.tail = tail_pos;
28742874
tester.head = tail_pos;
28752875
tester.reserve(63);
@@ -2899,7 +2899,7 @@ mod tests {
28992899
// len is the length *before* splitting
29002900
for len in 0..cap {
29012901
// index to split at
2902-
for at in 0..len + 1 {
2902+
for at in 0..=len {
29032903
// 0, 1, 2, .., at - 1 (may be empty)
29042904
let expected_self = (0..).take(at).collect::<VecDeque<_>>();
29052905
// at, at + 1, .., len - 1 (may be empty)
@@ -2927,7 +2927,7 @@ mod tests {
29272927
fn test_from_vec() {
29282928
use vec::Vec;
29292929
for cap in 0..35 {
2930-
for len in 0..cap + 1 {
2930+
for len in 0..=cap {
29312931
let mut vec = Vec::with_capacity(cap);
29322932
vec.extend(0..len);
29332933

src/liballoc/tests/binary_heap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@ fn panic_safe() {
318318
const NTEST: usize = 10;
319319

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

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

328328
let mut panic_ords: Vec<_> = data.iter()

src/liballoc/tests/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ fn test_range() {
302302
for i in 0..size {
303303
for j in i..size {
304304
let mut kvs = map.range((Included(&i), Included(&j))).map(|(&k, &v)| (k, v));
305-
let mut pairs = (i..j + 1).map(|i| (i, i));
305+
let mut pairs = (i..=j).map(|i| (i, i));
306306

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

326326
for (kv, pair) in kvs.by_ref().zip(pairs.by_ref()) {
327327
assert_eq!(kv, pair);

src/liballoc/tests/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ fn test_bool_from_str() {
13781378
fn check_contains_all_substrings(s: &str) {
13791379
assert!(s.contains(""));
13801380
for i in 0..s.len() {
1381-
for j in i+1..s.len() + 1 {
1381+
for j in i+1..=s.len() {
13821382
assert!(s.contains(&s[i..j]));
13831383
}
13841384
}

src/liballoc/tests/vec_deque.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -861,15 +861,15 @@ fn test_as_slices() {
861861
ring.push_back(i);
862862

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

869869
for j in -last..0 {
870870
ring.push_front(j);
871871
let (left, right) = ring.as_slices();
872-
let expected_left: Vec<_> = (-last..j + 1).rev().collect();
872+
let expected_left: Vec<_> = (-last..=j).rev().collect();
873873
let expected_right: Vec<_> = (0..first).collect();
874874
assert_eq!(left, &expected_left[..]);
875875
assert_eq!(right, &expected_right[..]);
@@ -889,15 +889,15 @@ fn test_as_mut_slices() {
889889
ring.push_back(i);
890890

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

897897
for j in -last..0 {
898898
ring.push_front(j);
899899
let (left, right) = ring.as_mut_slices();
900-
let expected_left: Vec<_> = (-last..j + 1).rev().collect();
900+
let expected_left: Vec<_> = (-last..=j).rev().collect();
901901
let expected_right: Vec<_> = (0..first).collect();
902902
assert_eq!(left, &expected_left[..]);
903903
assert_eq!(right, &expected_right[..]);

src/librustc/hir/map/hir_id_validator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
100100

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

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl<'tcx> Mir<'tcx> {
339339
#[inline]
340340
pub fn args_iter(&self) -> impl Iterator<Item = Local> {
341341
let arg_count = self.arg_count;
342-
(1..arg_count + 1).map(Local::new)
342+
(1..=arg_count).map(Local::new)
343343
}
344344

345345
/// Returns an iterator over all user-defined variables and compiler-generated temporaries (all

src/librustc_apfloat/ieee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {
571571
}
572572
// Fill with zeros up to precision.
573573
if !truncate_zero && precision > digits - 1 {
574-
for _ in 0..precision - digits + 1 {
574+
for _ in 0..=precision - digits {
575575
f.write_char('0')?;
576576
}
577577
}
@@ -1969,7 +1969,7 @@ impl<S: Semantics> IeeeFloat<S> {
19691969
// in a Limb. When this would overflow do we do a single
19701970
// bignum multiplication, and then revert again to multiplication
19711971
// in a Limb.
1972-
let mut chars = s[first_sig_digit..last_sig_digit + 1].chars();
1972+
let mut chars = s[first_sig_digit..=last_sig_digit].chars();
19731973
loop {
19741974
let mut val = 0;
19751975
let mut multiplier = 1;

src/librustc_errors/emitter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl EmitterWriter {
549549
// 3 |
550550
// 4 | }
551551
// |
552-
for pos in 0..line_len + 1 {
552+
for pos in 0..=line_len {
553553
draw_col_separator(buffer, line_offset + pos + 1, width_offset - 2);
554554
buffer.putc(line_offset + pos + 1,
555555
width_offset - 2,
@@ -617,7 +617,7 @@ impl EmitterWriter {
617617
let pos = pos + 1;
618618

619619
if pos > 1 && (annotation.has_label() || annotation.takes_space()) {
620-
for p in line_offset + 1..line_offset + pos + 1 {
620+
for p in line_offset + 1..=line_offset + pos {
621621
buffer.putc(p,
622622
code_offset + annotation.start_col,
623623
'|',
@@ -634,7 +634,7 @@ impl EmitterWriter {
634634
}
635635
}
636636
AnnotationType::MultilineEnd(depth) => {
637-
for p in line_offset..line_offset + pos + 1 {
637+
for p in line_offset..=line_offset + pos {
638638
buffer.putc(p,
639639
width_offset + depth - 1,
640640
'|',

src/librustc_incremental/persist/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Svh) {
354354
}
355355

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

359359
// Append the svh
360360
base_n::push_str(svh.as_u64() as u128, INT_ENCODE_BASE, &mut new_sub_dir_name);

src/librustc_mir/borrow_check/nll/region_infer/values.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl RegionValueElements {
4848

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

5454
Self {

src/librustc_mir/build/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
101101

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

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3614,7 +3614,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
36143614
let res = self.smart_resolve_path_fragment(
36153615
id,
36163616
None,
3617-
&path[..qself.position + 1],
3617+
&path[..=qself.position],
36183618
span,
36193619
PathSource::TraitItem(ns),
36203620
CrateLint::QPathTrait {

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4796,7 +4796,7 @@ impl<'a> fmt::Display for Source<'a> {
47964796
tmp /= 10;
47974797
}
47984798
write!(fmt, "<pre class=\"line-numbers\">")?;
4799-
for i in 1..lines + 1 {
4799+
for i in 1..=lines {
48004800
write!(fmt, "<span id=\"{0}\">{0:1$}</span>\n", i, cols)?;
48014801
}
48024802
write!(fmt, "</pre>")?;

src/libstd/collections/hash/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3610,7 +3610,7 @@ mod test_map {
36103610
for i in 1..1001 {
36113611
assert!(m.insert(i, i).is_none());
36123612

3613-
for j in 1..i + 1 {
3613+
for j in 1..=i {
36143614
let r = m.get(&j);
36153615
assert_eq!(r, Some(&j));
36163616
}
@@ -3629,7 +3629,7 @@ mod test_map {
36293629
for i in 1..1001 {
36303630
assert!(m.remove(&i).is_some());
36313631

3632-
for j in 1..i + 1 {
3632+
for j in 1..=i {
36333633
assert!(!m.contains_key(&j));
36343634
}
36353635

src/libstd/io/buffered.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ impl<W: Write> Write for LineWriter<W> {
918918
// some data then we *must* report that we wrote that data, so future
919919
// errors are ignored. We set our internal `need_flush` flag, though, in
920920
// case flushing fails and we need to try it first next time.
921-
let n = self.inner.write(&buf[..i + 1])?;
921+
let n = self.inner.write(&buf[..=i])?;
922922
self.need_flush = true;
923923
if self.flush().is_err() || n != i + 1 {
924924
return Ok(n)

src/libstd/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
12611261
};
12621262
match memchr::memchr(delim, available) {
12631263
Some(i) => {
1264-
buf.extend_from_slice(&available[..i + 1]);
1264+
buf.extend_from_slice(&available[..=i]);
12651265
(true, i + 1)
12661266
}
12671267
None => {

src/libstd/sys/windows/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ fn make_command_line(prog: &OsStr, args: &[OsString]) -> io::Result<Vec<u16>> {
487487
} else {
488488
if x == '"' as u16 {
489489
// Add n+1 backslashes to total 2n+1 before internal '"'.
490-
cmd.extend((0..(backslashes + 1)).map(|_| '\\' as u16));
490+
cmd.extend((0..=backslashes).map(|_| '\\' as u16));
491491
}
492492
backslashes = 0;
493493
}

src/libsyntax/util/lev_distance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn lev_distance(a: &str, b: &str) -> usize {
2020
return a.chars().count();
2121
}
2222

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

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

0 commit comments

Comments
 (0)