rust/src/liballoc/tests
Simon Sapin ce60da497b Fix vec![x; n] with null raw fat pointer zeroing the pointer metadata
https://github.com/rust-lang/rust/pull/49496 introduced specialization based on:

```
unsafe impl<T: ?Sized> IsZero for *mut T {
    fn is_zero(&self) -> bool {
        (*self).is_null()
    }
}
```

… to call `RawVec::with_capacity_zeroed` for creating `Vec<*mut T>`,
which is incorrect for fat pointers
since `<*mut T>::is_null` only looks at the data component.
That is, a fat pointer can be “null” without being made entirely of zero bits.

This commit fixes it by removing the `?Sized` bound on this impl
(and the corresponding `*const T` one).
This regresses `vec![x; n]` with `x` a null raw slice of length zero,
but that seems exceptionally uncommon.
(Vtable pointers are never null, so raw trait objects would not take
the fast path anyway.

An alternative to keep the `?Sized` bound
(or even generalize to `impl<U: Copy> IsZero for U`)
would be to cast to `&[u8]` of length `size_of::<U>()`,
but the optimizer seems not to be able to propagate alignment information
and sticks with comparing one byte at a time:

https://rust.godbolt.org/z/xQFkwL

----

Without the library change, the new test fails as follows:

```
---- vec::vec_macro_repeating_null_raw_fat_pointer stdout ----
[src/liballoc/tests/vec.rs:1301] ptr_metadata(raw_dyn) = 0x00005596ef95f9a8
[src/liballoc/tests/vec.rs:1306] ptr_metadata(vec[0]) = 0x0000000000000000
thread 'vec::vec_macro_repeating_null_raw_fat_pointer' panicked at 'assertion failed: vec[0] == null_raw_dyn', src/liballoc/tests/vec.rs:1307:5
```
2019-09-29 11:06:53 +02:00
..
btree Improve BTreeSet::Intersection::size_hint 2019-09-16 04:37:52 +00:00
arc.rs shared_from_iter: Polish internal docs. 2019-06-21 23:01:48 +02:00
binary_heap.rs Miri now supports entropy, but is still slow 2019-04-16 20:04:17 +02:00
cow_str.rs Deny rust_2018_idioms in liballoc tests 2019-04-20 16:05:25 +02:00
fmt.rs Remove licenses 2018-12-25 21:08:33 -07:00
heap.rs test more possible overaligned requests 2019-07-02 13:07:51 +02:00
lib.rs Add missing #![feature(associated_type_bounds)] 2019-08-09 11:19:45 +02:00
linked_list.rs Remove some more cfg(test)s 2019-08-02 02:40:01 +03:00
rc.rs shared_from_iter: Add more tests. 2019-06-21 03:52:38 +02:00
slice.rs test sort_unstable in Miri 2019-04-17 09:47:36 +02:00
str.rs Use associated_type_bounds where applicable - closes #61738 2019-08-08 22:39:15 +02:00
string.rs Add the Layout of the failed allocation to TryReserveError::AllocError 2019-08-16 18:08:37 +02:00
vec.rs Fix vec![x; n] with null raw fat pointer zeroing the pointer metadata 2019-09-29 11:06:53 +02:00
vec_deque.rs Add the Layout of the failed allocation to TryReserveError::AllocError 2019-08-16 18:08:37 +02:00