Skip to content

Commit

Permalink
Eagerly return ExprKind::Err on yield/await in wrong coroutine context
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 28, 2023
1 parent 5facb42 commit a76d2e1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
match self.coroutine_kind {
Some(hir::CoroutineKind::Async(_)) => {}
Some(hir::CoroutineKind::Coroutine) | Some(hir::CoroutineKind::Gen(_)) | None => {
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
return hir::ExprKind::Err(self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
await_kw_span,
item_span: self.current_item,
});
}));
}
}
let span = self.mark_span_with_reason(DesugaringKind::Await, await_kw_span, None);
Expand Down Expand Up @@ -1500,7 +1500,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
match self.coroutine_kind {
Some(hir::CoroutineKind::Gen(_)) => {}
Some(hir::CoroutineKind::Async(_)) => {
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
return hir::ExprKind::Err(self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span }));
}
Some(hir::CoroutineKind::Coroutine) | None => {
if !self.tcx.features().coroutines {
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/async-await/issue-70594.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
async fn fun() {
[1; ().await];
//~^ error: `await` is only allowed inside `async` functions and blocks
//~| error: `.await` is not allowed in a `const`
//~| error: `.await` is not allowed in a `const`
//~| error: `()` is not a future
}

fn main() {}
1 change: 0 additions & 1 deletion tests/ui/async-await/issues/issue-62009-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ fn main() {
//~^ ERROR `await` is only allowed inside `async` functions and blocks
(|_| 2333).await;
//~^ ERROR `await` is only allowed inside `async` functions and blocks
//~| ERROR is not a future
}

0 comments on commit a76d2e1

Please sign in to comment.