Skip to content

Commit 770b6e2

Browse files
committed
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.
1 parent 2585803 commit 770b6e2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/libsyntax/attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ pub fn test_cfg<AM: AttrMetaMethods, It: Iterator<AM>>
317317
debug!("not!");
318318
// inside #[cfg(not(...))], so these need to all
319319
// not match.
320-
not_cfgs.iter().all(|mi| {
320+
!not_cfgs.iter().all(|mi| {
321321
debug!("cfg(not({}[...]))", mi.name());
322-
!contains(cfg, *mi)
322+
contains(cfg, *mi)
323323
})
324324
}
325325
_ => contains(cfg, *cfg_mi)

src/test/run-pass/cfgs-on-items.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,24 @@
1616
fn foo1() -> int { 1 }
1717

1818
// !fooA AND !bar
19-
#[cfg(not(fooA, bar))]
19+
#[cfg(not(fooA), not(bar))]
2020
fn foo2() -> int { 2 }
2121

2222
// fooC OR (fooB AND !bar)
2323
#[cfg(fooC)]
2424
#[cfg(fooB, not(bar))]
2525
fn foo2() -> int { 3 }
2626

27+
// fooA AND bar
28+
#[cfg(fooA, bar)]
29+
fn foo3() -> int { 2 }
30+
31+
// !(fooA AND bar)
32+
#[cfg(not(fooA, bar))]
33+
fn foo3() -> int { 3 }
2734

2835
pub fn main() {
2936
assert_eq!(1, foo1());
3037
assert_eq!(3, foo2());
38+
assert_eq!(3, foo3());
3139
}

0 commit comments

Comments
 (0)