Skip to content

Commit

Permalink
Rollup merge of rust-lang#123859 - krtab:uneeded_clone, r=cuviper
Browse files Browse the repository at this point in the history
Remove uneeded clones now that TrustedStep implies Copy

This is a follow up to 11fa176 (from rust-lang#112083)
  • Loading branch information
GuillaumeGomez authored Apr 16, 2024
2 parents 1176134 + 864eb7f commit 183c706
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions library/core/src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,11 @@ impl<T: TrustedStep> RangeInclusiveIteratorImpl for ops::RangeInclusive<T> {
let is_iterating = self.start < self.end;
Some(if is_iterating {
// SAFETY: just checked precondition
let n = unsafe { Step::forward_unchecked(self.start.clone(), 1) };
let n = unsafe { Step::forward_unchecked(self.start, 1) };
mem::replace(&mut self.start, n)
} else {
self.exhausted = true;
self.start.clone()
self.start
})
}

Expand All @@ -1179,15 +1179,15 @@ impl<T: TrustedStep> RangeInclusiveIteratorImpl for ops::RangeInclusive<T> {

while self.start < self.end {
// SAFETY: just checked precondition
let n = unsafe { Step::forward_unchecked(self.start.clone(), 1) };
let n = unsafe { Step::forward_unchecked(self.start, 1) };
let n = mem::replace(&mut self.start, n);
accum = f(accum, n)?;
}

self.exhausted = true;

if self.start == self.end {
accum = f(accum, self.start.clone())?;
accum = f(accum, self.start)?;
}

try { accum }
Expand All @@ -1201,11 +1201,11 @@ impl<T: TrustedStep> RangeInclusiveIteratorImpl for ops::RangeInclusive<T> {
let is_iterating = self.start < self.end;
Some(if is_iterating {
// SAFETY: just checked precondition
let n = unsafe { Step::backward_unchecked(self.end.clone(), 1) };
let n = unsafe { Step::backward_unchecked(self.end, 1) };
mem::replace(&mut self.end, n)
} else {
self.exhausted = true;
self.end.clone()
self.end
})
}

Expand All @@ -1224,15 +1224,15 @@ impl<T: TrustedStep> RangeInclusiveIteratorImpl for ops::RangeInclusive<T> {

while self.start < self.end {
// SAFETY: just checked precondition
let n = unsafe { Step::backward_unchecked(self.end.clone(), 1) };
let n = unsafe { Step::backward_unchecked(self.end, 1) };
let n = mem::replace(&mut self.end, n);
accum = f(accum, n)?;
}

self.exhausted = true;

if self.start == self.end {
accum = f(accum, self.start.clone())?;
accum = f(accum, self.start)?;
}

try { accum }
Expand Down

0 comments on commit 183c706

Please sign in to comment.