@@ -3039,12 +3039,15 @@ impl<'a> LoweringContext<'a> {
3039
3039
// Async function arguments are lowered into the closure body so that they are
3040
3040
// captured and so that the drop order matches the equivalent non-async functions.
3041
3041
//
3042
+ // from:
3043
+ //
3042
3044
// async fn foo(<pattern>: <ty>, <pattern>: <ty>, <pattern>: <ty>) {
3043
3045
// async move {
3044
3046
// }
3045
3047
// }
3046
3048
//
3047
- // // ...becomes...
3049
+ // into:
3050
+ //
3048
3051
// fn foo(__arg0: <ty>, __arg1: <ty>, __arg2: <ty>) {
3049
3052
// async move {
3050
3053
// let __arg2 = __arg2;
@@ -3076,61 +3079,29 @@ impl<'a> LoweringContext<'a> {
3076
3079
} ,
3077
3080
} ;
3078
3081
3082
+ let desugared_span =
3083
+ this. mark_span_with_reason ( CompilerDesugaringKind :: Async , span, None ) ;
3084
+
3079
3085
// Construct an argument representing `__argN: <ty>` to replace the argument of the
3080
3086
// async function.
3081
3087
//
3082
3088
// If this is the simple case, this argument will end up being the same as the
3083
3089
// original argument, but with a different pattern id.
3084
- let new_argument_id = this. next_id ( ) ;
3085
- let desugared_span =
3086
- this. mark_span_with_reason ( CompilerDesugaringKind :: Async , span, None ) ;
3090
+ let ( new_argument_pat, new_argument_id) = this. pat_ident ( desugared_span, ident) ;
3087
3091
let new_argument = hir:: Arg {
3088
3092
hir_id : argument. hir_id ,
3089
- pat : P ( hir:: Pat {
3090
- hir_id : new_argument_id,
3091
- node : hir:: PatKind :: Binding ( hir:: BindingAnnotation :: Unannotated ,
3092
- new_argument_id, ident, None ) ,
3093
- span : desugared_span,
3094
- } ) ,
3095
- source : hir:: ArgSource :: AsyncFn ,
3096
- } ;
3097
-
3098
- let construct_stmt = |this : & mut LoweringContext < ' _ > , pat : P < hir:: Pat > ,
3099
- init_pat_id : hir:: HirId | {
3100
- hir:: Stmt {
3101
- hir_id : this. next_id ( ) ,
3102
- node : hir:: StmtKind :: Local ( P ( hir:: Local {
3103
- pat,
3104
- // We explicitly do not specify the type for any statements. When the
3105
- // user's argument type is `impl Trait` then this would require the
3106
- // `impl_trait_in_bindings` feature to also be present for that same
3107
- // type to be valid in this binding. At the time of writing (13 Mar 19),
3108
- // `impl_trait_in_bindings` is not stable.
3109
- ty : None ,
3110
- init : Some ( P ( hir:: Expr {
3111
- span,
3112
- node : hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
3113
- span,
3114
- res : Res :: Local ( init_pat_id) ,
3115
- segments : hir_vec ! [ hir:: PathSegment :: from_ident( ident) ] ,
3116
- } ) ) ) ,
3117
- attrs : ThinVec :: new ( ) ,
3118
- hir_id : this. next_id ( ) ,
3119
- } ) ) ,
3120
- hir_id : this. next_id ( ) ,
3121
- span : desugared_span,
3122
- attrs : ThinVec :: new ( ) ,
3123
- source : hir:: LocalSource :: AsyncFn ,
3124
- } ) ) ,
3125
- span : desugared_span,
3126
- }
3093
+ pat : new_argument_pat,
3094
+ source : hir:: ArgSource :: AsyncFn
3127
3095
} ;
3128
3096
3129
3097
let new_statements = if is_simple_argument {
3130
3098
// If this is the simple case, then we only insert one statement that is
3131
3099
// `let <pat> = <pat>;`. We re-use the original argument's pattern so that
3132
3100
// `HirId`s are densely assigned.
3133
- ( construct_stmt ( this, argument. pat , new_argument_id) , None )
3101
+ let expr = this. expr_ident ( desugared_span, ident, new_argument_id) ;
3102
+ let stmt = this. stmt_let_pat (
3103
+ desugared_span, Some ( P ( expr) ) , argument. pat , hir:: LocalSource :: AsyncFn ) ;
3104
+ ( stmt, None )
3134
3105
} else {
3135
3106
// If this is not the simple case, then we construct two statements:
3136
3107
//
@@ -3147,21 +3118,19 @@ impl<'a> LoweringContext<'a> {
3147
3118
// Construct the `let mut __argN = __argN;` statement. It must be a mut binding
3148
3119
// because the user may have specified a `ref mut` binding in the next
3149
3120
// statement.
3150
- let hir_id = this. next_id ( ) ;
3151
- let move_stmt = construct_stmt (
3152
- this,
3153
- P ( hir:: Pat {
3154
- hir_id,
3155
- node : hir:: PatKind :: Binding ( hir:: BindingAnnotation :: Mutable ,
3156
- hir_id, ident, None ) ,
3157
- span : desugared_span,
3158
- } ) ,
3159
- new_argument_id,
3160
- ) ;
3121
+ let ( move_pat, move_id) = this. pat_ident_binding_mode (
3122
+ desugared_span, ident, hir:: BindingAnnotation :: Mutable ) ;
3123
+ let move_expr = this. expr_ident ( desugared_span, ident, new_argument_id) ;
3124
+ let move_stmt = this. stmt_let_pat (
3125
+ desugared_span, Some ( P ( move_expr) ) , move_pat, hir:: LocalSource :: AsyncFn ) ;
3161
3126
3162
3127
// Construct the `let <pat> = __argN;` statement. We re-use the original
3163
3128
// argument's pattern so that `HirId`s are densely assigned.
3164
- let pattern_stmt = construct_stmt ( this, argument. pat , hir_id) ;
3129
+ let pattern_expr = this. expr_ident ( desugared_span, ident, move_id) ;
3130
+ let pattern_stmt = this. stmt_let_pat (
3131
+ desugared_span, Some ( P ( pattern_expr) ) , argument. pat ,
3132
+ hir:: LocalSource :: AsyncFn ) ;
3133
+
3165
3134
( move_stmt, Some ( pattern_stmt) )
3166
3135
} ;
3167
3136
@@ -5251,6 +5220,10 @@ impl<'a> LoweringContext<'a> {
5251
5220
}
5252
5221
}
5253
5222
5223
+ fn arg ( & mut self , hir_id : hir:: HirId , pat : P < hir:: Pat > , source : hir:: ArgSource ) -> hir:: Arg {
5224
+ hir:: Arg { hir_id, pat, source }
5225
+ }
5226
+
5254
5227
fn stmt ( & mut self , span : Span , node : hir:: StmtKind ) -> hir:: Stmt {
5255
5228
hir:: Stmt { span, node, hir_id : self . next_id ( ) }
5256
5229
}
0 commit comments