Skip to content

Commit f0fc4f9

Browse files
Tweak await span
1 parent 12a2f24 commit f0fc4f9

File tree

86 files changed

+479
-400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+479
-400
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,8 +1430,8 @@ pub enum ExprKind {
14301430
/// The async block used to have a `NodeId`, which was removed in favor of
14311431
/// using the parent `NodeId` of the parent `Expr`.
14321432
Async(CaptureBy, P<Block>),
1433-
/// An await expression (`my_future.await`).
1434-
Await(P<Expr>),
1433+
/// An await expression (`my_future.await`). Span is of await keyword.
1434+
Await(P<Expr>, Span),
14351435

14361436
/// A try block (`try { ... }`).
14371437
TryBlock(P<Block>),

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,10 @@ pub fn noop_visit_expr<T: MutVisitor>(
14151415
ExprKind::Async(_capture_by, body) => {
14161416
vis.visit_block(body);
14171417
}
1418-
ExprKind::Await(expr) => vis.visit_expr(expr),
1418+
ExprKind::Await(expr, await_kw_span) => {
1419+
vis.visit_expr(expr);
1420+
vis.visit_span(await_kw_span);
1421+
}
14191422
ExprKind::Assign(el, er, _) => {
14201423
vis.visit_expr(el);
14211424
vis.visit_expr(er);

compiler/rustc_ast/src/util/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
388388
// X { y: 1 } + X { y: 2 }
389389
contains_exterior_struct_lit(lhs) || contains_exterior_struct_lit(rhs)
390390
}
391-
ast::ExprKind::Await(x)
391+
ast::ExprKind::Await(x, _)
392392
| ast::ExprKind::Unary(_, x)
393393
| ast::ExprKind::Cast(x, _)
394394
| ast::ExprKind::Type(x, _)

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
864864
ExprKind::Async(_, body) => {
865865
visitor.visit_block(body);
866866
}
867-
ExprKind::Await(expr) => visitor.visit_expr(expr),
867+
ExprKind::Await(expr, _) => visitor.visit_expr(expr),
868868
ExprKind::Assign(lhs, rhs, _) => {
869869
visitor.visit_expr(lhs);
870870
visitor.visit_expr(rhs);

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
185185
hir::AsyncGeneratorKind::Block,
186186
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
187187
),
188-
ExprKind::Await(expr) => {
189-
let dot_await_span = if expr.span.hi() < e.span.hi() {
190-
let span_with_whitespace = self
191-
.tcx
192-
.sess
193-
.source_map()
194-
.span_extend_while(expr.span, char::is_whitespace)
195-
.unwrap_or(expr.span);
196-
span_with_whitespace.shrink_to_hi().with_hi(e.span.hi())
188+
ExprKind::Await(expr, await_kw_span) => {
189+
let await_kw_span = if expr.span.hi() < await_kw_span.hi() {
190+
*await_kw_span
197191
} else {
198192
// this is a recovered `await expr`
199193
e.span
200194
};
201-
self.lower_expr_await(dot_await_span, expr)
195+
self.lower_expr_await(await_kw_span, expr)
202196
}
203197
ExprKind::Closure(box Closure {
204198
binder,
@@ -710,18 +704,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
710704
/// }
711705
/// }
712706
/// ```
713-
fn lower_expr_await(&mut self, dot_await_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
714-
let full_span = expr.span.to(dot_await_span);
707+
fn lower_expr_await(&mut self, await_kw_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
708+
let full_span = expr.span.to(await_kw_span);
715709
match self.generator_kind {
716710
Some(hir::GeneratorKind::Async(_)) => {}
717711
Some(hir::GeneratorKind::Gen) | None => {
718712
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
719-
dot_await_span,
713+
dot_await_span: await_kw_span,
720714
item_span: self.current_item,
721715
});
722716
}
723717
}
724-
let span = self.mark_span_with_reason(DesugaringKind::Await, dot_await_span, None);
718+
let span = self.mark_span_with_reason(DesugaringKind::Await, await_kw_span, None);
725719
let gen_future_span = self.mark_span_with_reason(
726720
DesugaringKind::Await,
727721
full_span,

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ fn may_contain_yield_point(e: &ast::Expr) -> bool {
583583

584584
impl Visitor<'_> for MayContainYieldPoint {
585585
fn visit_expr(&mut self, e: &ast::Expr) {
586-
if let ast::ExprKind::Await(_) | ast::ExprKind::Yield(_) = e.kind {
586+
if let ast::ExprKind::Await(_, _) | ast::ExprKind::Yield(_) = e.kind {
587587
self.0 = true;
588588
} else {
589589
visit::walk_expr(self, e);

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'a> State<'a> {
447447
self.ibox(0);
448448
self.print_block_with_attrs(blk, attrs);
449449
}
450-
ast::ExprKind::Await(expr) => {
450+
ast::ExprKind::Await(expr, _) => {
451451
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX);
452452
self.word(".await");
453453
}

compiler/rustc_builtin_macros/src/assert/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
288288
ExprKind::Assign(_, _, _)
289289
| ExprKind::AssignOp(_, _, _)
290290
| ExprKind::Async(_, _)
291-
| ExprKind::Await(_)
291+
| ExprKind::Await(_, _)
292292
| ExprKind::Block(_, _)
293293
| ExprKind::Break(_, _)
294294
| ExprKind::Closure(_)

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ impl<'a> Parser<'a> {
16461646
// Avoid knock-down errors as we don't know whether to interpret this as `foo().await?`
16471647
// or `foo()?.await` (the very reason we went with postfix syntax 😅).
16481648
ExprKind::Try(_) => ExprKind::Err,
1649-
_ => ExprKind::Await(expr),
1649+
_ => ExprKind::Await(expr, await_sp),
16501650
};
16511651
let expr = self.mk_expr(lo.to(sp), kind);
16521652
self.maybe_recover_from_bad_qpath(expr)

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ impl<'a> Parser<'a> {
859859
ExprKind::Field(_, _) => "a field access",
860860
ExprKind::MethodCall(_) => "a method call",
861861
ExprKind::Call(_, _) => "a function call",
862-
ExprKind::Await(_) => "`.await`",
862+
ExprKind::Await(_, _) => "`.await`",
863863
ExprKind::Err => return Ok(with_postfix),
864864
_ => unreachable!("parse_dot_or_call_expr_with_ shouldn't produce this"),
865865
}
@@ -3256,7 +3256,7 @@ impl<'a> Parser<'a> {
32563256

32573257
fn mk_await_expr(&mut self, self_arg: P<Expr>, lo: Span) -> P<Expr> {
32583258
let span = lo.to(self.prev_token.span);
3259-
let await_expr = self.mk_expr(span, ExprKind::Await(self_arg));
3259+
let await_expr = self.mk_expr(span, ExprKind::Await(self_arg, self.prev_token.span));
32603260
self.recover_from_await_method_call();
32613261
await_expr
32623262
}

0 commit comments

Comments
 (0)