Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011
Make `ExprKind::Closure` a struct variant. Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`. r? ``@Aaron1011``
This commit is contained in:
commit
87e373e82f
75 changed files with 251 additions and 216 deletions
|
@ -577,7 +577,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
};
|
||||
|
||||
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
|
||||
let decl = self.arena.alloc(hir::FnDecl {
|
||||
let fn_decl = self.arena.alloc(hir::FnDecl {
|
||||
inputs: arena_vec![self; input_ty],
|
||||
output,
|
||||
c_variadic: false,
|
||||
|
@ -598,7 +598,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
};
|
||||
let params = arena_vec![self; param];
|
||||
|
||||
let body_id = self.lower_body(move |this| {
|
||||
let body = self.lower_body(move |this| {
|
||||
this.generator_kind = Some(hir::GeneratorKind::Async(async_gen_kind));
|
||||
|
||||
let old_ctx = this.task_context;
|
||||
|
@ -609,13 +609,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
});
|
||||
|
||||
// `static |_task_context| -> <ret_ty> { body }`:
|
||||
let generator_kind = hir::ExprKind::Closure(
|
||||
let generator_kind = hir::ExprKind::Closure {
|
||||
capture_clause,
|
||||
decl,
|
||||
body_id,
|
||||
self.lower_span(span),
|
||||
Some(hir::Movability::Static),
|
||||
);
|
||||
fn_decl,
|
||||
body,
|
||||
fn_decl_span: self.lower_span(span),
|
||||
movability: Some(hir::Movability::Static),
|
||||
};
|
||||
let generator = hir::Expr {
|
||||
hir_id: self.lower_node_id(closure_node_id),
|
||||
kind: generator_kind,
|
||||
|
@ -840,7 +840,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
body: &Expr,
|
||||
fn_decl_span: Span,
|
||||
) -> hir::ExprKind<'hir> {
|
||||
let (body_id, generator_option) = self.with_new_scopes(move |this| {
|
||||
let (body, generator_option) = self.with_new_scopes(move |this| {
|
||||
let prev = this.current_item;
|
||||
this.current_item = Some(fn_decl_span);
|
||||
let mut generator_kind = None;
|
||||
|
@ -858,13 +858,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
// Lower outside new scope to preserve `is_in_loop_condition`.
|
||||
let fn_decl = self.lower_fn_decl(decl, None, FnDeclKind::Closure, None);
|
||||
|
||||
hir::ExprKind::Closure(
|
||||
hir::ExprKind::Closure {
|
||||
capture_clause,
|
||||
fn_decl,
|
||||
body_id,
|
||||
self.lower_span(fn_decl_span),
|
||||
generator_option,
|
||||
)
|
||||
body,
|
||||
fn_decl_span: self.lower_span(fn_decl_span),
|
||||
movability: generator_option,
|
||||
}
|
||||
}
|
||||
|
||||
fn generator_movability_for_fn(
|
||||
|
@ -911,7 +911,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
let outer_decl =
|
||||
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
|
||||
|
||||
let body_id = self.with_new_scopes(|this| {
|
||||
let body = self.with_new_scopes(|this| {
|
||||
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
|
||||
if capture_clause == CaptureBy::Ref && !decl.inputs.is_empty() {
|
||||
struct_span_err!(
|
||||
|
@ -950,13 +950,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
// closure argument types.
|
||||
let fn_decl = self.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);
|
||||
|
||||
hir::ExprKind::Closure(
|
||||
hir::ExprKind::Closure {
|
||||
capture_clause,
|
||||
fn_decl,
|
||||
body_id,
|
||||
self.lower_span(fn_decl_span),
|
||||
None,
|
||||
)
|
||||
body,
|
||||
fn_decl_span: self.lower_span(fn_decl_span),
|
||||
movability: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Destructure the LHS of complex assignments.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue