@@ -16,7 +16,7 @@ use mysql_common::{
16
16
} ,
17
17
} ;
18
18
19
- use std:: { fmt, mem, str:: FromStr , sync:: Arc } ;
19
+ use std:: { fmt, future :: Future , mem, pin :: Pin , str:: FromStr , sync:: Arc } ;
20
20
21
21
use crate :: {
22
22
conn:: { pool:: Pool , stmt_cache:: StmtCache } ,
@@ -265,12 +265,16 @@ impl Conn {
265
265
}
266
266
}
267
267
268
- async fn continue_auth ( self ) -> Result < Conn > {
269
- match self . inner . auth_plugin {
270
- AuthPlugin :: MysqlNativePassword => self . continue_mysql_native_password_auth ( ) . await ,
271
- AuthPlugin :: CachingSha2Password => self . continue_caching_sha2_password_auth ( ) . await ,
272
- _ => unreachable ! ( ) ,
273
- }
268
+ fn continue_auth ( self ) -> Pin < Box < dyn Future < Output = Result < Conn > > + Send > > {
269
+ // NOTE: we need to box this since it may recurse
270
+ // see https://github.com/rust-lang/rust/issues/46415#issuecomment-528099782
271
+ Box :: pin ( async move {
272
+ match self . inner . auth_plugin {
273
+ AuthPlugin :: MysqlNativePassword => self . continue_mysql_native_password_auth ( ) . await ,
274
+ AuthPlugin :: CachingSha2Password => self . continue_caching_sha2_password_auth ( ) . await ,
275
+ _ => unreachable ! ( ) ,
276
+ }
277
+ } )
274
278
}
275
279
276
280
async fn continue_caching_sha2_password_auth ( self ) -> Result < Conn > {
@@ -389,19 +393,23 @@ impl Conn {
389
393
/// Returns new connection on success or self on error.
390
394
///
391
395
/// Won't try to reconnect if socket connection is already enforced in `Opts`.
392
- async fn reconnect_via_socket_if_needed ( self ) -> Result < Conn > {
393
- if let Some ( socket) = self . inner . socket . as_ref ( ) {
394
- let opts = self . inner . opts . clone ( ) ;
395
- if opts. get_socket ( ) . is_none ( ) {
396
- let mut builder = OptsBuilder :: from_opts ( opts) ;
397
- builder. socket ( Some ( & * * socket) ) ;
398
- match Conn :: new ( builder) . await {
399
- Ok ( conn) => return Ok ( conn) ,
400
- Err ( _) => return Ok ( self ) ,
396
+ fn reconnect_via_socket_if_needed ( self ) -> Pin < Box < dyn Future < Output = Result < Conn > > + Send > > {
397
+ // NOTE: we need to box this since it may recurse
398
+ // see https://github.com/rust-lang/rust/issues/46415#issuecomment-528099782
399
+ Box :: pin ( async move {
400
+ if let Some ( socket) = self . inner . socket . as_ref ( ) {
401
+ let opts = self . inner . opts . clone ( ) ;
402
+ if opts. get_socket ( ) . is_none ( ) {
403
+ let mut builder = OptsBuilder :: from_opts ( opts) ;
404
+ builder. socket ( Some ( & * * socket) ) ;
405
+ match Conn :: new ( builder) . await {
406
+ Ok ( conn) => return Ok ( conn) ,
407
+ Err ( _) => return Ok ( self ) ,
408
+ }
401
409
}
402
410
}
403
- }
404
- Ok ( self )
411
+ Ok ( self )
412
+ } )
405
413
}
406
414
407
415
/// Returns future that resolves to `Conn` with socket address stored in it.
@@ -482,15 +490,18 @@ impl Conn {
482
490
}
483
491
}
484
492
485
- async fn cleanup ( self ) -> Result < Conn > {
486
- // NOTE: we must box to avoid a recursive async fn
487
- if self . inner . has_result . is_some ( ) {
488
- Box :: pin ( async move { self . drop_result ( ) . await ?. cleanup ( ) . await } ) . await
489
- } else if self . inner . in_transaction {
490
- Box :: pin ( async move { self . rollback_transaction ( ) . await ?. cleanup ( ) . await } ) . await
491
- } else {
492
- Ok ( self )
493
- }
493
+ fn cleanup ( self ) -> Pin < Box < dyn Future < Output = Result < Conn > > + Send > > {
494
+ // NOTE: we need to box this since it may recurse
495
+ // see https://github.com/rust-lang/rust/issues/46415#issuecomment-528099782
496
+ Box :: pin ( async move {
497
+ if self . inner . has_result . is_some ( ) {
498
+ self . drop_result ( ) . await ?. cleanup ( ) . await
499
+ } else if self . inner . in_transaction {
500
+ self . rollback_transaction ( ) . await ?. cleanup ( ) . await
501
+ } else {
502
+ Ok ( self )
503
+ }
504
+ } )
494
505
}
495
506
}
496
507
0 commit comments