I don’t think this is any different from if let, where the same example becomes
let x = if let Ok(x) = foo { x } else { panic!("there was an error") }
And again, I think all the examples using simple, two-variant enum matches are giving the wrong intuitions for this feature. To copy my MIR example from above (updated to what seems to be the current syntax proposal), when you’re looking for a particular complex pattern, there isn’t an “other side” that makes sense to talk about:
let Statement {
source_info,
kind: StatementKind::Assign(lvalue, Rvalue::BinaryOp(_, lhs, rhs)),
} = bin_statement
else { continue };
Yes, that’s ignoring non-assignments, assignments from unary operations, etc. But that’s the point.
I do like the unless form of things, since as I’ve said I think it’s helpful even more non-pattern-matching conditions, the same way that assert! is phrased at what should hold, not the condition on which to panic!. But I don’t seem to have been convincing enough about it, it would need the new epoch, and I have no problem with let ... else after glaebhoerl’s points.
No, because of cases like the one earlier in this post where the there isn’t any reasonable unwrap_or_else-like method that could be put on the type. I think the various forms of ? handle the things with unwrap* fine. (We could potentially even put the unwrap methods on Try, though that’s a conversation for another day.)