Skip to content

Commit 5cba0ac

Browse files
committed
lowering: move make_async_expr -> expr.rs
1 parent 199d585 commit 5cba0ac

File tree

2 files changed

+56
-41
lines changed

2 files changed

+56
-41
lines changed

src/librustc/hir/lowering.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,47 +1151,6 @@ impl<'a> LoweringContext<'a> {
11511151
result
11521152
}
11531153

1154-
fn make_async_expr(
1155-
&mut self,
1156-
capture_clause: CaptureBy,
1157-
closure_node_id: NodeId,
1158-
ret_ty: Option<AstP<Ty>>,
1159-
span: Span,
1160-
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
1161-
) -> hir::ExprKind {
1162-
let capture_clause = self.lower_capture_clause(capture_clause);
1163-
let output = match ret_ty {
1164-
Some(ty) => FunctionRetTy::Ty(ty),
1165-
None => FunctionRetTy::Default(span),
1166-
};
1167-
let ast_decl = FnDecl {
1168-
inputs: vec![],
1169-
output,
1170-
c_variadic: false
1171-
};
1172-
let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None);
1173-
let body_id = self.lower_fn_body(&ast_decl, |this| {
1174-
this.generator_kind = Some(hir::GeneratorKind::Async);
1175-
body(this)
1176-
});
1177-
let generator = hir::Expr {
1178-
hir_id: self.lower_node_id(closure_node_id),
1179-
node: hir::ExprKind::Closure(capture_clause, decl, body_id, span,
1180-
Some(hir::GeneratorMovability::Static)),
1181-
span,
1182-
attrs: ThinVec::new(),
1183-
};
1184-
1185-
let unstable_span = self.mark_span_with_reason(
1186-
DesugaringKind::Async,
1187-
span,
1188-
self.allow_gen_future.clone(),
1189-
);
1190-
let gen_future = self.expr_std_path(
1191-
unstable_span, &[sym::future, sym::from_generator], None, ThinVec::new());
1192-
hir::ExprKind::Call(P(gen_future), hir_vec![generator])
1193-
}
1194-
11951154
fn lower_body(
11961155
&mut self,
11971156
f: impl FnOnce(&mut LoweringContext<'_>) -> (HirVec<hir::Arg>, hir::Expr),

src/librustc/hir/lowering/expr.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,62 @@ impl LoweringContext<'_> {
416416
P(self.expr_call(e.span, from_err, hir_vec![e]))
417417
}
418418

419+
pub(super) fn make_async_expr(
420+
&mut self,
421+
capture_clause: CaptureBy,
422+
closure_node_id: NodeId,
423+
ret_ty: Option<AstP<Ty>>,
424+
span: Span,
425+
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
426+
) -> hir::ExprKind {
427+
let capture_clause = self.lower_capture_clause(capture_clause);
428+
let output = match ret_ty {
429+
Some(ty) => FunctionRetTy::Ty(ty),
430+
None => FunctionRetTy::Default(span),
431+
};
432+
let ast_decl = FnDecl {
433+
inputs: vec![],
434+
output,
435+
c_variadic: false
436+
};
437+
let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None);
438+
let body_id = self.lower_fn_body(&ast_decl, |this| {
439+
this.generator_kind = Some(hir::GeneratorKind::Async);
440+
body(this)
441+
});
442+
443+
// `static || -> <ret_ty> { body }`:
444+
let generator_node = hir::ExprKind::Closure(
445+
capture_clause,
446+
decl,
447+
body_id,
448+
span,
449+
Some(hir::GeneratorMovability::Static)
450+
);
451+
let generator = hir::Expr {
452+
hir_id: self.lower_node_id(closure_node_id),
453+
node: generator_node,
454+
span,
455+
attrs: ThinVec::new(),
456+
};
457+
458+
// `future::from_generator`:
459+
let unstable_span = self.mark_span_with_reason(
460+
DesugaringKind::Async,
461+
span,
462+
self.allow_gen_future.clone(),
463+
);
464+
let gen_future = self.expr_std_path(
465+
unstable_span,
466+
&[sym::future, sym::from_generator],
467+
None,
468+
ThinVec::new()
469+
);
470+
471+
// `future::from_generator(generator)`:
472+
hir::ExprKind::Call(P(gen_future), hir_vec![generator])
473+
}
474+
419475
/// Desugar `<expr>.await` into:
420476
/// ```rust
421477
/// {

0 commit comments

Comments
 (0)