Skip to content

Commit a6833b0

Browse files
compiler-errorsKjetil Kjeka
authored andcommitted
Eagerly return ExprKind::Err on yield/await in wrong coroutine context
1 parent a01f706 commit a6833b0

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
759759
match self.coroutine_kind {
760760
Some(hir::CoroutineKind::Async(_)) => {}
761761
Some(hir::CoroutineKind::Coroutine) | Some(hir::CoroutineKind::Gen(_)) | None => {
762-
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
762+
return hir::ExprKind::Err(self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
763763
await_kw_span,
764764
item_span: self.current_item,
765-
});
765+
}));
766766
}
767767
}
768768
let span = self.mark_span_with_reason(DesugaringKind::Await, await_kw_span, None);
@@ -1481,7 +1481,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14811481
match self.coroutine_kind {
14821482
Some(hir::CoroutineKind::Gen(_)) => {}
14831483
Some(hir::CoroutineKind::Async(_)) => {
1484-
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
1484+
return hir::ExprKind::Err(self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span }));
14851485
}
14861486
Some(hir::CoroutineKind::Coroutine) | None => {
14871487
if !self.tcx.features().coroutines {

tests/ui/async-await/issue-70594.rs

Lines changed: 0 additions & 3 deletions
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() {}

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

Lines changed: 0 additions & 1 deletion
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)