@@ -465,32 +465,6 @@ impl<'a> LoweringContext<'a> {
465
465
visit:: walk_pat ( self , p)
466
466
}
467
467
468
- fn visit_fn ( & mut self , fk : visit:: FnKind < ' lcx > , fd : & ' lcx FnDecl , s : Span , _: NodeId ) {
469
- if fk. header ( ) . map ( |h| h. asyncness . node . is_async ( ) ) . unwrap_or ( false ) {
470
- // Don't visit the original pattern for async functions as it will be
471
- // replaced.
472
- for arg in & fd. inputs {
473
- if let ArgSource :: AsyncFn ( pat) = & arg. source { self . visit_pat ( pat) ; }
474
- self . visit_ty ( & arg. ty )
475
- }
476
- self . visit_fn_ret_ty ( & fd. output ) ;
477
-
478
- match fk {
479
- visit:: FnKind :: ItemFn ( _, decl, _, body) => {
480
- self . visit_fn_header ( decl) ;
481
- self . visit_block ( body)
482
- } ,
483
- visit:: FnKind :: Method ( _, sig, _, body) => {
484
- self . visit_fn_header ( & sig. header ) ;
485
- self . visit_block ( body)
486
- } ,
487
- visit:: FnKind :: Closure ( body) => self . visit_expr ( body) ,
488
- }
489
- } else {
490
- visit:: walk_fn ( self , fk, fd, s)
491
- }
492
- }
493
-
494
468
fn visit_item ( & mut self , item : & ' lcx Item ) {
495
469
let hir_id = self . lctx . allocate_hir_id_counter ( item. id ) ;
496
470
@@ -2266,17 +2240,10 @@ impl<'a> LoweringContext<'a> {
2266
2240
init : l. init . as_ref ( ) . map ( |e| P ( self . lower_expr ( e) ) ) ,
2267
2241
span : l. span ,
2268
2242
attrs : l. attrs . clone ( ) ,
2269
- source : self . lower_local_source ( l . source ) ,
2243
+ source : hir :: LocalSource :: Normal ,
2270
2244
} , ids)
2271
2245
}
2272
2246
2273
- fn lower_local_source ( & mut self , ls : LocalSource ) -> hir:: LocalSource {
2274
- match ls {
2275
- LocalSource :: Normal => hir:: LocalSource :: Normal ,
2276
- LocalSource :: AsyncFn => hir:: LocalSource :: AsyncFn ,
2277
- }
2278
- }
2279
-
2280
2247
fn lower_mutability ( & mut self , m : Mutability ) -> hir:: Mutability {
2281
2248
match m {
2282
2249
Mutability :: Mutable => hir:: MutMutable ,
@@ -2292,14 +2259,7 @@ impl<'a> LoweringContext<'a> {
2292
2259
hir:: Arg {
2293
2260
hir_id : self . lower_node_id ( arg. id ) ,
2294
2261
pat : self . lower_pat ( & arg. pat ) ,
2295
- source : self . lower_arg_source ( & arg. source ) ,
2296
- }
2297
- }
2298
-
2299
- fn lower_arg_source ( & mut self , source : & ArgSource ) -> hir:: ArgSource {
2300
- match source {
2301
- ArgSource :: Normal => hir:: ArgSource :: Normal ,
2302
- ArgSource :: AsyncFn ( pat) => hir:: ArgSource :: AsyncFn ( self . lower_pat ( pat) ) ,
2262
+ source : hir:: ArgSource :: Normal ,
2303
2263
}
2304
2264
}
2305
2265
@@ -3028,44 +2988,13 @@ impl<'a> LoweringContext<'a> {
3028
2988
fn lower_async_body (
3029
2989
& mut self ,
3030
2990
decl : & FnDecl ,
3031
- asyncness : & IsAsync ,
2991
+ asyncness : IsAsync ,
3032
2992
body : & Block ,
3033
2993
) -> hir:: BodyId {
3034
2994
self . lower_body ( Some ( & decl) , |this| {
3035
- if let IsAsync :: Async { closure_id, ref arguments, .. } = asyncness {
3036
- let mut body = body. clone ( ) ;
3037
-
3038
- // Async function arguments are lowered into the closure body so that they are
3039
- // captured and so that the drop order matches the equivalent non-async functions.
3040
- //
3041
- // async fn foo(<pattern>: <ty>, <pattern>: <ty>, <pattern>: <ty>) {
3042
- // async move {
3043
- // }
3044
- // }
3045
- //
3046
- // // ...becomes...
3047
- // fn foo(__arg0: <ty>, __arg1: <ty>, __arg2: <ty>) {
3048
- // async move {
3049
- // let __arg2 = __arg2;
3050
- // let <pattern> = __arg2;
3051
- // let __arg1 = __arg1;
3052
- // let <pattern> = __arg1;
3053
- // let __arg0 = __arg0;
3054
- // let <pattern> = __arg0;
3055
- // }
3056
- // }
3057
- //
3058
- // If `<pattern>` is a simple ident, then it is lowered to a single
3059
- // `let <pattern> = <pattern>;` statement as an optimization.
3060
- for a in arguments. iter ( ) . rev ( ) {
3061
- if let Some ( pat_stmt) = a. pat_stmt . clone ( ) {
3062
- body. stmts . insert ( 0 , pat_stmt) ;
3063
- }
3064
- body. stmts . insert ( 0 , a. move_stmt . clone ( ) ) ;
3065
- }
3066
-
2995
+ if let IsAsync :: Async { closure_id, .. } = asyncness {
3067
2996
let async_expr = this. make_async_expr (
3068
- CaptureBy :: Value , * closure_id, None , body. span ,
2997
+ CaptureBy :: Value , closure_id, None , body. span ,
3069
2998
|this| {
3070
2999
let body = this. lower_block ( & body, false ) ;
3071
3000
this. expr_block ( body, ThinVec :: new ( ) )
@@ -3126,47 +3055,26 @@ impl<'a> LoweringContext<'a> {
3126
3055
value
3127
3056
)
3128
3057
}
3129
- ItemKind :: Fn ( ref decl, ref header, ref generics, ref body) => {
3058
+ ItemKind :: Fn ( ref decl, header, ref generics, ref body) => {
3130
3059
let fn_def_id = self . resolver . definitions ( ) . local_def_id ( id) ;
3131
3060
self . with_new_scopes ( |this| {
3061
+ // Note: we don't need to change the return type from `T` to
3062
+ // `impl Future<Output = T>` here because lower_body
3063
+ // only cares about the input argument patterns in the function
3064
+ // declaration (decl), not the return types.
3065
+ let body_id = this. lower_async_body ( decl, header. asyncness . node , body) ;
3066
+ let ( generics, fn_decl) = this. add_in_band_defs (
3067
+ generics,
3068
+ fn_def_id,
3069
+ AnonymousLifetimeMode :: PassThrough ,
3070
+ |this, idty| this. lower_fn_decl (
3071
+ decl,
3072
+ Some ( ( fn_def_id, idty) ) ,
3073
+ true ,
3074
+ header. asyncness . node . opt_return_id ( )
3075
+ ) ,
3076
+ ) ;
3132
3077
this. current_item = Some ( ident. span ) ;
3133
- let mut lower_fn = |decl : & FnDecl | {
3134
- // Note: we don't need to change the return type from `T` to
3135
- // `impl Future<Output = T>` here because lower_body
3136
- // only cares about the input argument patterns in the function
3137
- // declaration (decl), not the return types.
3138
- let body_id = this. lower_async_body ( & decl, & header. asyncness . node , body) ;
3139
-
3140
- let ( generics, fn_decl) = this. add_in_band_defs (
3141
- generics,
3142
- fn_def_id,
3143
- AnonymousLifetimeMode :: PassThrough ,
3144
- |this, idty| this. lower_fn_decl (
3145
- & decl,
3146
- Some ( ( fn_def_id, idty) ) ,
3147
- true ,
3148
- header. asyncness . node . opt_return_id ( )
3149
- ) ,
3150
- ) ;
3151
-
3152
- ( body_id, generics, fn_decl)
3153
- } ;
3154
-
3155
- let ( body_id, generics, fn_decl) = if let IsAsync :: Async {
3156
- arguments, ..
3157
- } = & header. asyncness . node {
3158
- let mut decl = decl. clone ( ) ;
3159
- // Replace the arguments of this async function with the generated
3160
- // arguments that will be moved into the closure.
3161
- for ( i, a) in arguments. clone ( ) . drain ( ..) . enumerate ( ) {
3162
- if let Some ( arg) = a. arg {
3163
- decl. inputs [ i] = arg;
3164
- }
3165
- }
3166
- lower_fn ( & decl)
3167
- } else {
3168
- lower_fn ( decl)
3169
- } ;
3170
3078
3171
3079
hir:: ItemKind :: Fn (
3172
3080
fn_decl,
@@ -3638,36 +3546,15 @@ impl<'a> LoweringContext<'a> {
3638
3546
)
3639
3547
}
3640
3548
ImplItemKind :: Method ( ref sig, ref body) => {
3641
- let mut lower_method = |sig : & MethodSig | {
3642
- let body_id = self . lower_async_body (
3643
- & sig. decl , & sig. header . asyncness . node , body
3644
- ) ;
3645
- let impl_trait_return_allow = !self . is_in_trait_impl ;
3646
- let ( generics, sig) = self . lower_method_sig (
3647
- & i. generics ,
3648
- sig,
3649
- impl_item_def_id,
3650
- impl_trait_return_allow,
3651
- sig. header . asyncness . node . opt_return_id ( ) ,
3652
- ) ;
3653
- ( body_id, generics, sig)
3654
- } ;
3655
-
3656
- let ( body_id, generics, sig) = if let IsAsync :: Async {
3657
- ref arguments, ..
3658
- } = sig. header . asyncness . node {
3659
- let mut sig = sig. clone ( ) ;
3660
- // Replace the arguments of this async function with the generated
3661
- // arguments that will be moved into the closure.
3662
- for ( i, a) in arguments. clone ( ) . drain ( ..) . enumerate ( ) {
3663
- if let Some ( arg) = a. arg {
3664
- sig. decl . inputs [ i] = arg;
3665
- }
3666
- }
3667
- lower_method ( & sig)
3668
- } else {
3669
- lower_method ( sig)
3670
- } ;
3549
+ let body_id = self . lower_async_body ( & sig. decl , sig. header . asyncness . node , body) ;
3550
+ let impl_trait_return_allow = !self . is_in_trait_impl ;
3551
+ let ( generics, sig) = self . lower_method_sig (
3552
+ & i. generics ,
3553
+ sig,
3554
+ impl_item_def_id,
3555
+ impl_trait_return_allow,
3556
+ sig. header . asyncness . node . opt_return_id ( ) ,
3557
+ ) ;
3671
3558
self . current_item = Some ( i. span ) ;
3672
3559
3673
3560
( generics, hir:: ImplItemKind :: Method ( sig, body_id) )
@@ -3860,7 +3747,7 @@ impl<'a> LoweringContext<'a> {
3860
3747
impl_trait_return_allow : bool ,
3861
3748
is_async : Option < NodeId > ,
3862
3749
) -> ( hir:: Generics , hir:: MethodSig ) {
3863
- let header = self . lower_fn_header ( & sig. header ) ;
3750
+ let header = self . lower_fn_header ( sig. header ) ;
3864
3751
let ( generics, decl) = self . add_in_band_defs (
3865
3752
generics,
3866
3753
fn_def_id,
@@ -3882,10 +3769,10 @@ impl<'a> LoweringContext<'a> {
3882
3769
}
3883
3770
}
3884
3771
3885
- fn lower_fn_header ( & mut self , h : & FnHeader ) -> hir:: FnHeader {
3772
+ fn lower_fn_header ( & mut self , h : FnHeader ) -> hir:: FnHeader {
3886
3773
hir:: FnHeader {
3887
3774
unsafety : self . lower_unsafety ( h. unsafety ) ,
3888
- asyncness : self . lower_asyncness ( & h. asyncness . node ) ,
3775
+ asyncness : self . lower_asyncness ( h. asyncness . node ) ,
3889
3776
constness : self . lower_constness ( h. constness ) ,
3890
3777
abi : h. abi ,
3891
3778
}
@@ -3905,7 +3792,7 @@ impl<'a> LoweringContext<'a> {
3905
3792
}
3906
3793
}
3907
3794
3908
- fn lower_asyncness ( & mut self , a : & IsAsync ) -> hir:: IsAsync {
3795
+ fn lower_asyncness ( & mut self , a : IsAsync ) -> hir:: IsAsync {
3909
3796
match a {
3910
3797
IsAsync :: Async { .. } => hir:: IsAsync :: Async ,
3911
3798
IsAsync :: NotAsync => hir:: IsAsync :: NotAsync ,
@@ -4222,7 +4109,7 @@ impl<'a> LoweringContext<'a> {
4222
4109
}
4223
4110
ExprKind :: Await ( _origin, ref expr) => self . lower_await ( e. span , expr) ,
4224
4111
ExprKind :: Closure (
4225
- capture_clause, ref asyncness, movability, ref decl, ref body, fn_decl_span
4112
+ capture_clause, asyncness, movability, ref decl, ref body, fn_decl_span
4226
4113
) => {
4227
4114
if let IsAsync :: Async { closure_id, .. } = asyncness {
4228
4115
let outer_decl = FnDecl {
@@ -4260,7 +4147,7 @@ impl<'a> LoweringContext<'a> {
4260
4147
Some ( & * * ty)
4261
4148
} else { None } ;
4262
4149
let async_body = this. make_async_expr (
4263
- capture_clause, * closure_id, async_ret_ty, body. span ,
4150
+ capture_clause, closure_id, async_ret_ty, body. span ,
4264
4151
|this| {
4265
4152
this. with_new_scopes ( |this| this. lower_expr ( body) )
4266
4153
} ) ;
0 commit comments