1
Fork 0

mark as_inner as unsafe and update comments

This commit is contained in:
The8472 2020-01-18 16:03:58 +01:00
parent 2a51e579f5
commit ab382b7661
5 changed files with 76 additions and 50 deletions

View file

@ -2167,6 +2167,8 @@ where
}
}
// A helper struct for in-place iteration that drops the destination slice of iteration.
// The source slice is dropped by IntoIter
struct InPlaceDrop<T> {
inner: *mut T,
dst: *mut T,
@ -2230,8 +2232,10 @@ where
return SpecFromNested::from_iter(iterator);
}
let src_buf = iterator.as_inner().as_into_iter().buf.as_ptr();
let src_end = iterator.as_inner().as_into_iter().end;
let (src_buf, src_end) = {
let inner = unsafe { iterator.as_inner().as_into_iter() };
(inner.buf.as_ptr(), inner.end)
};
let dst = src_buf;
let dst = if mem::needs_drop::<T>() {
@ -2273,7 +2277,7 @@ where
.unwrap()
};
let src = iterator.as_inner().as_into_iter();
let src = unsafe { iterator.as_inner().as_into_iter() };
// check if SourceIter and InPlaceIterable contracts were upheld.
// caveat: if they weren't we may not even make it to this point
debug_assert_eq!(src_buf, src.buf.as_ptr());
@ -2993,7 +2997,7 @@ unsafe impl<T> SourceIter for IntoIter<T> {
type Source = IntoIter<T>;
#[inline]
fn as_inner(&mut self) -> &mut Self::Source {
unsafe fn as_inner(&mut self) -> &mut Self::Source {
self
}
}