diff --git a/vec-drain.md b/vec-drain.md index 4521bbd..edad06c 100644 --- a/vec-drain.md +++ b/vec-drain.md @@ -129,14 +129,16 @@ impl<'a, T> Drop for Drain<'a, T> { impl Vec { pub fn drain(&mut self) -> Drain { - // 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 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; + Drain { - iter: RawValIter::new(&self), + iter: iter, vec: PhantomData, } } diff --git a/vec-final.md b/vec-final.md index 847957e..ace8f20 100644 --- a/vec-final.md +++ b/vec-final.md @@ -155,13 +155,16 @@ impl Vec { } pub fn drain(&mut self) -> Drain { - // 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 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; + Drain { - iter: RawValIter::new(&self), + iter: iter, vec: PhantomData, } }