/// Removes useless operands of an logical expressions.
Removes useless operands of an logical expressions.
Removes useless operands of an logical expressions .
pub(super) fn drop_logical_operands(&mut self, e: &mut Expr) {
        if !self.options.conditionals {
            return;
        }
        let bin = match e {
            Expr::Bin(b) => b,
            _ => return,
        };
        if bin.op != op!("||") && bin.op != op!("&&") {
            return;
        }
        if bin.left.may_have_side_effects() {
            return;
        }
        let lt = bin.left.get_type();
        let rt = bin.right.get_type();
        let _lb = bin.left.as_pure_bool();
        let rb = bin.right.as_pure_bool();
        if let (Value::Known(Type::Bool), Value::Known(Type::Bool)) = (lt, rt) {
            // `!!b || true` => true
            if let Value::Known(true) = rb {
                self.changed = true;
                log::debug!("conditionals: `!!foo || true` => `true`");
                *e = make_bool(bin.span, true);
                return;
            }
        }
    }
pub ( super ) fn drop_logical_operands ( & mut self , e : & mut Expr ) { if ! self . options . conditionals { return ; } let bin = match e { Expr :: Bin ( b ) => b , _ => return , } ; if bin . op != op ! ( " " ) && bin . op != op ! ( " " ) { return ; } if bin . left . may_have_side_effects ( ) { return ; } let lt = bin . left . get_type ( ) ; let rt = bin . right . get_type ( ) ; let _lb = bin . left . as_pure_bool ( ) ; let rb = bin . right . as_pure_bool ( ) ; if let ( Value :: Known ( Type :: Bool ) , Value :: Known ( Type :: Bool ) ) = ( lt , rt ) { // `!!b || true` => true if let Value :: Known ( true ) = rb { self . changed = true ; log :: debug ! ( " " ) ; * e = make_bool ( bin . span , true ) ; return ; } } }
Removes useless operands of an logical expressions.
Removes useless operands of an logical expressions .
&mut self
e
&mut Expr