From 59b3c83a819567a1ca8b7c8535dad5bf73c855b1 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 12 Nov 2014 23:34:32 +0100 Subject: [PATCH] Fix `Vec::map_in_place` not doing what is written in the comment --- src/libcollections/vec.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 0e3799ed9ac37..4a3418986064d 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1661,7 +1661,10 @@ impl Vec { // Create a `Vec` from our `PartialVecZeroSized` and make sure the // destructor of the latter will not run. None of this can panic. let mut result = Vec::new(); - unsafe { result.set_len(pv.num_u); } + unsafe { + result.set_len(pv.num_u); + mem::forget(pv); + } result } }