diff options
| author | bors <bors@rust-lang.org> | 2023-10-29 00:03:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-29 00:03:52 +0000 |
| commit | 2cad938a8173520f2bc39137b475f136be0aeeda (patch) | |
| tree | 668c1a104a33221cc0a6082cbe42e752d82690b3 /compiler/rustc_parse/src/parser/mod.rs | |
| parent | e5cfc55477eceed1317a02189fdf77a4a98f2124 (diff) | |
| parent | eb66d10cc3a6947cad6b4b169ed86b8c07f464d3 (diff) | |
| download | rust-2cad938a8173520f2bc39137b475f136be0aeeda.tar.gz rust-2cad938a8173520f2bc39137b475f136be0aeeda.zip | |
Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errors
Implement `gen` blocks in the 2024 edition
Coroutines tracking issue https://github.com/rust-lang/rust/issues/43122
`gen` block tracking issue https://github.com/rust-lang/rust/issues/117078
This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically.
An example usage of `gen` blocks is
```rust
fn foo() -> impl Iterator<Item = i32> {
gen {
yield 42;
for i in 5..18 {
if i.is_even() { continue }
yield i * 2;
}
}
}
```
The limitations (to be resolved) of the implementation are listed in the tracking issue
Diffstat (limited to 'compiler/rustc_parse/src/parser/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 41b19ecb63a..59b51954542 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -11,6 +11,7 @@ mod stmt; mod ty; use crate::lexer::UnmatchedDelim; +use ast::Gen; pub use attr_wrapper::AttrWrapper; pub use diagnostics::AttemptLocalParseRecovery; pub(crate) use expr::ForbiddenLetReason; @@ -1128,6 +1129,16 @@ impl<'a> Parser<'a> { } } + /// Parses genness: `gen` or nothing. + fn parse_genness(&mut self, case: Case) -> Gen { + if self.token.span.at_least_rust_2024() && self.eat_keyword_case(kw::Gen, case) { + let span = self.prev_token.uninterpolated_span(); + Gen::Yes { span, closure_id: DUMMY_NODE_ID, return_impl_trait_id: DUMMY_NODE_ID } + } else { + Gen::No + } + } + /// Parses unsafety: `unsafe` or nothing. fn parse_unsafety(&mut self, case: Case) -> Unsafe { if self.eat_keyword_case(kw::Unsafe, case) { |
