diff options
| author | Luqman Aden <me@luqman.ca> | 2014-07-04 15:29:47 -0700 |
|---|---|---|
| committer | Luqman Aden <me@luqman.ca> | 2014-07-05 02:49:03 -0700 |
| commit | e9e5ea2f903ed780e0bbbe5f5662a5ee2054c4a2 (patch) | |
| tree | a0a716098a67f279e24a8861830e2abcfa3db862 /src/libcollections | |
| parent | f48cc740017bac1214030300435dfa95dbaa220b (diff) | |
| download | rust-e9e5ea2f903ed780e0bbbe5f5662a5ee2054c4a2.tar.gz rust-e9e5ea2f903ed780e0bbbe5f5662a5ee2054c4a2.zip | |
libcore: Fix Items iterator for zero sized types.
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/vec.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index a284ef40257..6e2dc95cfd6 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -75,12 +75,10 @@ impl<T> Vec<T> { /// ``` #[inline] pub fn new() -> Vec<T> { - // If we have a 0-sized vector, then the base pointer should not be NULL - // because an iterator over the slice will attempt to yield the base - // pointer as the first element in the vector, but this will end up - // being Some(NULL) which is optimized to None. So instead we set ptr - // to some arbitrary non-null value which is fine since we never call - // deallocate on the ptr if cap is 0. + // We want ptr to never be NULL so instead we set it to some arbitrary + // non-null value which is fine since we never call deallocate on the ptr + // if cap is 0. The reason for this is because the pointer of a slice + // being NULL would break the null pointer optimization for enums. Vec { len: 0, cap: 0, ptr: &PTR_MARKER as *const _ as *mut T } } |
