[Pre-Pre-RFC] Block-tail Coerce Conversion


Sorry for the bad name (definitely need something better). And there’s absolutely devils in the details.


I’m thinking about adding an (extensible) coercing rule to address several wanted-features:

  1. Ok-wrapping
  2. never type fallback inference.


This coercion only happens when the block as a whole has type (somehow) specified; and the tail-expr type doesn’t correspond to it. Then this trait supplies additional fallbacks for such conversion.

// Ok-wrapping
impl<T, E> BlocktailCoerceFrom<T> for Result<T, E> {
     fn block_coerce_from(v: T) -> Self {

//workaround the fallback-to-() problem
impl BlocktailCoerceFrom<()> for ! {
     fn block_coerce_from(v: ()) -> Self {




And another future possibility is that this can expand to return, continue with value, etc. Then ? operator can change from Err(From::from(err)) to Err(err), leaving this trait to do the conversion job. This means that you can actually write impl Error or something on the function signature, if you have only one ?, the inference use the original error type as the inference result of impl Error



So why do we want to special-case blocks? How exactly would the use of this feature look like? As-is, this seems really vague and severely undermotivated.

1 Like


This is at least vague; because of inference and all the ways something can get a type it might even be impossible to distinguish.

Also, this is just “if it doesn’t typecheck then have a fallback”, which is both complicated to implement and weird to specify in nested cases.

1 Like


OK, i’m giving up this idea.