Remove the NodeId
of ast::ExprKind::Async
This commit is contained in:
parent
ab9bb3ea36
commit
c8ead2e693
@ -1426,13 +1426,9 @@ pub enum ExprKind {
|
|||||||
Block(P<Block>, Option<Label>),
|
Block(P<Block>, Option<Label>),
|
||||||
/// An async block (`async move { ... }`).
|
/// An async block (`async move { ... }`).
|
||||||
///
|
///
|
||||||
/// The `NodeId` is the `NodeId` for the closure that results from
|
/// The async block used to have a `NodeId`, which was removed in favor of
|
||||||
/// desugaring an async block, just like the NodeId field in the
|
/// using the parent `NodeId` of the parent `Expr`.
|
||||||
/// `Async::Yes` variant. This is necessary in order to create a def for the
|
Async(CaptureBy, P<Block>),
|
||||||
/// closure which can be used as a parent of any child defs. Defs
|
|
||||||
/// created during lowering cannot be made the parent of any other
|
|
||||||
/// preexisting defs.
|
|
||||||
Async(CaptureBy, NodeId, P<Block>),
|
|
||||||
/// An await expression (`my_future.await`).
|
/// An await expression (`my_future.await`).
|
||||||
Await(P<Expr>),
|
Await(P<Expr>),
|
||||||
|
|
||||||
|
@ -1407,8 +1407,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
|||||||
vis.visit_block(blk);
|
vis.visit_block(blk);
|
||||||
visit_opt(label, |label| vis.visit_label(label));
|
visit_opt(label, |label| vis.visit_label(label));
|
||||||
}
|
}
|
||||||
ExprKind::Async(_capture_by, node_id, body) => {
|
ExprKind::Async(_capture_by, body) => {
|
||||||
vis.visit_id(node_id);
|
|
||||||
vis.visit_block(body);
|
vis.visit_block(body);
|
||||||
}
|
}
|
||||||
ExprKind::Await(expr) => vis.visit_expr(expr),
|
ExprKind::Await(expr) => vis.visit_expr(expr),
|
||||||
|
@ -860,7 +860,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
|
|||||||
walk_list!(visitor, visit_label, opt_label);
|
walk_list!(visitor, visit_label, opt_label);
|
||||||
visitor.visit_block(block);
|
visitor.visit_block(block);
|
||||||
}
|
}
|
||||||
ExprKind::Async(_, _, body) => {
|
ExprKind::Async(_, body) => {
|
||||||
visitor.visit_block(body);
|
visitor.visit_block(body);
|
||||||
}
|
}
|
||||||
ExprKind::Await(expr) => visitor.visit_expr(expr),
|
ExprKind::Await(expr) => visitor.visit_expr(expr),
|
||||||
|
@ -63,20 +63,6 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
|
|||||||
ExprKind::ForLoop(pat, head, body, opt_label) => {
|
ExprKind::ForLoop(pat, head, body, opt_label) => {
|
||||||
return self.lower_expr_for(e, pat, head, body, *opt_label);
|
return self.lower_expr_for(e, pat, head, body, *opt_label);
|
||||||
}
|
}
|
||||||
// Similarly, async blocks do not use `e.id` but rather `closure_node_id`.
|
|
||||||
ExprKind::Async(capture_clause, closure_node_id, block) => {
|
|
||||||
let hir_id = self.lower_node_id(*closure_node_id);
|
|
||||||
self.lower_attrs(hir_id, &e.attrs);
|
|
||||||
return self.make_async_expr(
|
|
||||||
*capture_clause,
|
|
||||||
hir_id,
|
|
||||||
*closure_node_id,
|
|
||||||
None,
|
|
||||||
e.span,
|
|
||||||
hir::AsyncGeneratorKind::Block,
|
|
||||||
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +173,14 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
|
|||||||
self.arena.alloc_from_iter(arms.iter().map(|x| self.lower_arm(x))),
|
self.arena.alloc_from_iter(arms.iter().map(|x| self.lower_arm(x))),
|
||||||
hir::MatchSource::Normal,
|
hir::MatchSource::Normal,
|
||||||
),
|
),
|
||||||
|
ExprKind::Async(capture_clause, block) => self.make_async_expr(
|
||||||
|
*capture_clause,
|
||||||
|
e.id,
|
||||||
|
None,
|
||||||
|
e.span,
|
||||||
|
hir::AsyncGeneratorKind::Block,
|
||||||
|
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
|
||||||
|
),
|
||||||
ExprKind::Await(expr) => {
|
ExprKind::Await(expr) => {
|
||||||
let dot_await_span = if expr.span.hi() < e.span.hi() {
|
let dot_await_span = if expr.span.hi() < e.span.hi() {
|
||||||
let span_with_whitespace = self
|
let span_with_whitespace = self
|
||||||
@ -320,7 +314,7 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
|
|||||||
),
|
),
|
||||||
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
|
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
|
||||||
|
|
||||||
ExprKind::Paren(_) | ExprKind::ForLoop(..) | ExprKind::Async(..) => {
|
ExprKind::Paren(_) | ExprKind::ForLoop(..) => {
|
||||||
unreachable!("already handled")
|
unreachable!("already handled")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,13 +585,12 @@ fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
|
|||||||
pub(super) fn make_async_expr(
|
pub(super) fn make_async_expr(
|
||||||
&mut self,
|
&mut self,
|
||||||
capture_clause: CaptureBy,
|
capture_clause: CaptureBy,
|
||||||
outer_hir_id: hir::HirId,
|
|
||||||
closure_node_id: NodeId,
|
closure_node_id: NodeId,
|
||||||
ret_ty: Option<hir::FnRetTy<'hir>>,
|
ret_ty: Option<hir::FnRetTy<'hir>>,
|
||||||
span: Span,
|
span: Span,
|
||||||
async_gen_kind: hir::AsyncGeneratorKind,
|
async_gen_kind: hir::AsyncGeneratorKind,
|
||||||
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
|
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
|
||||||
) -> hir::Expr<'hir> {
|
) -> hir::ExprKind<'hir> {
|
||||||
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
|
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
|
||||||
|
|
||||||
// Resume argument type: `ResumeTy`
|
// Resume argument type: `ResumeTy`
|
||||||
@ -644,8 +637,7 @@ pub(super) fn make_async_expr(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// `static |_task_context| -> <ret_ty> { body }`:
|
// `static |_task_context| -> <ret_ty> { body }`:
|
||||||
let generator_kind = {
|
hir::ExprKind::Closure(self.arena.alloc(hir::Closure {
|
||||||
let c = self.arena.alloc(hir::Closure {
|
|
||||||
def_id: self.local_def_id(closure_node_id),
|
def_id: self.local_def_id(closure_node_id),
|
||||||
binder: hir::ClosureBinder::Default,
|
binder: hir::ClosureBinder::Default,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
@ -656,12 +648,17 @@ pub(super) fn make_async_expr(
|
|||||||
fn_arg_span: None,
|
fn_arg_span: None,
|
||||||
movability: Some(hir::Movability::Static),
|
movability: Some(hir::Movability::Static),
|
||||||
constness: hir::Constness::NotConst,
|
constness: hir::Constness::NotConst,
|
||||||
});
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
hir::ExprKind::Closure(c)
|
/// Forwards a possible `#[track_caller]` annotation from `outer_hir_id` to
|
||||||
};
|
/// `inner_hir_id` in case the `closure_track_caller` feature is enabled.
|
||||||
|
pub(super) fn maybe_forward_track_caller(
|
||||||
let hir_id = self.lower_node_id(closure_node_id);
|
&mut self,
|
||||||
|
span: Span,
|
||||||
|
outer_hir_id: hir::HirId,
|
||||||
|
inner_hir_id: hir::HirId,
|
||||||
|
) {
|
||||||
if self.tcx.features().closure_track_caller
|
if self.tcx.features().closure_track_caller
|
||||||
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
|
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
|
||||||
&& attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
|
&& attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
|
||||||
@ -669,7 +666,7 @@ pub(super) fn make_async_expr(
|
|||||||
let unstable_span =
|
let unstable_span =
|
||||||
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
|
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
|
||||||
self.lower_attrs(
|
self.lower_attrs(
|
||||||
hir_id,
|
inner_hir_id,
|
||||||
&[Attribute {
|
&[Attribute {
|
||||||
kind: AttrKind::Normal(ptr::P(NormalAttr {
|
kind: AttrKind::Normal(ptr::P(NormalAttr {
|
||||||
item: AttrItem {
|
item: AttrItem {
|
||||||
@ -685,8 +682,6 @@ pub(super) fn make_async_expr(
|
|||||||
}],
|
}],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Desugar `<expr>.await` into:
|
/// Desugar `<expr>.await` into:
|
||||||
@ -1001,15 +996,17 @@ fn lower_expr_async_closure(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
this.make_async_expr(
|
let async_body = this.make_async_expr(
|
||||||
capture_clause,
|
capture_clause,
|
||||||
closure_hir_id,
|
|
||||||
inner_closure_id,
|
inner_closure_id,
|
||||||
async_ret_ty,
|
async_ret_ty,
|
||||||
body.span,
|
body.span,
|
||||||
hir::AsyncGeneratorKind::Closure,
|
hir::AsyncGeneratorKind::Closure,
|
||||||
|this| this.with_new_scopes(|this| this.lower_expr_mut(body)),
|
|this| this.with_new_scopes(|this| this.lower_expr_mut(body)),
|
||||||
)
|
);
|
||||||
|
let hir_id = this.lower_node_id(inner_closure_id);
|
||||||
|
this.maybe_forward_track_caller(body.span, closure_hir_id, hir_id);
|
||||||
|
hir::Expr { hir_id, kind: async_body, span: this.lower_span(body.span) }
|
||||||
});
|
});
|
||||||
body_id
|
body_id
|
||||||
});
|
});
|
||||||
|
@ -1146,7 +1146,6 @@ fn lower_maybe_async_body(
|
|||||||
|
|
||||||
let async_expr = this.make_async_expr(
|
let async_expr = this.make_async_expr(
|
||||||
CaptureBy::Value,
|
CaptureBy::Value,
|
||||||
fn_id,
|
|
||||||
closure_id,
|
closure_id,
|
||||||
None,
|
None,
|
||||||
body.span,
|
body.span,
|
||||||
@ -1180,7 +1179,11 @@ fn lower_maybe_async_body(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
(this.arena.alloc_from_iter(parameters), async_expr)
|
let hir_id = this.lower_node_id(closure_id);
|
||||||
|
this.maybe_forward_track_caller(body.span, fn_id, hir_id);
|
||||||
|
let expr = hir::Expr { hir_id, kind: async_expr, span: this.lower_span(body.span) };
|
||||||
|
|
||||||
|
(this.arena.alloc_from_iter(parameters), expr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
|
|||||||
self.ibox(0);
|
self.ibox(0);
|
||||||
self.print_block_with_attrs(blk, attrs);
|
self.print_block_with_attrs(blk, attrs);
|
||||||
}
|
}
|
||||||
ast::ExprKind::Async(capture_clause, _, blk) => {
|
ast::ExprKind::Async(capture_clause, blk) => {
|
||||||
self.word_nbsp("async");
|
self.word_nbsp("async");
|
||||||
self.print_capture_clause(*capture_clause);
|
self.print_capture_clause(*capture_clause);
|
||||||
// cbox/ibox in analogy to the `ExprKind::Block` arm above
|
// cbox/ibox in analogy to the `ExprKind::Block` arm above
|
||||||
|
@ -287,7 +287,7 @@ fn manage_cond_expr(&mut self, expr: &mut P<Expr>) {
|
|||||||
// sync with the `rfc-2011-nicer-assert-messages/all-expr-kinds.rs` test.
|
// sync with the `rfc-2011-nicer-assert-messages/all-expr-kinds.rs` test.
|
||||||
ExprKind::Assign(_, _, _)
|
ExprKind::Assign(_, _, _)
|
||||||
| ExprKind::AssignOp(_, _, _)
|
| ExprKind::AssignOp(_, _, _)
|
||||||
| ExprKind::Async(_, _, _)
|
| ExprKind::Async(_, _)
|
||||||
| ExprKind::Await(_)
|
| ExprKind::Await(_)
|
||||||
| ExprKind::Block(_, _)
|
| ExprKind::Block(_, _)
|
||||||
| ExprKind::Break(_, _)
|
| ExprKind::Break(_, _)
|
||||||
|
@ -224,8 +224,7 @@ fn visit_expr_post(&mut self, e: &'a ast::Expr) {
|
|||||||
ast::ExprKind::Closure(box ast::Closure {
|
ast::ExprKind::Closure(box ast::Closure {
|
||||||
asyncness: ast::Async::Yes { closure_id, .. },
|
asyncness: ast::Async::Yes { closure_id, .. },
|
||||||
..
|
..
|
||||||
})
|
}) => self.check_id(closure_id),
|
||||||
| ast::ExprKind::Async(_, closure_id, ..) => self.check_id(closure_id),
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2917,7 +2917,7 @@ fn parse_async_block(&mut self) -> PResult<'a, P<Expr>> {
|
|||||||
self.expect_keyword(kw::Async)?;
|
self.expect_keyword(kw::Async)?;
|
||||||
let capture_clause = self.parse_capture_clause()?;
|
let capture_clause = self.parse_capture_clause()?;
|
||||||
let (attrs, body) = self.parse_inner_attrs_and_block()?;
|
let (attrs, body) = self.parse_inner_attrs_and_block()?;
|
||||||
let kind = ExprKind::Async(capture_clause, DUMMY_NODE_ID, body);
|
let kind = ExprKind::Async(capture_clause, body);
|
||||||
Ok(self.mk_expr_with_attrs(lo.to(self.prev_token.span), kind, attrs))
|
Ok(self.mk_expr_with_attrs(lo.to(self.prev_token.span), kind, attrs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,9 +260,7 @@ fn visit_expr(&mut self, expr: &'a Expr) {
|
|||||||
Async::No => closure_def,
|
Async::No => closure_def,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Async(_, async_id, _) => {
|
ExprKind::Async(_, _) => self.create_def(expr.id, DefPathData::ClosureExpr, expr.span),
|
||||||
self.create_def(async_id, DefPathData::ClosureExpr, expr.span)
|
|
||||||
}
|
|
||||||
_ => self.parent_def,
|
_ => self.parent_def,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
|||||||
if expr.span.from_expansion() {
|
if expr.span.from_expansion() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let ExprKind::Async(_, _, block) = &expr.kind && block.stmts.len() == 1 &&
|
if let ExprKind::Async(_, block) = &expr.kind && block.stmts.len() == 1 &&
|
||||||
let Some(Stmt { kind: StmtKind::Expr(last), .. }) = block.stmts.last() &&
|
let Some(Stmt { kind: StmtKind::Expr(last), .. }) = block.stmts.last() &&
|
||||||
let ExprKind::Await(future) = &last.kind &&
|
let ExprKind::Await(future) = &last.kind &&
|
||||||
!future.span.from_expansion() &&
|
!future.span.from_expansion() &&
|
||||||
|
@ -578,7 +578,7 @@ fn ident_difference_expr_with_base_location(
|
|||||||
| (Assign(_, _, _), Assign(_, _, _))
|
| (Assign(_, _, _), Assign(_, _, _))
|
||||||
| (TryBlock(_), TryBlock(_))
|
| (TryBlock(_), TryBlock(_))
|
||||||
| (Await(_), Await(_))
|
| (Await(_), Await(_))
|
||||||
| (Async(_, _, _), Async(_, _, _))
|
| (Async(_, _), Async(_, _))
|
||||||
| (Block(_, _), Block(_, _))
|
| (Block(_, _), Block(_, _))
|
||||||
| (Closure(_), Closure(_))
|
| (Closure(_), Closure(_))
|
||||||
| (Match(_, _), Match(_, _))
|
| (Match(_, _), Match(_, _))
|
||||||
|
@ -209,7 +209,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
|||||||
&& eq_fn_decl(lf, rf)
|
&& eq_fn_decl(lf, rf)
|
||||||
&& eq_expr(le, re)
|
&& eq_expr(le, re)
|
||||||
},
|
},
|
||||||
(Async(lc, _, lb), Async(rc, _, rb)) => lc == rc && eq_block(lb, rb),
|
(Async(lc, lb), Async(rc, rb)) => lc == rc && eq_block(lb, rb),
|
||||||
(Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt),
|
(Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt),
|
||||||
(AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re),
|
(AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re),
|
||||||
(Path(lq, lp), Path(rq, rp)) => both(lq, rq, eq_qself) && eq_path(lp, rp),
|
(Path(lq, lp), Path(rq, rp)) => both(lq, rq, eq_qself) && eq_path(lp, rp),
|
||||||
|
@ -366,7 +366,7 @@ fn needs_space_after_range(rhs: &ast::Expr) -> bool {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::ExprKind::Async(capture_by, _node_id, ref block) => {
|
ast::ExprKind::Async(capture_by, ref block) => {
|
||||||
let mover = if capture_by == ast::CaptureBy::Value {
|
let mover = if capture_by == ast::CaptureBy::Value {
|
||||||
"move "
|
"move "
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user