Why this fires¶
?. and ?? are nil-only operators. Option<T> and Result<T, E> are boxed
enum values, so neither wrapper is itself nil and ?? cannot unwrap it.
fn maybe() -> Option<int> { Option.None }
fn invalid() -> int {
maybe() ?? 7 // error[TE834]
}Fix it¶
Use postfix ? to propagate, pattern matching to handle both variants, or an
explicit wrapper operation such as unwrap_or when a default is intended:
fn valid() -> int {
Option.unwrap_or(maybe(), 7)
}Reserve ?? for a genuine T? value whose empty representation is runtime
nil.