Skip to content

Commit a76d2e1

Browse files
Eagerly return ExprKind::Err on yield/await in wrong coroutine context
1 parent 5facb42 commit a76d2e1

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
778778
match self.coroutine_kind {
779779
Some(hir::CoroutineKind::Async(_)) => {}
780780
Some(hir::CoroutineKind::Coroutine) | Some(hir::CoroutineKind::Gen(_)) | None => {
781-
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
781+
return hir::ExprKind::Err(self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
782782
await_kw_span,
783783
item_span: self.current_item,
784-
});
784+
}));
785785
}
786786
}
787787
let span = self.mark_span_with_reason(DesugaringKind::Await, await_kw_span, None);
@@ -1500,7 +1500,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15001500
match self.coroutine_kind {
15011501
Some(hir::CoroutineKind::Gen(_)) => {}
15021502
Some(hir::CoroutineKind::Async(_)) => {
1503-
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
1503+
return hir::ExprKind::Err(self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span }));
15041504
}
15051505
Some(hir::CoroutineKind::Coroutine) | None => {
15061506
if !self.tcx.features().coroutines {

Diff for: tests/ui/async-await/issue-70594.rs

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
async fn fun() {
44
[1; ().await];
55
//~^ error: `await` is only allowed inside `async` functions and blocks
6-
//~| error: `.await` is not allowed in a `const`
7-
//~| error: `.await` is not allowed in a `const`
8-
//~| error: `()` is not a future
96
}
107

118
fn main() {}

Diff for: tests/ui/async-await/issues/issue-62009-1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ fn main() {
1111
//~^ ERROR `await` is only allowed inside `async` functions and blocks
1212
(|_| 2333).await;
1313
//~^ ERROR `await` is only allowed inside `async` functions and blocks
14-
//~| ERROR is not a future
1514
}

0 commit comments

Comments
 (0)