about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/doc/nomicon/vec-drain.md14
-rw-r--r--src/doc/nomicon/vec-final.md13
2 files changed, 16 insertions, 11 deletions
diff --git a/src/doc/nomicon/vec-drain.md b/src/doc/nomicon/vec-drain.md
index 4521bbdd05e..6e732ee1074 100644
--- a/src/doc/nomicon/vec-drain.md
+++ b/src/doc/nomicon/vec-drain.md
@@ -129,14 +129,16 @@ impl<'a, T> Drop for Drain<'a, T> {
 
 impl<T> Vec<T> {
     pub fn drain(&mut self) -> Drain<T> {
-        // this is a mem::forget safety thing. If Drain is forgotten, we just
-        // leak the whole Vec's contents. Also we need to do this eventually
-        // anyway, so why not do it now?
-        self.len = 0;
-
         unsafe {
+            let iter = RawValIter::new(&self);
+
+            // this is a mem::forget safety thing. If Drain is forgotten, we just
+            // leak the whole Vec's contents. Also we need to do this *eventually*
+            // anyway, so why not do it now?
+            self.len = 0;
+
             Drain {
-                iter: RawValIter::new(&self),
+                iter: iter,
                 vec: PhantomData,
             }
         }
diff --git a/src/doc/nomicon/vec-final.md b/src/doc/nomicon/vec-final.md
index 847957e2ea9..ba4537f1640 100644
--- a/src/doc/nomicon/vec-final.md
+++ b/src/doc/nomicon/vec-final.md
@@ -155,13 +155,16 @@ impl<T> Vec<T> {
     }
 
     pub fn drain(&mut self) -> Drain<T> {
-        // this is a mem::forget safety thing. If this is forgotten, we just
-        // leak the whole Vec's contents. Also we need to do this *eventually*
-        // anyway, so why not do it now?
-        self.len = 0;
         unsafe {
+            let iter = RawValIter::new(&self);
+
+            // this is a mem::forget safety thing. If Drain is forgotten, we just
+            // leak the whole Vec's contents. Also we need to do this *eventually*
+            // anyway, so why not do it now?
+            self.len = 0;
+
             Drain {
-                iter: RawValIter::new(&self),
+                iter: iter,
                 vec: PhantomData,
             }
         }