Skip to content

Commit f29b36d

Browse files
committed
Make async gen fn an error
1 parent 7c43784 commit f29b36d

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

compiler/rustc_parse/messages.ftl

+2
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

+7
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

+6
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,12 @@ impl<'a> Parser<'a> {
24142414
self.sess.gated_spans.gate(sym::gen_blocks, span);
24152415
}
24162416

2417+
if let (Async::Yes { span: async_span, .. }, Gen::Yes { span: gen_span, .. }) =
2418+
(asyncness, genness)
2419+
{
2420+
self.sess.emit_err(errors::AsyncGenFn { span: async_span.to(gen_span) });
2421+
}
2422+
24172423
if !self.eat_keyword_case(kw::Fn, case) {
24182424
// It is possible for `expect_one_of` to recover given the contents of
24192425
// `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't

tests/ui/coroutine/async_gen_fn.rs

+11
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() {}
+8
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)