Skip to content

Commit 3c7e0eb

Browse files
committed
rustc: construct statement vector directly
This commit simplifies the previous logic to construct the statement vector directly rather than constructing a `Vec` of `(hir::Stmt, Option<hir::Stmt>)` first.
1 parent 3ebe9ab commit 3c7e0eb

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

src/librustc/hir/lowering.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ impl<'a> LoweringContext<'a> {
30343034

30353035
self.lower_body(|this| {
30363036
let mut arguments: Vec<hir::Arg> = Vec::new();
3037-
let mut statements: Vec<(hir::Stmt, Option<hir::Stmt>)> = Vec::new();
3037+
let mut statements: Vec<hir::Stmt> = Vec::new();
30383038

30393039
// Async function arguments are lowered into the closure body so that they are
30403040
// captured and so that the drop order matches the equivalent non-async functions.
@@ -3094,14 +3094,14 @@ impl<'a> LoweringContext<'a> {
30943094
source: hir::ArgSource::AsyncFn
30953095
};
30963096

3097-
let new_statements = if is_simple_argument {
3097+
if is_simple_argument {
30983098
// If this is the simple case, then we only insert one statement that is
30993099
// `let <pat> = <pat>;`. We re-use the original argument's pattern so that
31003100
// `HirId`s are densely assigned.
31013101
let expr = this.expr_ident(desugared_span, ident, new_argument_id);
31023102
let stmt = this.stmt_let_pat(
31033103
desugared_span, Some(P(expr)), argument.pat, hir::LocalSource::AsyncFn);
3104-
(stmt, None)
3104+
statements.push(stmt);
31053105
} else {
31063106
// If this is not the simple case, then we construct two statements:
31073107
//
@@ -3131,26 +3131,17 @@ impl<'a> LoweringContext<'a> {
31313131
desugared_span, Some(P(pattern_expr)), argument.pat,
31323132
hir::LocalSource::AsyncFn);
31333133

3134-
(move_stmt, Some(pattern_stmt))
3134+
statements.push(move_stmt);
3135+
statements.push(pattern_stmt);
31353136
};
31363137

31373138
arguments.push(new_argument);
3138-
statements.push(new_statements);
31393139
}
31403140

31413141
let async_expr = this.make_async_expr(
31423142
CaptureBy::Value, closure_id, None, body.span,
31433143
|this| {
3144-
let mut stmts = vec![];
3145-
for (move_stmt, pattern_stmt) in statements.drain(..) {
3146-
// Insert the `let __argN = __argN` statement first.
3147-
stmts.push(move_stmt);
3148-
// Then insert the `let <pat> = __argN` statement, if there is one.
3149-
if let Some(pattern_stmt) = pattern_stmt {
3150-
stmts.push(pattern_stmt);
3151-
}
3152-
}
3153-
let body = this.lower_block_with_stmts(body, false, stmts);
3144+
let body = this.lower_block_with_stmts(body, false, statements);
31543145
this.expr_block(body, ThinVec::new())
31553146
});
31563147
(HirVec::from(arguments), this.expr(body.span, async_expr, ThinVec::new()))
@@ -5220,10 +5211,6 @@ impl<'a> LoweringContext<'a> {
52205211
}
52215212
}
52225213

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-
52275214
fn stmt(&mut self, span: Span, node: hir::StmtKind) -> hir::Stmt {
52285215
hir::Stmt { span, node, hir_id: self.next_id() }
52295216
}

0 commit comments

Comments
 (0)