Thanks a lot, those are quite informative examples! Looking through these and reading once more through RFC #1303 led me to this thought:
We could simply consider let
to be an expression returning true
on successful assignment, false
otherwise. Then, using lazy evaluation of ||
:
(let hir::ExprBinary(op, ref l, ref r) = e.node) || return;
Ugly, perhaps, but simple and easy to explain. This definition would also seamlessly fit with if let
and while let
, and would directly allow for if precond && (let Ok(x) = blah) && postcond(x) { ... }
mentioned in RFC #1303.
Edit: obviously, when let
returns false, the whole statement is required to exit the current scope.