Skip to content

Commit c905ce0

Browse files
committed
Use correct desugaring to support all Try types
1 parent 585afb9 commit c905ce0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

text/0000-gen-fn.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ Instead of returning the `Err` variant, `foo?` yields the `Err` variant and then
113113
This has the effect of it being an iterator with `Iterator::Item`'s type being `Result<T, E>`, and once a `Some(Err(e))`
114114
is produced via `?`, the iterator returns `None` next.
115115

116-
`gen` blocks do not need to have a trailing `Ok(x)` expression, because returning from an `gen` block will make the `Iterator` return `None` from now, which needs no value.
116+
`gen` blocks do not need to have a trailing `Ok(x)` expression, because returning from an `gen` block will make the `Iterator` return `None` from now, which needs no value. Instead all `yield` operations must be given a `Result`.
117+
118+
Similarly the `?` operator on `Option`s will `yield None` if it is `None`, and require passing an `Option` to all `yield` operations.
117119

118120
# Reference-level explanation
119121
[reference-level-explanation]: #reference-level-explanation
@@ -135,15 +137,18 @@ In the 2024 edition we reserve `gen` as a keyword. Previous editions need to use
135137
`foo?` in `gen` blocks desugars to
136138

137139
```rust
138-
match foo {
139-
Err(err) => {
140-
yield Err(err.into());
140+
match foo.branch() {
141+
ControlFlow::Break(err) => {
142+
yield R::from_residual(err);
141143
return;
142144
},
143-
Ok(val) => val,
145+
ControlFlow::Continue(val) => val,
144146
}
145147
```
146148

149+
which will stop iteration after the first error. This is the same behaviour that `collect::<Result<_, _>>()` performs
150+
on any iterator over `Result`s
151+
147152
# Drawbacks
148153
[drawbacks]: #drawbacks
149154

0 commit comments

Comments
 (0)