@@ -1099,8 +1099,7 @@ impl LoweringContext<'_> {
1099
1099
// from:
1100
1100
//
1101
1101
// async fn foo(<pattern>: <ty>, <pattern>: <ty>, <pattern>: <ty>) {
1102
- // async move {
1103
- // }
1102
+ // <body>
1104
1103
// }
1105
1104
//
1106
1105
// into:
@@ -1113,11 +1112,19 @@ impl LoweringContext<'_> {
1113
1112
// let <pattern> = __arg1;
1114
1113
// let __arg0 = __arg0;
1115
1114
// let <pattern> = __arg0;
1115
+ // drop-temps { <body> } // see comments later in fn for details
1116
1116
// }
1117
1117
// }
1118
1118
//
1119
1119
// If `<pattern>` is a simple ident, then it is lowered to a single
1120
1120
// `let <pattern> = <pattern>;` statement as an optimization.
1121
+ //
1122
+ // Note that the body is embedded in `drop-temps`; an
1123
+ // equivalent desugaring would be `return { <body>
1124
+ // };`. The key point is that we wish to drop all the
1125
+ // let-bound variables and temporaries created in the body
1126
+ // (and its tail expression!) before we drop the
1127
+ // parameters (c.f. rust-lang/rust#64512).
1121
1128
for ( index, parameter) in decl. inputs . iter ( ) . enumerate ( ) {
1122
1129
let parameter = this. lower_param ( parameter) ;
1123
1130
let span = parameter. pat . span ;
@@ -1231,7 +1238,7 @@ impl LoweringContext<'_> {
1231
1238
ThinVec :: new ( ) ,
1232
1239
) ;
1233
1240
1234
- // Create a block like
1241
+ // As noted above, create the final block like
1235
1242
//
1236
1243
// ```
1237
1244
// {
@@ -1240,13 +1247,6 @@ impl LoweringContext<'_> {
1240
1247
// drop-temps { <user-body> }
1241
1248
// }
1242
1249
// ```
1243
- //
1244
- // This construction is carefully calibrated to
1245
- // get the drop-order correct. In particular, the
1246
- // drop-temps ensures that any temporaries in the
1247
- // tail expression of `<user-body>` are dropped
1248
- // *before* the parameters are dropped (see
1249
- // rust-lang/rust#64512).
1250
1250
let body = this. block_all (
1251
1251
desugared_span,
1252
1252
statements. into ( ) ,
0 commit comments