]> git.lizzy.rs Git - rust.git/commitdiff
treat macros as terminals to prevent `cfg!` from giving platform specific hints
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 24 Mar 2016 08:37:16 +0000 (09:37 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 29 Mar 2016 08:45:18 +0000 (10:45 +0200)
src/booleans.rs
tests/compile-fail/booleans.rs

index e9197cf85c69ffc9cb7226c6be34c5f00a7725d0..1b4d661da8474e6a0d22717c0311f4a5b0694323 100644 (file)
@@ -54,23 +54,26 @@ fn extract(&mut self, op: BinOp_, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Ve
     }
 
     fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
-        match e.node {
-            ExprUnary(UnNot, ref inner) => return Ok(Bool::Not(box self.run(inner)?)),
-            ExprBinary(binop, ref lhs, ref rhs) => {
-                match binop.node {
-                    BiOr => return Ok(Bool::Or(self.extract(BiOr, &[lhs, rhs], Vec::new())?)),
-                    BiAnd => return Ok(Bool::And(self.extract(BiAnd, &[lhs, rhs], Vec::new())?)),
-                    _ => {},
-                }
-            },
-            ExprLit(ref lit) => {
-                match lit.node {
-                    LitKind::Bool(true) => return Ok(Bool::True),
-                    LitKind::Bool(false) => return Ok(Bool::False),
-                    _ => {},
-                }
-            },
-            _ => {},
+        // prevent folding of `cfg!` macros and the like
+        if !in_macro(self.cx, e.span) {
+            match e.node {
+                ExprUnary(UnNot, ref inner) => return Ok(Bool::Not(box self.run(inner)?)),
+                ExprBinary(binop, ref lhs, ref rhs) => {
+                    match binop.node {
+                        BiOr => return Ok(Bool::Or(self.extract(BiOr, &[lhs, rhs], Vec::new())?)),
+                        BiAnd => return Ok(Bool::And(self.extract(BiAnd, &[lhs, rhs], Vec::new())?)),
+                        _ => {},
+                    }
+                },
+                ExprLit(ref lit) => {
+                    match lit.node {
+                        LitKind::Bool(true) => return Ok(Bool::True),
+                        LitKind::Bool(false) => return Ok(Bool::False),
+                        _ => {},
+                    }
+                },
+                _ => {},
+            }
         }
         if let Some((n, _)) = self.terminals
                                   .iter()
index 8130e5357733a85b14435010683bc10c2aded0d3..f9bf1a15f18e3856b92195dc9bf33f6ccc24b428 100644 (file)
@@ -29,4 +29,7 @@ fn main() {
     let _ = false || a; //~ ERROR this boolean expression can be simplified
     //|~ HELP for further information visit
     //|~ SUGGESTION let _ = a;
+
+    // don't lint on cfgs
+    let _ = cfg!(you_shall_not_not_pass) && a;
 }