summary refs log tree commit diff
path: root/library/alloc/src/vec
diff options
context:
space:
mode:
authorPaolo Barbolini <paolo@paolo565.org>2022-04-11 00:00:03 +0200
committerPaolo Barbolini <paolo@paolo565.org>2022-04-28 06:13:54 +0200
commitc126f7fc8bf9e2abc0cac1fae40d04f4cf21e4d0 (patch)
tree1f2be7eebbe25dce4142ab74a1b8f0e57c12a347 /library/alloc/src/vec
parent84b8898d6357810472a01038bde7b1788615aa8a (diff)
downloadrust-c126f7fc8bf9e2abc0cac1fae40d04f4cf21e4d0.tar.gz
rust-c126f7fc8bf9e2abc0cac1fae40d04f4cf21e4d0.zip
Add VecDeque::extend from vec::IntoIter and slice::Iter specializations
Diffstat (limited to 'library/alloc/src/vec')
-rw-r--r--library/alloc/src/vec/into_iter.rs5
-rw-r--r--library/alloc/src/vec/spec_extend.rs2
2 files changed, 6 insertions, 1 deletions
diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs
index 03c532bb697..8134eea570a 100644
--- a/library/alloc/src/vec/into_iter.rs
+++ b/library/alloc/src/vec/into_iter.rs
@@ -121,6 +121,11 @@ impl<T, A: Allocator> IntoIter<T, A> {
             ptr::drop_in_place(remaining);
         }
     }
+
+    /// Forgets to Drop the remaining elements while still allowing the backing allocation to be freed.
+    pub(crate) fn forget_remaining_elements(&mut self) {
+        self.ptr = self.end;
+    }
 }
 
 #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")]
diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs
index c3b4534096d..506ee0ecfa2 100644
--- a/library/alloc/src/vec/spec_extend.rs
+++ b/library/alloc/src/vec/spec_extend.rs
@@ -62,7 +62,7 @@ impl<T, A: Allocator> SpecExtend<T, IntoIter<T>> for Vec<T, A> {
         unsafe {
             self.append_elements(iterator.as_slice() as _);
         }
-        iterator.ptr = iterator.end;
+        iterator.forget_remaining_elements();
     }
 }