@@ -38,6 +38,7 @@ fn bind_futures(fut_exprs: Vec<Expr>, span: Span) -> (Vec<TokenStream2>, Vec<Ide
38
38
// Move future into a local so that it is pinned in one place and
39
39
// is no longer accessible by the end user.
40
40
let mut #name = __futures_crate:: future:: maybe_done( #expr) ;
41
+ let mut #name = unsafe { __futures_crate:: Pin :: new_unchecked( & mut #name) } ;
41
42
} ) ;
42
43
name
43
44
} )
@@ -58,12 +59,12 @@ pub(crate) fn join(input: TokenStream) -> TokenStream {
58
59
let poll_futures = future_names. iter ( ) . map ( |fut| {
59
60
quote ! {
60
61
__all_done &= __futures_crate:: future:: Future :: poll(
61
- unsafe { __futures_crate :: Pin :: new_unchecked ( & mut #fut) } , __cx) . is_ready( ) ;
62
+ #fut. as_mut ( ) , __cx) . is_ready( ) ;
62
63
}
63
64
} ) ;
64
65
let take_outputs = future_names. iter ( ) . map ( |fut| {
65
66
quote ! {
66
- unsafe { __futures_crate :: Pin :: new_unchecked ( & mut #fut) } . take_output( ) . unwrap( ) ,
67
+ #fut. as_mut ( ) . take_output( ) . unwrap( ) ,
67
68
}
68
69
} ) ;
69
70
@@ -96,17 +97,17 @@ pub(crate) fn try_join(input: TokenStream) -> TokenStream {
96
97
let poll_futures = future_names. iter ( ) . map ( |fut| {
97
98
quote ! {
98
99
if __futures_crate:: future:: Future :: poll(
99
- unsafe { __futures_crate :: Pin :: new_unchecked ( & mut #fut) } , __cx) . is_pending( )
100
+ #fut. as_mut ( ) , __cx) . is_pending( )
100
101
{
101
102
__all_done = false ;
102
- } else if unsafe { __futures_crate :: Pin :: new_unchecked ( & mut #fut) } . output_mut( ) . unwrap( ) . is_err( ) {
103
+ } else if #fut. as_mut ( ) . output_mut( ) . unwrap( ) . is_err( ) {
103
104
// `.err().unwrap()` rather than `.unwrap_err()` so that we don't introduce
104
105
// a `T: Debug` bound.
105
106
// Also, for an error type of ! any code after `err().unwrap()` is unreachable.
106
107
#[ allow( unreachable_code) ]
107
108
return __futures_crate:: task:: Poll :: Ready (
108
109
__futures_crate:: Err (
109
- unsafe { __futures_crate :: Pin :: new_unchecked ( & mut #fut) } . take_output( ) . unwrap( ) . err( ) . unwrap( )
110
+ #fut. as_mut ( ) . take_output( ) . unwrap( ) . err( ) . unwrap( )
110
111
)
111
112
) ;
112
113
}
@@ -118,7 +119,7 @@ pub(crate) fn try_join(input: TokenStream) -> TokenStream {
118
119
// an `E: Debug` bound.
119
120
// Also, for an ok type of ! any code after `ok().unwrap()` is unreachable.
120
121
#[ allow( unreachable_code) ]
121
- unsafe { __futures_crate :: Pin :: new_unchecked ( & mut #fut) } . take_output( ) . unwrap( ) . ok( ) . unwrap( ) ,
122
+ #fut. as_mut ( ) . take_output( ) . unwrap( ) . ok( ) . unwrap( ) ,
122
123
}
123
124
} ) ;
124
125
0 commit comments