-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(gen_blocks): cannot use the ? operator in a gen block that returns () #117486
Comments
CC: @oli-obk |
This is kind of expected given the desugaring for I guess we could make |
Making ? aware of generator blocks is a little awkward. Already ? performs an Into call (through the residual work), so adding more functionality may be adding a bit too many eggs in the basket. The problem with this issue is the semantics of a theoretical '?' in a generator is not necessarily the canonical extension. For example, what is expected if '?' is used in a for block? Should it just return? Or perhaps break/continue? In a non-gen situation, these question don't exist because the function ends at the decision to return. A solution could be to have a user-crate with a few macros that perform the necessary functionality. For example, it could have "or_yield", "or_yield_continue", and "or_yield_break". Note the "or_yield_break" would accept 1-2 arguments. Names would need to be bikeshed. |
So would the generator. My expected desugaring of the Err case is yield Err(e);
return; Forcing the generator to be If you want the generator to continue yieldig items after an |
The comment was just to express all PoVs. IMO, I'd also lean toward making ? short-circuit. For the most part, it seems the other cases aren't used, however there is a bias here since collect made the choice not to collect errors as well. But is it the case gen will never implement return values? For example, JavaScript generators allow return values separate from yielded values. |
It would be surprising if Returning values from generator other than () isn't blocked on this proposal either, since it should be forward-compatible by explicitly requiring return to be of unit type. |
As per gen_blocks RFC:
But currently upon using
?
an error occurs:cannot use the ? operator in a gen block that returns ()
To reproduce: https://godbolt.org/z/4fGT9EM8q
The text was updated successfully, but these errors were encountered: