1
Fork 0

Fix undocumented unsafe in AssertUnwindSafe impls

This commit is contained in:
David Tolnay 2021-04-28 08:47:09 -07:00
parent 4e17994b2c
commit 6d988dc1e3
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -281,6 +281,7 @@ impl<F: Future> Future for AssertUnwindSafe<F> {
type Output = F::Output; type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// SAFETY: pin projection. AssertUnwindSafe follows structural pinning.
let pinned_field = unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }; let pinned_field = unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) };
F::poll(pinned_field, cx) F::poll(pinned_field, cx)
} }
@ -291,6 +292,7 @@ impl<S: Stream> Stream for AssertUnwindSafe<S> {
type Item = S::Item; type Item = S::Item;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<S::Item>> { fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<S::Item>> {
// SAFETY: pin projection. AssertUnwindSafe follows structural pinning.
unsafe { self.map_unchecked_mut(|x| &mut x.0) }.poll_next(cx) unsafe { self.map_unchecked_mut(|x| &mut x.0) }.poll_next(cx)
} }