]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #9557 : blake2-ppc/rust/vec-lifetime-token, r=thestinger
authorbors <bors@rust-lang.org>
Sat, 28 Sep 2013 02:16:05 +0000 (19:16 -0700)
committerbors <bors@rust-lang.org>
Sat, 28 Sep 2013 02:16:05 +0000 (19:16 -0700)
std::vec: Use a valid value as lifetime dummy in iterator

The current implementation uses `&v[0]` for the lifetime struct field,
but that is a dangling pointer for iterators derived from zero-length
slices.

Example:

    let v: [int, ..0] = [];  println!("{:?}", v.iter())

    std::vec::VecIterator<,int>{ptr: (0x7f3768626100 as *()), end: (0x7f3768626100 as *()), lifetime: &139875951207128}

To replace this parameter, use a field of type `Option<&'self ()>`
that is simply initialized with `None`, but still allows the iterator to
have a lifetime parameter.

1  2 
src/libstd/vec.rs

Simple merge