Skip to content

Commit cb4a5eb

Browse files
committed
Make async gen fn an error
1 parent e27ebef commit cb4a5eb

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

compiler/rustc_parse/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ parse_async_block_in_2015 = `async` blocks are only allowed in Rust 2018 or late
2323
parse_async_fn_in_2015 = `async fn` is not permitted in Rust 2015
2424
.label = to use `async fn`, switch to Rust 2018 or later
2525
26+
parse_async_gen_fn = `async gen` functions are not supported
27+
2628
parse_async_move_block_in_2015 = `async move` blocks are only allowed in Rust 2018 or later
2729
2830
parse_async_move_order_incorrect = the order of `move` and `async` is incorrect

compiler/rustc_parse/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,13 @@ pub(crate) struct GenFn {
562562
pub span: Span,
563563
}
564564

565+
#[derive(Diagnostic)]
566+
#[diag(parse_async_gen_fn)]
567+
pub(crate) struct AsyncGenFn {
568+
#[primary_span]
569+
pub span: Span,
570+
}
571+
565572
#[derive(Diagnostic)]
566573
#[diag(parse_comma_after_base_struct)]
567574
#[note]

compiler/rustc_parse/src/parser/item.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,12 @@ impl<'a> Parser<'a> {
24192419
self.sess.gated_spans.gate(sym::gen_blocks, span);
24202420
}
24212421

2422+
if let (Async::Yes { span: async_span, .. }, Gen::Yes { span: gen_span, .. }) =
2423+
(asyncness, genness)
2424+
{
2425+
self.sess.emit_err(errors::AsyncGenFn { span: async_span.to(gen_span) });
2426+
}
2427+
24222428
if !self.eat_keyword_case(kw::Fn, case) {
24232429
// It is possible for `expect_one_of` to recover given the contents of
24242430
// `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't

tests/ui/coroutine/async_gen_fn.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// edition: 2024
2+
// compile-flags: -Zunstable-options
3+
#![feature(gen_blocks)]
4+
5+
// async generators are not yet supported, so this test makes sure they make some kind of reasonable
6+
// error.
7+
8+
async gen fn foo() {}
9+
//~^ `async gen` functions are not supported
10+
11+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: `async gen` functions are not supported
2+
--> $DIR/async_gen_fn.rs:8:1
3+
|
4+
LL | async gen fn foo() {}
5+
| ^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)