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>),
|
||||
/// An async block (`async move { ... }`).
|
||||
///
|
||||
/// The `NodeId` is the `NodeId` for the closure that results from
|
||||
/// desugaring an async block, just like the NodeId field in the
|
||||
/// `Async::Yes` variant. This is necessary in order to create a def for the
|
||||
/// 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>),
|
||||
/// The async block used to have a `NodeId`, which was removed in favor of
|
||||
/// using the parent `NodeId` of the parent `Expr`.
|
||||
Async(CaptureBy, P<Block>),
|
||||
/// An await expression (`my_future.await`).
|
||||
Await(P<Expr>),
|
||||
|
||||
|
@ -1407,8 +1407,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
||||
vis.visit_block(blk);
|
||||
visit_opt(label, |label| vis.visit_label(label));
|
||||
}
|
||||
ExprKind::Async(_capture_by, node_id, body) => {
|
||||
vis.visit_id(node_id);
|
||||
ExprKind::Async(_capture_by, body) => {
|
||||
vis.visit_block(body);
|
||||
}
|
||||
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);
|
||||
visitor.visit_block(block);
|
||||
}
|
||||
ExprKind::Async(_, _, body) => {
|
||||
ExprKind::Async(_, body) => {
|
||||
visitor.visit_block(body);
|
||||
}
|
||||
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) => {
|
||||
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))),
|
||||
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) => {
|
||||
let dot_await_span = if expr.span.hi() < e.span.hi() {
|
||||
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::Paren(_) | ExprKind::ForLoop(..) | ExprKind::Async(..) => {
|
||||
ExprKind::Paren(_) | ExprKind::ForLoop(..) => {
|
||||
unreachable!("already handled")
|
||||
}
|
||||
|
||||
@ -591,13 +585,12 @@ fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
|
||||
pub(super) fn make_async_expr(
|
||||
&mut self,
|
||||
capture_clause: CaptureBy,
|
||||
outer_hir_id: hir::HirId,
|
||||
closure_node_id: NodeId,
|
||||
ret_ty: Option<hir::FnRetTy<'hir>>,
|
||||
span: Span,
|
||||
async_gen_kind: hir::AsyncGeneratorKind,
|
||||
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)));
|
||||
|
||||
// Resume argument type: `ResumeTy`
|
||||
@ -644,24 +637,28 @@ pub(super) fn make_async_expr(
|
||||
});
|
||||
|
||||
// `static |_task_context| -> <ret_ty> { body }`:
|
||||
let generator_kind = {
|
||||
let c = self.arena.alloc(hir::Closure {
|
||||
def_id: self.local_def_id(closure_node_id),
|
||||
binder: hir::ClosureBinder::Default,
|
||||
capture_clause,
|
||||
bound_generic_params: &[],
|
||||
fn_decl,
|
||||
body,
|
||||
fn_decl_span: self.lower_span(span),
|
||||
fn_arg_span: None,
|
||||
movability: Some(hir::Movability::Static),
|
||||
constness: hir::Constness::NotConst,
|
||||
});
|
||||
hir::ExprKind::Closure(self.arena.alloc(hir::Closure {
|
||||
def_id: self.local_def_id(closure_node_id),
|
||||
binder: hir::ClosureBinder::Default,
|
||||
capture_clause,
|
||||
bound_generic_params: &[],
|
||||
fn_decl,
|
||||
body,
|
||||
fn_decl_span: self.lower_span(span),
|
||||
fn_arg_span: None,
|
||||
movability: Some(hir::Movability::Static),
|
||||
constness: hir::Constness::NotConst,
|
||||
}))
|
||||
}
|
||||
|
||||
hir::ExprKind::Closure(c)
|
||||
};
|
||||
|
||||
let hir_id = self.lower_node_id(closure_node_id);
|
||||
/// 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(
|
||||
&mut self,
|
||||
span: Span,
|
||||
outer_hir_id: hir::HirId,
|
||||
inner_hir_id: hir::HirId,
|
||||
) {
|
||||
if self.tcx.features().closure_track_caller
|
||||
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
|
||||
&& attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
|
||||
@ -669,7 +666,7 @@ pub(super) fn make_async_expr(
|
||||
let unstable_span =
|
||||
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
|
||||
self.lower_attrs(
|
||||
hir_id,
|
||||
inner_hir_id,
|
||||
&[Attribute {
|
||||
kind: AttrKind::Normal(ptr::P(NormalAttr {
|
||||
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:
|
||||
@ -1001,15 +996,17 @@ fn lower_expr_async_closure(
|
||||
None
|
||||
};
|
||||
|
||||
this.make_async_expr(
|
||||
let async_body = this.make_async_expr(
|
||||
capture_clause,
|
||||
closure_hir_id,
|
||||
inner_closure_id,
|
||||
async_ret_ty,
|
||||
body.span,
|
||||
hir::AsyncGeneratorKind::Closure,
|
||||
|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
|
||||
});
|
||||
|
@ -1146,7 +1146,6 @@ fn lower_maybe_async_body(
|
||||
|
||||
let async_expr = this.make_async_expr(
|
||||
CaptureBy::Value,
|
||||
fn_id,
|
||||
closure_id,
|
||||
None,
|
||||
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.print_block_with_attrs(blk, attrs);
|
||||
}
|
||||
ast::ExprKind::Async(capture_clause, _, blk) => {
|
||||
ast::ExprKind::Async(capture_clause, blk) => {
|
||||
self.word_nbsp("async");
|
||||
self.print_capture_clause(*capture_clause);
|
||||
// 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.
|
||||
ExprKind::Assign(_, _, _)
|
||||
| ExprKind::AssignOp(_, _, _)
|
||||
| ExprKind::Async(_, _, _)
|
||||
| ExprKind::Async(_, _)
|
||||
| ExprKind::Await(_)
|
||||
| ExprKind::Block(_, _)
|
||||
| ExprKind::Break(_, _)
|
||||
|
@ -224,8 +224,7 @@ fn visit_expr_post(&mut self, e: &'a ast::Expr) {
|
||||
ast::ExprKind::Closure(box ast::Closure {
|
||||
asyncness: ast::Async::Yes { closure_id, .. },
|
||||
..
|
||||
})
|
||||
| ast::ExprKind::Async(_, closure_id, ..) => self.check_id(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)?;
|
||||
let capture_clause = self.parse_capture_clause()?;
|
||||
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))
|
||||
}
|
||||
|
||||
|
@ -260,9 +260,7 @@ fn visit_expr(&mut self, expr: &'a Expr) {
|
||||
Async::No => closure_def,
|
||||
}
|
||||
}
|
||||
ExprKind::Async(_, async_id, _) => {
|
||||
self.create_def(async_id, DefPathData::ClosureExpr, expr.span)
|
||||
}
|
||||
ExprKind::Async(_, _) => self.create_def(expr.id, DefPathData::ClosureExpr, expr.span),
|
||||
_ => self.parent_def,
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,7 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if expr.span.from_expansion() {
|
||||
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 ExprKind::Await(future) = &last.kind &&
|
||||
!future.span.from_expansion() &&
|
||||
|
@ -578,7 +578,7 @@ fn ident_difference_expr_with_base_location(
|
||||
| (Assign(_, _, _), Assign(_, _, _))
|
||||
| (TryBlock(_), TryBlock(_))
|
||||
| (Await(_), Await(_))
|
||||
| (Async(_, _, _), Async(_, _, _))
|
||||
| (Async(_, _), Async(_, _))
|
||||
| (Block(_, _), Block(_, _))
|
||||
| (Closure(_), Closure(_))
|
||||
| (Match(_, _), Match(_, _))
|
||||
|
@ -209,7 +209,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
||||
&& eq_fn_decl(lf, rf)
|
||||
&& 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),
|
||||
(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),
|
||||
|
@ -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 {
|
||||
"move "
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user