Skip to content

Commit c69e60f

Browse files
authored
Rollup merge of rust-lang#93103 - estebank:await-span, r=nagisa
Tweak `expr.await` desugaring `Span` Fix rust-lang#93074
2 parents 224c6ac + 7356e28 commit c69e60f

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -625,18 +625,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
625625
/// }
626626
/// }
627627
/// ```
628-
fn lower_expr_await(&mut self, await_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
629-
let dot_await_span = expr.span.shrink_to_hi().to(await_span);
628+
fn lower_expr_await(&mut self, dot_await_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
629+
let full_span = expr.span.to(dot_await_span);
630630
match self.generator_kind {
631631
Some(hir::GeneratorKind::Async(_)) => {}
632632
Some(hir::GeneratorKind::Gen) | None => {
633633
let mut err = struct_span_err!(
634634
self.sess,
635-
await_span,
635+
dot_await_span,
636636
E0728,
637637
"`await` is only allowed inside `async` functions and blocks"
638638
);
639-
err.span_label(await_span, "only allowed inside `async` functions and blocks");
639+
err.span_label(dot_await_span, "only allowed inside `async` functions and blocks");
640640
if let Some(item_sp) = self.current_item {
641641
err.span_label(item_sp, "this is not `async`");
642642
}
@@ -646,7 +646,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
646646
let span = self.mark_span_with_reason(DesugaringKind::Await, dot_await_span, None);
647647
let gen_future_span = self.mark_span_with_reason(
648648
DesugaringKind::Await,
649-
await_span,
649+
full_span,
650650
self.allow_gen_future.clone(),
651651
);
652652
let expr = self.lower_expr_mut(expr);
@@ -699,9 +699,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
699699
let loop_hir_id = self.lower_node_id(loop_node_id);
700700
let ready_arm = {
701701
let x_ident = Ident::with_dummy_span(sym::result);
702-
let (x_pat, x_pat_hid) = self.pat_ident(span, x_ident);
703-
let x_expr = self.expr_ident(span, x_ident, x_pat_hid);
704-
let ready_field = self.single_pat_field(span, x_pat);
702+
let (x_pat, x_pat_hid) = self.pat_ident(gen_future_span, x_ident);
703+
let x_expr = self.expr_ident(gen_future_span, x_ident, x_pat_hid);
704+
let ready_field = self.single_pat_field(gen_future_span, x_pat);
705705
let ready_pat = self.pat_lang_item_variant(
706706
span,
707707
hir::LangItem::PollReady,
@@ -711,7 +711,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
711711
let break_x = self.with_loop_scope(loop_node_id, move |this| {
712712
let expr_break =
713713
hir::ExprKind::Break(this.lower_loop_destination(None), Some(x_expr));
714-
this.arena.alloc(this.expr(span, expr_break, ThinVec::new()))
714+
this.arena.alloc(this.expr(gen_future_span, expr_break, ThinVec::new()))
715715
});
716716
self.arm(ready_pat, break_x)
717717
};
@@ -783,7 +783,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
783783
// `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
784784
let into_future_span = self.mark_span_with_reason(
785785
DesugaringKind::Await,
786-
await_span,
786+
dot_await_span,
787787
self.allow_into_future.clone(),
788788
);
789789
let into_future_expr = self.expr_call_lang_item_fn(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// edition:2021
2+
// run-rustfix
3+
#![allow(dead_code)]
4+
5+
async fn a() {}
6+
7+
async fn foo() -> Result<(), i32> {
8+
Ok(a().await) //~ ERROR mismatched types
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// edition:2021
2+
// run-rustfix
3+
#![allow(dead_code)]
4+
5+
async fn a() {}
6+
7+
async fn foo() -> Result<(), i32> {
8+
a().await //~ ERROR mismatched types
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/proper-span-for-type-error.rs:8:5
3+
|
4+
LL | a().await
5+
| ^^^^^^^^^ expected enum `Result`, found `()`
6+
|
7+
= note: expected enum `Result<(), i32>`
8+
found unit type `()`
9+
help: try wrapping the expression in `Ok`
10+
|
11+
LL | Ok(a().await)
12+
| +++ +
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)