From 1750c7bdd36ec18324423bd30867e39d787d5977 Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Sat, 10 Sep 2022 15:00:37 +0200 Subject: [PATCH] Clarify documentation --- library/alloc/src/vec/in_place_collect.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 83ed3d915a2..9f2555ee161 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -194,11 +194,10 @@ where ); } - // Drop any remaining values at the tail of the source but prevent drop of the allocation - // itself once IntoIter goes out of scope. - // If the drop panics then we also try to drop the destination buffer and its elements. + // The ownership of the allocation and the new `T` values is temporarily moved into `dst_guard`. // This is safe because `forget_allocation_drop_remaining` immediately forgets the allocation - // and won't panic before that. + // before any panic can occur in order to avoid any double free, and then proceeds to drop + // any remaining values at the tail of the source. // // Note: This access to the source wouldn't be allowed by the TrustedRandomIteratorNoCoerce // contract (used by SpecInPlaceCollect below). But see the "O(1) collect" section in the