Design `?` to work on named blocks

A small clarification

We currently have an experimental implementation of do catch blocks, tracking issue #31436. Enable with the following crate attribute: #![feature(catch_expr)]. Read the two RFCs #243 and #1859 for more background.

The main reason for this thread has been to discuss and evaluate an alternative and simplified design, all under the presupposition that there is a strong interest within the Rust core team to make an advancement in the area of in-function error capturing for the ? operator.

Simplified design?

In its essence, the whole proposal can be described as just one change to the ? operator: that it can take an optional label.

  • without the label: (EXPR)? the function is the exit point.
  • with the label: (EXPR)'a? the block named 'a is the exit point, implemented as break 'a error;.

Goals

Is there any merit to this alternative design? Is it a good idea to reuse the already accepted (and for loops, already stable) feature of break-with-value as a means of propagating errors to specific points within the fn?

6 Likes