Why this fires¶
Postfix ? and ?> return the matching nil, Option.None, or Result.Err
from the enclosing function. That failure must be compatible with the
function's declared return type.
fn parse() -> Result<int, str> { Result.Err("invalid") }
fn invalid() -> int {
parse()? // error[TE833]: `Result.Err` cannot be returned as `int`
}Option.None is not interchangeable with Result.Err, and a nilable failure
is not silently boxed into either enum.
Fix it¶
Return a compatible fallible type, or handle the failure explicitly:
fn valid() -> Result<int, str> {
Result.Ok(parse()? * 2)
}Use match when translating between different failure representations.