From 5052197e447a2279a63e8ef06179ca01b657eb9b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 9 Jan 2019 04:17:24 +0100 Subject: [PATCH] explain safety for vec.set_len(0) --- src/liballoc/vec.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 30bcc034221d3..0da00b70f9e51 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -816,6 +816,9 @@ impl Vec { /// let mut vec = vec![vec![1, 0, 0], /// vec![0, 1, 0], /// vec![0, 0, 1]]; + /// // SAFETY: + /// // 1. `old_len..0` is empty so no elements need to be initialized. + /// // 2. `0 <= capacity` always holds whatever `capacity` is. /// unsafe { /// vec.set_len(0); /// }