1
Fork 0

Rollup merge of #52502 - RalfJung:rotate, r=scottmcm

fix unsafety: don't call ptr_rotate for ZST

`rotate::ptr_rotate` has a comment saying
```
/// # Safety
///
/// The specified range must be valid for reading and writing.
/// The type `T` must have non-zero size.
```
So we better make sure we don't call it on ZST...

Cc @scottmcm (author of https://github.com/rust-lang/rust/pull/41670)
This commit is contained in:
kennytm 2018-07-21 02:59:04 +08:00
commit c74ff6cbd4
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C

View file

@ -48,7 +48,6 @@ impl<T> RawArray<T> {
/// # Safety
///
/// The specified range must be valid for reading and writing.
/// The type `T` must have non-zero size.
///
/// # Algorithm
///
@ -73,6 +72,7 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mid: *mut T, mut right: usize) {
loop {
let delta = cmp::min(left, right);
if delta <= RawArray::<T>::cap() {
// We will always hit this immediately for ZST.
break;
}