File tree 1 file changed +7
-4
lines changed
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,9 @@ use crate::task::{Context, Poll};
5
5
6
6
/// Creates a future that wraps a function returning [`Poll`].
7
7
///
8
- /// Polling the future delegates to the wrapped function.
8
+ /// Polling the future delegates to the wrapped function. If the returned future is pinned, then the
9
+ /// captured environment of the wrapped function is also pinned in-place, so as long as the closure
10
+ /// does not move out of its captures it can soundly create pinned references to them.
9
11
///
10
12
/// # Examples
11
13
///
@@ -41,7 +43,7 @@ pub struct PollFn<F> {
41
43
}
42
44
43
45
#[ stable( feature = "future_poll_fn" , since = "1.64.0" ) ]
44
- impl < F > Unpin for PollFn < F > { }
46
+ impl < F : Unpin > Unpin for PollFn < F > { }
45
47
46
48
#[ stable( feature = "future_poll_fn" , since = "1.64.0" ) ]
47
49
impl < F > fmt:: Debug for PollFn < F > {
57
59
{
58
60
type Output = T ;
59
61
60
- fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < T > {
61
- ( & mut self . f ) ( cx)
62
+ fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < T > {
63
+ // SAFETY: We are not moving out of the pinned field.
64
+ ( unsafe { & mut self . get_unchecked_mut ( ) . f } ) ( cx)
62
65
}
63
66
}
You can’t perform that action at this time.
0 commit comments