Skip to content

Commit aa3b126

Browse files
committed
Continue cfg syntax transition
All deprecation warnings have been converted to errors. This includes the warning for multiple cfgs on one item. We'll leave that as an error for some period of time to ensure that all uses are updated before the behavior changes from "or" to "and".
1 parent cd1fa91 commit aa3b126

25 files changed

+98
-190
lines changed

src/compiletest/runtest.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -952,10 +952,10 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
952952
to_lower(line).as_slice().starts_with(to_lower(prefix).as_slice())
953953
}
954954

955-
#[cfg(target_os = "linux")]
956-
#[cfg(target_os = "macos")]
957-
#[cfg(target_os = "freebsd")]
958-
#[cfg(target_os = "dragonfly")]
955+
#[cfg(any(target_os = "linux",
956+
target_os = "macos",
957+
target_os = "freebsd",
958+
target_os = "dragonfly"))]
959959
fn prefix_matches( line : &str, prefix : &str ) -> bool {
960960
line.starts_with( prefix )
961961
}
@@ -1356,10 +1356,10 @@ fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String
13561356
}
13571357

13581358
// Linux and mac don't require adjusting the library search path
1359-
#[cfg(target_os = "linux")]
1360-
#[cfg(target_os = "macos")]
1361-
#[cfg(target_os = "freebsd")]
1362-
#[cfg(target_os = "dragonfly")]
1359+
#[cfg(any(target_os = "linux",
1360+
target_os = "macos",
1361+
target_os = "freebsd",
1362+
target_os = "dragonfly"))]
13631363
fn make_cmdline(_libpath: &str, prog: &str, args: &[String]) -> String {
13641364
format!("{} {}", prog, args.connect(" "))
13651365
}

src/doc/guide-ffi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ conventions. Rust provides a way to tell the compiler which convention to use:
475475
~~~~
476476
extern crate libc;
477477

478-
#[cfg(target_os = "win32", target_arch = "x86")]
478+
#[cfg(all(target_os = "win32", target_arch = "x86"))]
479479
#[link(name = "kernel32")]
480480
#[allow(non_snake_case)]
481481
extern "stdcall" {

src/doc/guide-unsafe.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,15 @@ literal string (i.e `""`)
313313
```
314314
#![feature(asm)]
315315
316-
#[cfg(target_arch = "x86")]
317-
#[cfg(target_arch = "x86_64")]
316+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
318317
fn foo() {
319318
unsafe {
320319
asm!("NOP");
321320
}
322321
}
323322
324323
// other platforms
325-
#[cfg(not(target_arch = "x86"),
326-
not(target_arch = "x86_64"))]
324+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
327325
fn foo() { /* ... */ }
328326
329327
fn main() {
@@ -340,7 +338,7 @@ but you must add the right number of `:` if you skip them:
340338

341339
```
342340
# #![feature(asm)]
343-
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
341+
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
344342
# fn main() { unsafe {
345343
asm!("xor %eax, %eax"
346344
:
@@ -354,7 +352,7 @@ Whitespace also doesn't matter:
354352

355353
```
356354
# #![feature(asm)]
357-
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
355+
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
358356
# fn main() { unsafe {
359357
asm!("xor %eax, %eax" ::: "eax");
360358
# } }
@@ -368,7 +366,7 @@ expressions must be mutable lvalues:
368366

369367
```
370368
# #![feature(asm)]
371-
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
369+
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
372370
fn add(a: int, b: int) -> int {
373371
let mut c = 0;
374372
unsafe {
@@ -379,7 +377,7 @@ fn add(a: int, b: int) -> int {
379377
}
380378
c
381379
}
382-
# #[cfg(not(target_arch = "x86"), not(target_arch = "x86_64"))]
380+
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
383381
# fn add(a: int, b: int) -> int { a + b }
384382
385383
fn main() {
@@ -396,7 +394,7 @@ stay valid.
396394

397395
```
398396
# #![feature(asm)]
399-
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
397+
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
400398
# fn main() { unsafe {
401399
// Put the value 0x200 in eax
402400
asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax");

src/doc/reference.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -2066,26 +2066,28 @@ fn macos_only() {
20662066
}
20672067
20682068
// This function is only included when either foo or bar is defined
2069-
#[cfg(foo)]
2070-
#[cfg(bar)]
2069+
#[cfg(any(foo, bar))]
20712070
fn needs_foo_or_bar() {
20722071
// ...
20732072
}
20742073
20752074
// This function is only included when compiling for a unixish OS with a 32-bit
20762075
// architecture
2077-
#[cfg(unix, target_word_size = "32")]
2076+
#[cfg(all(unix, target_word_size = "32"))]
20782077
fn on_32bit_unix() {
20792078
// ...
20802079
}
2080+
2081+
// This function is only included when foo is not defined
2082+
#[cfg(not(foo))]
2083+
fn needs_not_foo() {
2084+
// ...
2085+
}
20812086
```
20822087

20832088
This illustrates some conditional compilation can be achieved using the
2084-
`#[cfg(...)]` attribute. Note that `#[cfg(foo, bar)]` is a condition that needs
2085-
both `foo` and `bar` to be defined while `#[cfg(foo)] #[cfg(bar)]` only needs
2086-
one of `foo` and `bar` to be defined (this resembles in the disjunctive normal
2087-
form). Additionally, one can reverse a condition by enclosing it in a
2088-
`not(...)`, like e. g. `#[cfg(not(target_os = "win32"))]`.
2089+
`#[cfg(...)]` attribute. `any`, `all` and `not` can be used to assemble
2090+
arbitrarily complex configurations through nesting.
20892091

20902092
The following configurations must be defined by the implementation:
20912093

src/libcoretest/mem.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ fn size_of_basic() {
1919
}
2020

2121
#[test]
22-
#[cfg(target_arch = "x86")]
23-
#[cfg(target_arch = "arm")]
24-
#[cfg(target_arch = "mips")]
25-
#[cfg(target_arch = "mipsel")]
22+
#[cfg(any(target_arch = "x86",
23+
target_arch = "arm",
24+
target_arch = "mips",
25+
target_arch = "mipsel"))]
2626
fn size_of_32() {
2727
assert_eq!(size_of::<uint>(), 4u);
2828
assert_eq!(size_of::<*const uint>(), 4u);
@@ -51,10 +51,10 @@ fn align_of_basic() {
5151
}
5252

5353
#[test]
54-
#[cfg(target_arch = "x86")]
55-
#[cfg(target_arch = "arm")]
56-
#[cfg(target_arch = "mips")]
57-
#[cfg(target_arch = "mipsel")]
54+
#[cfg(any(target_arch = "x86",
55+
target_arch = "arm",
56+
target_arch = "mips",
57+
target_arch = "mipsel"))]
5858
fn align_of_32() {
5959
assert_eq!(align_of::<uint>(), 4u);
6060
assert_eq!(align_of::<*const uint>(), 4u);

src/librustc_back/rpath.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ mod test {
200200
}
201201

202202
#[test]
203-
#[cfg(target_os = "linux")]
204-
#[cfg(target_os = "android")]
203+
#[cfg(any(target_os = "linux", target_os = "android"))]
205204
fn test_rpath_relative() {
206205
let config = &mut RPathConfig {
207206
os: abi::OsLinux,

src/libsyntax/attr.rs

+3-54
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,10 @@ pub fn cfg_matches(diagnostic: &SpanHandler, cfgs: &[P<MetaItem>], cfg: &ast::Me
316316
mis.iter().all(|mi| cfg_matches(diagnostic, cfgs, &**mi)),
317317
ast::MetaList(ref pred, ref mis) if pred.get() == "not" => {
318318
if mis.len() != 1 {
319-
diagnostic.span_warn(cfg.span, "the use of multiple cfgs in the same `not` \
320-
statement is deprecated. Change `not(a, b)` to \
321-
`not(all(a, b))`.");
319+
diagnostic.span_err(cfg.span, "expected 1 cfg-pattern");
320+
return false;
322321
}
323-
!mis.iter().all(|mi| cfg_matches(diagnostic, cfgs, &**mi))
322+
!cfg_matches(diagnostic, cfgs, &*mis[0])
324323
}
325324
ast::MetaList(ref pred, _) => {
326325
diagnostic.span_err(cfg.span, format!("invalid predicate `{}`", pred).as_slice());
@@ -330,56 +329,6 @@ pub fn cfg_matches(diagnostic: &SpanHandler, cfgs: &[P<MetaItem>], cfg: &ast::Me
330329
}
331330
}
332331

333-
/// Tests if any `cfg(...)` meta items in `metas` match `cfg`. e.g.
334-
///
335-
/// test_cfg(`[foo="a", bar]`, `[cfg(foo), cfg(bar)]`) == true
336-
/// test_cfg(`[foo="a", bar]`, `[cfg(not(bar))]`) == false
337-
/// test_cfg(`[foo="a", bar]`, `[cfg(bar, foo="a")]`) == true
338-
/// test_cfg(`[foo="a", bar]`, `[cfg(bar, foo="b")]`) == false
339-
pub fn test_cfg<'a, AM: AttrMetaMethods, It: Iterator<&'a AM>>
340-
(cfg: &[P<MetaItem>], mut metas: It) -> bool {
341-
// having no #[cfg(...)] attributes counts as matching.
342-
let mut no_cfgs = true;
343-
344-
// this would be much nicer as a chain of iterator adaptors, but
345-
// this doesn't work.
346-
let some_cfg_matches = metas.fold(false, |matches, mi| {
347-
debug!("testing name: {}", mi.name());
348-
let this_matches = if mi.check_name("cfg") { // it is a #[cfg()] attribute
349-
debug!("is cfg");
350-
no_cfgs = false;
351-
// only #[cfg(...)] ones are understood.
352-
match mi.meta_item_list() {
353-
Some(cfg_meta) => {
354-
debug!("is cfg(...)");
355-
cfg_meta.iter().all(|cfg_mi| {
356-
debug!("cfg({}[...])", cfg_mi.name());
357-
match cfg_mi.node {
358-
ast::MetaList(ref s, ref not_cfgs)
359-
if s.equiv(&("not")) => {
360-
debug!("not!");
361-
// inside #[cfg(not(...))], so these need to all
362-
// not match.
363-
!not_cfgs.iter().all(|mi| {
364-
debug!("cfg(not({}[...]))", mi.name());
365-
contains(cfg, &**mi)
366-
})
367-
}
368-
_ => contains(cfg, &**cfg_mi)
369-
}
370-
})
371-
}
372-
None => false
373-
}
374-
} else {
375-
false
376-
};
377-
matches || this_matches
378-
});
379-
debug!("test_cfg (no_cfgs={}, some_cfg_matches={})", no_cfgs, some_cfg_matches);
380-
no_cfgs || some_cfg_matches
381-
}
382-
383332
/// Represents the #[deprecated="foo"] and friends attributes.
384333
#[deriving(Encodable,Decodable,Clone,Show)]
385334
pub struct Stability {

src/libsyntax/config.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,20 @@ fn in_cfg(diagnostic: &SpanHandler, cfg: &[P<ast::MetaItem>], attrs: &[ast::Attr
261261
};
262262

263263
if mis.len() != 1 {
264-
diagnostic.span_warn(attr.span, "The use of multiple cfgs in the top level of \
265-
`#[cfg(..)]` is deprecated. Change `#[cfg(a, b)]` to \
266-
`#[cfg(all(a, b))]`.");
264+
diagnostic.span_err(attr.span, "expected 1 cfg-pattern");
265+
return false;
267266
}
268267

269268
if seen_cfg {
270-
diagnostic.span_warn(attr.span, "The semantics of multiple `#[cfg(..)]` attributes on \
271-
same item are changing from the union of the cfgs to \
272-
the intersection of the cfgs. Change `#[cfg(a)] \
273-
#[cfg(b)]` to `#[cfg(any(a, b))]`.");
269+
diagnostic.span_err(attr.span, "The semantics of multiple `#[cfg(..)]` attributes on \
270+
same item are changing from the union of the cfgs to \
271+
the intersection of the cfgs. Change `#[cfg(a)] \
272+
#[cfg(b)]` to `#[cfg(any(a, b))]`.");
273+
return false;
274274
}
275275

276276
seen_cfg = true;
277-
in_cfg |= mis.iter().all(|mi| attr::cfg_matches(diagnostic, cfg, &**mi));
277+
in_cfg |= attr::cfg_matches(diagnostic, cfg, &*mis[0]);
278278
}
279279
in_cfg | !seen_cfg
280280
}

src/libsyntax/ext/cfg.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/**
12-
The compiler code necessary to support the cfg! extension, which
13-
expands to a literal `true` or `false` based on whether the given cfgs
14-
match the current compilation environment.
15-
*/
11+
/// The compiler code necessary to support the cfg! extension, which expands to
12+
/// a literal `true` or `false` based on whether the given cfg matches the
13+
/// current compilation environment.
1614
1715
use ast;
1816
use codemap::Span;
@@ -24,28 +22,18 @@ use attr::*;
2422
use parse::attr::ParserAttr;
2523
use parse::token;
2624

27-
2825
pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
2926
sp: Span,
3027
tts: &[ast::TokenTree])
3128
-> Box<base::MacResult+'static> {
3229
let mut p = cx.new_parser_from_tts(tts);
33-
let mut cfgs = Vec::new();
34-
// parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)`
35-
while p.token != token::EOF {
36-
cfgs.push(p.parse_meta_item());
37-
if p.eat(&token::EOF) { break } // trailing comma is optional,.
38-
p.expect(&token::COMMA);
39-
}
30+
let cfg = p.parse_meta_item();
4031

41-
if cfgs.len() != 1 {
42-
cx.span_warn(sp, "The use of multiple cfgs at the top level of `cfg!` \
43-
is deprecated. Change `cfg!(a, b)` to \
44-
`cfg!(all(a, b))`.");
32+
if !p.eat(&token::EOF) {
33+
cx.span_err(sp, "expected 1 cfg-pattern");
34+
return DummyResult::expr(sp);
4535
}
4636

47-
let matches_cfg = cfgs.iter().all(|cfg| attr::cfg_matches(&cx.parse_sess.span_diagnostic,
48-
cx.cfg.as_slice(), &**cfg));
49-
37+
let matches_cfg = attr::cfg_matches(&cx.parse_sess.span_diagnostic, cx.cfg.as_slice(), &*cfg);
5038
MacExpr::new(cx.expr_bool(sp, matches_cfg))
5139
}

src/libsyntax/test.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
126126
span: i.span,
127127
path: self.cx.path.clone(),
128128
bench: is_bench_fn(&self.cx, &*i),
129-
ignore: is_ignored(&self.cx, &*i),
129+
ignore: is_ignored(&*i),
130130
should_fail: should_fail(&*i)
131131
};
132132
self.cx.testfns.push(test);
@@ -343,22 +343,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
343343
return has_bench_attr && has_test_signature(i);
344344
}
345345

346-
fn is_ignored(cx: &TestCtxt, i: &ast::Item) -> bool {
347-
i.attrs.iter().any(|attr| {
348-
// check ignore(cfg(foo, bar))
349-
attr.check_name("ignore") && match attr.meta_item_list() {
350-
Some(ref cfgs) => {
351-
if cfgs.iter().any(|cfg| cfg.check_name("cfg")) {
352-
cx.span_diagnostic.span_warn(attr.span,
353-
"The use of cfg filters in #[ignore] is \
354-
deprecated. Use #[cfg_attr(<cfg pattern>, \
355-
ignore)] instead.");
356-
}
357-
attr::test_cfg(cx.config.as_slice(), cfgs.iter())
358-
}
359-
None => true
360-
}
361-
})
346+
fn is_ignored(i: &ast::Item) -> bool {
347+
i.attrs.iter().any(|attr| attr.check_name("ignore"))
362348
}
363349

364350
fn should_fail(i: &ast::Item) -> bool {

src/test/auxiliary/extern_calling_convention.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ pub extern "win64" fn foo(a: int, b: int, c: int, d: int) {
2626
}
2727

2828
#[inline(never)]
29-
#[cfg(target_arch = "x86")]
30-
#[cfg(target_arch = "arm")]
29+
#[cfg(any(target_arch = "x86", target_arch = "arm"))]
3130
pub extern fn foo(a: int, b: int, c: int, d: int) {
3231
assert!(a == 1);
3332
assert!(b == 2);

src/test/run-make/test-harness/test-ignore-cfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
// except according to those terms.
1010

1111
#[test]
12-
#[ignore(cfg(ignorecfg))]
12+
#[cfg_attr(ignorecfg, ignore)]
1313
fn shouldignore() {
1414
}
1515

1616
#[test]
17-
#[ignore(cfg(noignorecfg))]
17+
#[cfg_attr(noignorecfg, ignore)]
1818
fn shouldnotignore() {
1919
}

0 commit comments

Comments
 (0)