@@ -38,6 +38,7 @@ fn bind_futures(fut_exprs: Vec<Expr>, span: Span) -> (Vec<TokenStream2>, Vec<Ide
3838 // Move future into a local so that it is pinned in one place and
3939 // is no longer accessible by the end user.
4040 let mut #name = __futures_crate:: future:: maybe_done( #expr) ;
41+ let mut #name = unsafe { __futures_crate:: Pin :: new_unchecked( & mut #name) } ;
4142 } ) ;
4243 name
4344 } )
@@ -58,12 +59,12 @@ pub(crate) fn join(input: TokenStream) -> TokenStream {
5859 let poll_futures = future_names. iter ( ) . map ( |fut| {
5960 quote ! {
6061 __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( ) ;
6263 }
6364 } ) ;
6465 let take_outputs = future_names. iter ( ) . map ( |fut| {
6566 quote ! {
66- unsafe { __futures_crate :: Pin :: new_unchecked ( & mut #fut) } . take_output( ) . unwrap( ) ,
67+ #fut. as_mut ( ) . take_output( ) . unwrap( ) ,
6768 }
6869 } ) ;
6970
@@ -96,17 +97,17 @@ pub(crate) fn try_join(input: TokenStream) -> TokenStream {
9697 let poll_futures = future_names. iter ( ) . map ( |fut| {
9798 quote ! {
9899 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( )
100101 {
101102 __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( ) {
103104 // `.err().unwrap()` rather than `.unwrap_err()` so that we don't introduce
104105 // a `T: Debug` bound.
105106 // Also, for an error type of ! any code after `err().unwrap()` is unreachable.
106107 #[ allow( unreachable_code) ]
107108 return __futures_crate:: task:: Poll :: Ready (
108109 __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( )
110111 )
111112 ) ;
112113 }
@@ -118,7 +119,7 @@ pub(crate) fn try_join(input: TokenStream) -> TokenStream {
118119 // an `E: Debug` bound.
119120 // Also, for an ok type of ! any code after `ok().unwrap()` is unreachable.
120121 #[ 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( ) ,
122123 }
123124 } ) ;
124125
0 commit comments