Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 31feafd

Browse files
committedNov 30, 2023
Make async gen fn an error
1 parent c58c4e8 commit 31feafd

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
@@ -536,6 +536,13 @@ pub(crate) struct GenFn {
536536
pub span: Span,
537537
}
538538

539+
#[derive(Diagnostic)]
540+
#[diag(parse_async_gen_fn)]
541+
pub(crate) struct AsyncGenFn {
542+
#[primary_span]
543+
pub span: Span,
544+
}
545+
539546
#[derive(Diagnostic)]
540547
#[diag(parse_comma_after_base_struct)]
541548
#[note]

‎compiler/rustc_parse/src/parser/item.rs

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

2390+
if let (Async::Yes { span: async_span, .. }, Gen::Yes { span: gen_span, .. }) =
2391+
(asyncness, genness)
2392+
{
2393+
self.sess.emit_err(errors::AsyncGenFn { span: async_span.to(gen_span) });
2394+
}
2395+
23902396
if !self.eat_keyword_case(kw::Fn, case) {
23912397
// It is possible for `expect_one_of` to recover given the contents of
23922398
// `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)
Please sign in to comment.