Sorry for the bad name (definitely need something better). And there’s absolutely devils in the details.
Motivation
I’m thinking about adding an (extensible) coercing rule to address several wanted-features:
Ok-wrapping
never type fallback inference.
Reference-level
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 {
Ok(v)
}
}
//workaround the fallback-to-() problem
impl BlocktailCoerceFrom<()> for ! {
fn block_coerce_from(v: ()) -> Self {
unreachable!()
}
}
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.