about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorJørn Lode <jlode90@gmail.com>2015-09-06 03:20:53 +0200
committerJørn Lode <jlode90@gmail.com>2015-09-06 03:44:13 +0200
commitc08deef9825c62ad8eb4012826b66daca30a731b (patch)
treefc24cb611e57a4eeff623921ed99f05069127e3e /src/rustllvm/RustWrapper.cpp
parent53e694e19be805a3e14d257120b5515a7670e122 (diff)
downloadrust-c08deef9825c62ad8eb4012826b66daca30a731b.tar.gz
rust-c08deef9825c62ad8eb4012826b66daca30a731b.zip
Rustonomicon: Fix bug in implementation of Vec::drain()
In the last code snippet on the following page there is a bug in the
implementation of Vec::drain().

https://doc.rust-lang.org/nightly/nomicon/vec-drain.html

```rust
pub fn drain(&mut self) -> Drain<T> {
    // Oops, setting it to 0 while we still need the old value!
    self.len = 0;

    unsafe {
        Drain {
            // len is used to create a &[T] from &self here,
            // so we end up always creating an empty slice.
            iter: RawValIter::new(&self),
            vec: PhantomData,
        }
    }
}
```

A simple test to verify that Drain is broken can be found here:
https://play.rust-lang.org/?gist=30f579565e4bbf4836ce&version=nightly

And here's one with a fixed implementation:
https://play.rust-lang.org/?gist=2ec0c1a6dcf5defd7a53&version=nightly
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions