We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6dee5f1 commit e8339e8Copy full SHA for e8339e8
src/liballoc/slice.rs
@@ -733,14 +733,14 @@ impl<T: Clone> ToOwned for [T] {
733
fn clone_into(&self, target: &mut Vec<T>) {
734
// drop anything in target that will not be overwritten
735
target.truncate(self.len());
736
- let len = target.len();
737
-
738
- // reuse the contained values' allocations/resources.
739
- target.clone_from_slice(&self[..len]);
740
741
// target.len <= self.len due to the truncate above, so the
742
- // slice here is always in-bounds.
743
- 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);
744
}
745
746
0 commit comments