about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-03-14 10:29:13 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-03-14 10:32:22 -0700
commit770b6e2fc2f8749466487e4c2ae031b8ceecae04 (patch)
tree55cbf8481fa11d4cd778a5152cc187e36018e357
parent2585803ec1c2476d0fbcf384b42f76677434bbb7 (diff)
downloadrust-770b6e2fc2f8749466487e4c2ae031b8ceecae04.tar.gz
rust-770b6e2fc2f8749466487e4c2ae031b8ceecae04.zip
rustc: Fix cfg(not(a, b)) to be not(a && b)
Previously, the cfg attribute `cfg(not(a, b))` was translated to `(!a && !b)`,
but this isn't very useful because that can already be expressed as
`cfg(not(a), not(b))`. This commit changes the translation to `!(a && b)` which
is more symmetrical of the rest of the `cfg` attribute.

Put another way, I would expect `cfg(clause)` to be the opposite of
`cfg(not(clause))`, but this is not currently the case with multiple element
clauses.
-rw-r--r--src/libsyntax/attr.rs4
-rw-r--r--src/test/run-pass/cfgs-on-items.rs10
2 files changed, 11 insertions, 3 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index ed56ef15a1c..7ff9a73f29d 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -317,9 +317,9 @@ pub fn test_cfg<AM: AttrMetaMethods, It: Iterator<AM>>
                                 debug!("not!");
                                 // inside #[cfg(not(...))], so these need to all
                                 // not match.
-                                not_cfgs.iter().all(|mi| {
+                                !not_cfgs.iter().all(|mi| {
                                     debug!("cfg(not({}[...]))", mi.name());
-                                    !contains(cfg, *mi)
+                                    contains(cfg, *mi)
                                 })
                             }
                             _ => contains(cfg, *cfg_mi)
diff --git a/src/test/run-pass/cfgs-on-items.rs b/src/test/run-pass/cfgs-on-items.rs
index 72d12b56c5c..f1c91dbaf35 100644
--- a/src/test/run-pass/cfgs-on-items.rs
+++ b/src/test/run-pass/cfgs-on-items.rs
@@ -16,7 +16,7 @@
 fn foo1() -> int { 1 }
 
 // !fooA AND !bar
-#[cfg(not(fooA, bar))]
+#[cfg(not(fooA), not(bar))]
 fn foo2() -> int { 2 }
 
 // fooC OR (fooB AND !bar)
@@ -24,8 +24,16 @@ fn foo2() -> int { 2 }
 #[cfg(fooB, not(bar))]
 fn foo2() -> int { 3 }
 
+// fooA AND bar
+#[cfg(fooA, bar)]
+fn foo3() -> int { 2 }
+
+// !(fooA AND bar)
+#[cfg(not(fooA, bar))]
+fn foo3() -> int { 3 }
 
 pub fn main() {
     assert_eq!(1, foo1());
     assert_eq!(3, foo2());
+    assert_eq!(3, foo3());
 }