Lazy Boolean Operators
The boolean operators && and || are lazy, which means that they only evaluate their
right-hand-side if it is can influence the final value of the operation.
#![allow(unused)]
fn main() {
$lhs || $rhs
// desugars to:
if $lhs { true } else { $rhs }
}
#![allow(unused)]
fn main() {
$lhs && $rhs
// desugars to:
if $lhs { $rhs } else { false }
}
Inside an if expression, the && and ||
operators are also allowed to be mixed with if let (this is called “let-chains”).
We do not touch these at this stage, they will be dealt with in a later pass.
After this step, the only && and || operators left are involved in let-chains.
In particular, they’re all directly inside an if.
Backlinks