We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2835ca6 commit 745eb7aCopy full SHA for 745eb7a
src/liballoc/slice.rs
@@ -735,14 +735,14 @@ impl<T: Clone> ToOwned for [T] {
735
fn clone_into(&self, target: &mut Vec<T>) {
736
// drop anything in target that will not be overwritten
737
target.truncate(self.len());
738
- let len = target.len();
739
-
740
- // reuse the contained values' allocations/resources.
741
- target.clone_from_slice(&self[..len]);
742
743
// target.len <= self.len due to the truncate above, so the
744
- // slice here is always in-bounds.
745
- target.extend_from_slice(&self[len..]);
+ // slices here are always in-bounds.
+ let (init, tail) = self.split_at(target.len());
+
+ // reuse the contained values' allocations/resources.
+ target.clone_from_slice(init);
+ target.extend_from_slice(tail);
746
}
747
748
0 commit comments