Question mark in `gen fn` doesn't work.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
I tried this code (playground link):
#![feature(gen_blocks)]
gen fn fallible() -> Option<u32> {
None?;
}
I expected to see this happen: The code compiles and fallible() produces an iterator that yields exactly one None. As far as I understand, this is prescribed by RFC 3513 and #117078 says the RFC has been implemented.
Instead, this happened: There's a compilation error:
error[E0277]: the `?` operator can only be used in a gen function that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> src/main.rs:4:9
|
3 | gen fn fallible() -> Option<u32> {
| __________________________________-
4 | | None?;
| | ^ cannot use the `?` operator in a gen function that returns `()`
5 | | }
| |_- this function should return `Result` or `Option` to accept `?`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Note that the function does "return" an Option. But as I understand the diagnostics here are expected to be unfinished so perhaps the exact wording of the error is not so important.
Meta
rustc --version --verbose:
rustc 1.98.0-nightly (f28ac764c 2026-06-23)
binary: rustc
commit-hash: f28ac764c36004fa6a6e098d15b4016a838c13c6
commit-date: 2026-06-23
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.7
or 1.98.0-nightly (2026-06-23 f28ac764c36004fa6a6e) on playground.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the linked Playground example and read RFC 3513's error-handling section alongside issue #117078. Trace the compiler handling for ? in a gen fn; done means the example compiles, fallible() yields exactly one None, and the relevant diagnostic or regression test reflects the supported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100