Allow `?` in unit-returning methods

To avoid forcing the API to use Option<()> as the return type when there is none, ? operator could be allowed to have cleaner early returns.

By the way, Option<Infallible> can be used too.

If we get Add `homogeneous_try_blocks` RFC by scottmcm · Pull Request #3721 · rust-lang/rfcs · GitHub then this can be done just by wrapping the body in try { … };.

2 Likes

this can be done just by wrapping the body in try { … }; .

Good to know, thanks. But I can't think of any reason not to allow it everywhere. The difference in codegen would be return as opposed to return v for Result and Option.