mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
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".
This commit is contained in:
parent
cd1fa91d2b
commit
aa3b1261b1
@ -952,10 +952,10 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
|
|||||||
to_lower(line).as_slice().starts_with(to_lower(prefix).as_slice())
|
to_lower(line).as_slice().starts_with(to_lower(prefix).as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux",
|
||||||
#[cfg(target_os = "macos")]
|
target_os = "macos",
|
||||||
#[cfg(target_os = "freebsd")]
|
target_os = "freebsd",
|
||||||
#[cfg(target_os = "dragonfly")]
|
target_os = "dragonfly"))]
|
||||||
fn prefix_matches( line : &str, prefix : &str ) -> bool {
|
fn prefix_matches( line : &str, prefix : &str ) -> bool {
|
||||||
line.starts_with( prefix )
|
line.starts_with( prefix )
|
||||||
}
|
}
|
||||||
@ -1356,10 +1356,10 @@ fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Linux and mac don't require adjusting the library search path
|
// Linux and mac don't require adjusting the library search path
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux",
|
||||||
#[cfg(target_os = "macos")]
|
target_os = "macos",
|
||||||
#[cfg(target_os = "freebsd")]
|
target_os = "freebsd",
|
||||||
#[cfg(target_os = "dragonfly")]
|
target_os = "dragonfly"))]
|
||||||
fn make_cmdline(_libpath: &str, prog: &str, args: &[String]) -> String {
|
fn make_cmdline(_libpath: &str, prog: &str, args: &[String]) -> String {
|
||||||
format!("{} {}", prog, args.connect(" "))
|
format!("{} {}", prog, args.connect(" "))
|
||||||
}
|
}
|
||||||
|
@ -475,7 +475,7 @@ conventions. Rust provides a way to tell the compiler which convention to use:
|
|||||||
~~~~
|
~~~~
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
#[cfg(target_os = "win32", target_arch = "x86")]
|
#[cfg(all(target_os = "win32", target_arch = "x86"))]
|
||||||
#[link(name = "kernel32")]
|
#[link(name = "kernel32")]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
extern "stdcall" {
|
extern "stdcall" {
|
||||||
|
@ -313,8 +313,7 @@ literal string (i.e `""`)
|
|||||||
```
|
```
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
fn foo() {
|
fn foo() {
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!("NOP");
|
asm!("NOP");
|
||||||
@ -322,8 +321,7 @@ fn foo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// other platforms
|
// other platforms
|
||||||
#[cfg(not(target_arch = "x86"),
|
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||||
not(target_arch = "x86_64"))]
|
|
||||||
fn foo() { /* ... */ }
|
fn foo() { /* ... */ }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -340,7 +338,7 @@ but you must add the right number of `:` if you skip them:
|
|||||||
|
|
||||||
```
|
```
|
||||||
# #![feature(asm)]
|
# #![feature(asm)]
|
||||||
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
|
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
# fn main() { unsafe {
|
# fn main() { unsafe {
|
||||||
asm!("xor %eax, %eax"
|
asm!("xor %eax, %eax"
|
||||||
:
|
:
|
||||||
@ -354,7 +352,7 @@ Whitespace also doesn't matter:
|
|||||||
|
|
||||||
```
|
```
|
||||||
# #![feature(asm)]
|
# #![feature(asm)]
|
||||||
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
|
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
# fn main() { unsafe {
|
# fn main() { unsafe {
|
||||||
asm!("xor %eax, %eax" ::: "eax");
|
asm!("xor %eax, %eax" ::: "eax");
|
||||||
# } }
|
# } }
|
||||||
@ -368,7 +366,7 @@ expressions must be mutable lvalues:
|
|||||||
|
|
||||||
```
|
```
|
||||||
# #![feature(asm)]
|
# #![feature(asm)]
|
||||||
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
|
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
fn add(a: int, b: int) -> int {
|
fn add(a: int, b: int) -> int {
|
||||||
let mut c = 0;
|
let mut c = 0;
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -379,7 +377,7 @@ fn add(a: int, b: int) -> int {
|
|||||||
}
|
}
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
# #[cfg(not(target_arch = "x86"), not(target_arch = "x86_64"))]
|
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||||
# fn add(a: int, b: int) -> int { a + b }
|
# fn add(a: int, b: int) -> int { a + b }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -396,7 +394,7 @@ stay valid.
|
|||||||
|
|
||||||
```
|
```
|
||||||
# #![feature(asm)]
|
# #![feature(asm)]
|
||||||
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
|
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
# fn main() { unsafe {
|
# fn main() { unsafe {
|
||||||
// Put the value 0x200 in eax
|
// Put the value 0x200 in eax
|
||||||
asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax");
|
asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax");
|
||||||
|
@ -2066,26 +2066,28 @@ fn macos_only() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This function is only included when either foo or bar is defined
|
// This function is only included when either foo or bar is defined
|
||||||
#[cfg(foo)]
|
#[cfg(any(foo, bar))]
|
||||||
#[cfg(bar)]
|
|
||||||
fn needs_foo_or_bar() {
|
fn needs_foo_or_bar() {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is only included when compiling for a unixish OS with a 32-bit
|
// This function is only included when compiling for a unixish OS with a 32-bit
|
||||||
// architecture
|
// architecture
|
||||||
#[cfg(unix, target_word_size = "32")]
|
#[cfg(all(unix, target_word_size = "32"))]
|
||||||
fn on_32bit_unix() {
|
fn on_32bit_unix() {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is only included when foo is not defined
|
||||||
|
#[cfg(not(foo))]
|
||||||
|
fn needs_not_foo() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This illustrates some conditional compilation can be achieved using the
|
This illustrates some conditional compilation can be achieved using the
|
||||||
`#[cfg(...)]` attribute. Note that `#[cfg(foo, bar)]` is a condition that needs
|
`#[cfg(...)]` attribute. `any`, `all` and `not` can be used to assemble
|
||||||
both `foo` and `bar` to be defined while `#[cfg(foo)] #[cfg(bar)]` only needs
|
arbitrarily complex configurations through nesting.
|
||||||
one of `foo` and `bar` to be defined (this resembles in the disjunctive normal
|
|
||||||
form). Additionally, one can reverse a condition by enclosing it in a
|
|
||||||
`not(...)`, like e. g. `#[cfg(not(target_os = "win32"))]`.
|
|
||||||
|
|
||||||
The following configurations must be defined by the implementation:
|
The following configurations must be defined by the implementation:
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@ fn size_of_basic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86",
|
||||||
#[cfg(target_arch = "arm")]
|
target_arch = "arm",
|
||||||
#[cfg(target_arch = "mips")]
|
target_arch = "mips",
|
||||||
#[cfg(target_arch = "mipsel")]
|
target_arch = "mipsel"))]
|
||||||
fn size_of_32() {
|
fn size_of_32() {
|
||||||
assert_eq!(size_of::<uint>(), 4u);
|
assert_eq!(size_of::<uint>(), 4u);
|
||||||
assert_eq!(size_of::<*const uint>(), 4u);
|
assert_eq!(size_of::<*const uint>(), 4u);
|
||||||
@ -51,10 +51,10 @@ fn align_of_basic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86",
|
||||||
#[cfg(target_arch = "arm")]
|
target_arch = "arm",
|
||||||
#[cfg(target_arch = "mips")]
|
target_arch = "mips",
|
||||||
#[cfg(target_arch = "mipsel")]
|
target_arch = "mipsel"))]
|
||||||
fn align_of_32() {
|
fn align_of_32() {
|
||||||
assert_eq!(align_of::<uint>(), 4u);
|
assert_eq!(align_of::<uint>(), 4u);
|
||||||
assert_eq!(align_of::<*const uint>(), 4u);
|
assert_eq!(align_of::<*const uint>(), 4u);
|
||||||
|
@ -200,8 +200,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
fn test_rpath_relative() {
|
fn test_rpath_relative() {
|
||||||
let config = &mut RPathConfig {
|
let config = &mut RPathConfig {
|
||||||
os: abi::OsLinux,
|
os: abi::OsLinux,
|
||||||
|
@ -316,11 +316,10 @@ pub fn cfg_matches(diagnostic: &SpanHandler, cfgs: &[P<MetaItem>], cfg: &ast::Me
|
|||||||
mis.iter().all(|mi| cfg_matches(diagnostic, cfgs, &**mi)),
|
mis.iter().all(|mi| cfg_matches(diagnostic, cfgs, &**mi)),
|
||||||
ast::MetaList(ref pred, ref mis) if pred.get() == "not" => {
|
ast::MetaList(ref pred, ref mis) if pred.get() == "not" => {
|
||||||
if mis.len() != 1 {
|
if mis.len() != 1 {
|
||||||
diagnostic.span_warn(cfg.span, "the use of multiple cfgs in the same `not` \
|
diagnostic.span_err(cfg.span, "expected 1 cfg-pattern");
|
||||||
statement is deprecated. Change `not(a, b)` to \
|
return false;
|
||||||
`not(all(a, b))`.");
|
|
||||||
}
|
}
|
||||||
!mis.iter().all(|mi| cfg_matches(diagnostic, cfgs, &**mi))
|
!cfg_matches(diagnostic, cfgs, &*mis[0])
|
||||||
}
|
}
|
||||||
ast::MetaList(ref pred, _) => {
|
ast::MetaList(ref pred, _) => {
|
||||||
diagnostic.span_err(cfg.span, format!("invalid predicate `{}`", pred).as_slice());
|
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
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests if any `cfg(...)` meta items in `metas` match `cfg`. e.g.
|
|
||||||
///
|
|
||||||
/// test_cfg(`[foo="a", bar]`, `[cfg(foo), cfg(bar)]`) == true
|
|
||||||
/// test_cfg(`[foo="a", bar]`, `[cfg(not(bar))]`) == false
|
|
||||||
/// test_cfg(`[foo="a", bar]`, `[cfg(bar, foo="a")]`) == true
|
|
||||||
/// test_cfg(`[foo="a", bar]`, `[cfg(bar, foo="b")]`) == false
|
|
||||||
pub fn test_cfg<'a, AM: AttrMetaMethods, It: Iterator<&'a AM>>
|
|
||||||
(cfg: &[P<MetaItem>], mut metas: It) -> bool {
|
|
||||||
// having no #[cfg(...)] attributes counts as matching.
|
|
||||||
let mut no_cfgs = true;
|
|
||||||
|
|
||||||
// this would be much nicer as a chain of iterator adaptors, but
|
|
||||||
// this doesn't work.
|
|
||||||
let some_cfg_matches = metas.fold(false, |matches, mi| {
|
|
||||||
debug!("testing name: {}", mi.name());
|
|
||||||
let this_matches = if mi.check_name("cfg") { // it is a #[cfg()] attribute
|
|
||||||
debug!("is cfg");
|
|
||||||
no_cfgs = false;
|
|
||||||
// only #[cfg(...)] ones are understood.
|
|
||||||
match mi.meta_item_list() {
|
|
||||||
Some(cfg_meta) => {
|
|
||||||
debug!("is cfg(...)");
|
|
||||||
cfg_meta.iter().all(|cfg_mi| {
|
|
||||||
debug!("cfg({}[...])", cfg_mi.name());
|
|
||||||
match cfg_mi.node {
|
|
||||||
ast::MetaList(ref s, ref not_cfgs)
|
|
||||||
if s.equiv(&("not")) => {
|
|
||||||
debug!("not!");
|
|
||||||
// inside #[cfg(not(...))], so these need to all
|
|
||||||
// not match.
|
|
||||||
!not_cfgs.iter().all(|mi| {
|
|
||||||
debug!("cfg(not({}[...]))", mi.name());
|
|
||||||
contains(cfg, &**mi)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => contains(cfg, &**cfg_mi)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
None => false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
matches || this_matches
|
|
||||||
});
|
|
||||||
debug!("test_cfg (no_cfgs={}, some_cfg_matches={})", no_cfgs, some_cfg_matches);
|
|
||||||
no_cfgs || some_cfg_matches
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Represents the #[deprecated="foo"] and friends attributes.
|
/// Represents the #[deprecated="foo"] and friends attributes.
|
||||||
#[deriving(Encodable,Decodable,Clone,Show)]
|
#[deriving(Encodable,Decodable,Clone,Show)]
|
||||||
pub struct Stability {
|
pub struct Stability {
|
||||||
|
@ -261,20 +261,20 @@ fn in_cfg(diagnostic: &SpanHandler, cfg: &[P<ast::MetaItem>], attrs: &[ast::Attr
|
|||||||
};
|
};
|
||||||
|
|
||||||
if mis.len() != 1 {
|
if mis.len() != 1 {
|
||||||
diagnostic.span_warn(attr.span, "The use of multiple cfgs in the top level of \
|
diagnostic.span_err(attr.span, "expected 1 cfg-pattern");
|
||||||
`#[cfg(..)]` is deprecated. Change `#[cfg(a, b)]` to \
|
return false;
|
||||||
`#[cfg(all(a, b))]`.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if seen_cfg {
|
if seen_cfg {
|
||||||
diagnostic.span_warn(attr.span, "The semantics of multiple `#[cfg(..)]` attributes on \
|
diagnostic.span_err(attr.span, "The semantics of multiple `#[cfg(..)]` attributes on \
|
||||||
same item are changing from the union of the cfgs to \
|
same item are changing from the union of the cfgs to \
|
||||||
the intersection of the cfgs. Change `#[cfg(a)] \
|
the intersection of the cfgs. Change `#[cfg(a)] \
|
||||||
#[cfg(b)]` to `#[cfg(any(a, b))]`.");
|
#[cfg(b)]` to `#[cfg(any(a, b))]`.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
seen_cfg = true;
|
seen_cfg = true;
|
||||||
in_cfg |= mis.iter().all(|mi| attr::cfg_matches(diagnostic, cfg, &**mi));
|
in_cfg |= attr::cfg_matches(diagnostic, cfg, &*mis[0]);
|
||||||
}
|
}
|
||||||
in_cfg | !seen_cfg
|
in_cfg | !seen_cfg
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,9 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
/**
|
/// The compiler code necessary to support the cfg! extension, which expands to
|
||||||
The compiler code necessary to support the cfg! extension, which
|
/// a literal `true` or `false` based on whether the given cfg matches the
|
||||||
expands to a literal `true` or `false` based on whether the given cfgs
|
/// current compilation environment.
|
||||||
match the current compilation environment.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use ast;
|
use ast;
|
||||||
use codemap::Span;
|
use codemap::Span;
|
||||||
@ -24,28 +22,18 @@ use attr::*;
|
|||||||
use parse::attr::ParserAttr;
|
use parse::attr::ParserAttr;
|
||||||
use parse::token;
|
use parse::token;
|
||||||
|
|
||||||
|
|
||||||
pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
|
pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[ast::TokenTree])
|
tts: &[ast::TokenTree])
|
||||||
-> Box<base::MacResult+'static> {
|
-> Box<base::MacResult+'static> {
|
||||||
let mut p = cx.new_parser_from_tts(tts);
|
let mut p = cx.new_parser_from_tts(tts);
|
||||||
let mut cfgs = Vec::new();
|
let cfg = p.parse_meta_item();
|
||||||
// parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)`
|
|
||||||
while p.token != token::EOF {
|
if !p.eat(&token::EOF) {
|
||||||
cfgs.push(p.parse_meta_item());
|
cx.span_err(sp, "expected 1 cfg-pattern");
|
||||||
if p.eat(&token::EOF) { break } // trailing comma is optional,.
|
return DummyResult::expr(sp);
|
||||||
p.expect(&token::COMMA);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfgs.len() != 1 {
|
let matches_cfg = attr::cfg_matches(&cx.parse_sess.span_diagnostic, cx.cfg.as_slice(), &*cfg);
|
||||||
cx.span_warn(sp, "The use of multiple cfgs at the top level of `cfg!` \
|
|
||||||
is deprecated. Change `cfg!(a, b)` to \
|
|
||||||
`cfg!(all(a, b))`.");
|
|
||||||
}
|
|
||||||
|
|
||||||
let matches_cfg = cfgs.iter().all(|cfg| attr::cfg_matches(&cx.parse_sess.span_diagnostic,
|
|
||||||
cx.cfg.as_slice(), &**cfg));
|
|
||||||
|
|
||||||
MacExpr::new(cx.expr_bool(sp, matches_cfg))
|
MacExpr::new(cx.expr_bool(sp, matches_cfg))
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
|
|||||||
span: i.span,
|
span: i.span,
|
||||||
path: self.cx.path.clone(),
|
path: self.cx.path.clone(),
|
||||||
bench: is_bench_fn(&self.cx, &*i),
|
bench: is_bench_fn(&self.cx, &*i),
|
||||||
ignore: is_ignored(&self.cx, &*i),
|
ignore: is_ignored(&*i),
|
||||||
should_fail: should_fail(&*i)
|
should_fail: should_fail(&*i)
|
||||||
};
|
};
|
||||||
self.cx.testfns.push(test);
|
self.cx.testfns.push(test);
|
||||||
@ -343,22 +343,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
|
|||||||
return has_bench_attr && has_test_signature(i);
|
return has_bench_attr && has_test_signature(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ignored(cx: &TestCtxt, i: &ast::Item) -> bool {
|
fn is_ignored(i: &ast::Item) -> bool {
|
||||||
i.attrs.iter().any(|attr| {
|
i.attrs.iter().any(|attr| attr.check_name("ignore"))
|
||||||
// check ignore(cfg(foo, bar))
|
|
||||||
attr.check_name("ignore") && match attr.meta_item_list() {
|
|
||||||
Some(ref cfgs) => {
|
|
||||||
if cfgs.iter().any(|cfg| cfg.check_name("cfg")) {
|
|
||||||
cx.span_diagnostic.span_warn(attr.span,
|
|
||||||
"The use of cfg filters in #[ignore] is \
|
|
||||||
deprecated. Use #[cfg_attr(<cfg pattern>, \
|
|
||||||
ignore)] instead.");
|
|
||||||
}
|
|
||||||
attr::test_cfg(cx.config.as_slice(), cfgs.iter())
|
|
||||||
}
|
|
||||||
None => true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_fail(i: &ast::Item) -> bool {
|
fn should_fail(i: &ast::Item) -> bool {
|
||||||
|
@ -26,8 +26,7 @@ pub extern "win64" fn foo(a: int, b: int, c: int, d: int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "arm"))]
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
pub extern fn foo(a: int, b: int, c: int, d: int) {
|
pub extern fn foo(a: int, b: int, c: int, d: int) {
|
||||||
assert!(a == 1);
|
assert!(a == 1);
|
||||||
assert!(b == 2);
|
assert!(b == 2);
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore(cfg(ignorecfg))]
|
#[cfg_attr(ignorecfg, ignore)]
|
||||||
fn shouldignore() {
|
fn shouldignore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore(cfg(noignorecfg))]
|
#[cfg_attr(noignorecfg, ignore)]
|
||||||
fn shouldnotignore() {
|
fn shouldnotignore() {
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
unsafe fn next_power_of_2(n: u32) -> u32 {
|
unsafe fn next_power_of_2(n: u32) -> u32 {
|
||||||
let mut tmp = n;
|
let mut tmp = n;
|
||||||
asm!("dec $0" : "+rm"(tmp) :: "cc");
|
asm!("dec $0" : "+rm"(tmp) :: "cc");
|
||||||
@ -28,8 +27,7 @@ unsafe fn next_power_of_2(n: u32) -> u32 {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert_eq!(64, next_power_of_2(37));
|
assert_eq!(64, next_power_of_2(37));
|
||||||
@ -62,5 +60,5 @@ pub fn main() {
|
|||||||
assert_eq!(x, 60);
|
assert_eq!(x, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "x86"), not(target_arch = "x86_64"))]
|
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||||
pub fn main() {}
|
pub fn main() {}
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x: int;
|
let x: int;
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -30,5 +29,5 @@ pub fn main() {
|
|||||||
assert_eq!(x, 13);
|
assert_eq!(x, 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "x86"), not(target_arch = "x86_64"))]
|
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||||
pub fn main() {}
|
pub fn main() {}
|
||||||
|
@ -9,8 +9,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "arm"))]
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
fn target() {
|
fn target() {
|
||||||
assert_eq!(-1000 as uint >> 3u, 536870787u);
|
assert_eq!(-1000 as uint >> 3u, 536870787u);
|
||||||
}
|
}
|
||||||
|
@ -11,24 +11,23 @@
|
|||||||
// compile-flags: --cfg fooA --cfg fooB
|
// compile-flags: --cfg fooA --cfg fooB
|
||||||
|
|
||||||
// fooA AND !bar
|
// fooA AND !bar
|
||||||
#[cfg(fooA, not(bar))]
|
#[cfg(all(fooA, not(bar)))]
|
||||||
fn foo1() -> int { 1 }
|
fn foo1() -> int { 1 }
|
||||||
|
|
||||||
// !fooA AND !bar
|
// !fooA AND !bar
|
||||||
#[cfg(not(fooA), not(bar))]
|
#[cfg(all(not(fooA), not(bar)))]
|
||||||
fn foo2() -> int { 2 }
|
fn foo2() -> int { 2 }
|
||||||
|
|
||||||
// fooC OR (fooB AND !bar)
|
// fooC OR (fooB AND !bar)
|
||||||
#[cfg(fooC)]
|
#[cfg(any(fooC, all(fooB, not(bar))))]
|
||||||
#[cfg(fooB, not(bar))]
|
|
||||||
fn foo2() -> int { 3 }
|
fn foo2() -> int { 3 }
|
||||||
|
|
||||||
// fooA AND bar
|
// fooA AND bar
|
||||||
#[cfg(fooA, bar)]
|
#[cfg(all(fooA, bar))]
|
||||||
fn foo3() -> int { 2 }
|
fn foo3() -> int { 2 }
|
||||||
|
|
||||||
// !(fooA AND bar)
|
// !(fooA AND bar)
|
||||||
#[cfg(not(fooA, bar))]
|
#[cfg(not(all(fooA, bar)))]
|
||||||
fn foo3() -> int { 3 }
|
fn foo3() -> int { 3 }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
@ -60,10 +60,10 @@ pub fn test_destroy_actually_kills(force: bool) {
|
|||||||
use libc;
|
use libc;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
#[cfg(unix,not(target_os="android"))]
|
#[cfg(all(unix,not(target_os="android")))]
|
||||||
static BLOCK_COMMAND: &'static str = "cat";
|
static BLOCK_COMMAND: &'static str = "cat";
|
||||||
|
|
||||||
#[cfg(unix,target_os="android")]
|
#[cfg(all(unix,target_os="android"))]
|
||||||
static BLOCK_COMMAND: &'static str = "/system/bin/cat";
|
static BLOCK_COMMAND: &'static str = "/system/bin/cat";
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -17,10 +17,10 @@ mod rusti {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux",
|
||||||
#[cfg(target_os = "macos")]
|
target_os = "macos",
|
||||||
#[cfg(target_os = "freebsd")]
|
target_os = "freebsd",
|
||||||
#[cfg(target_os = "dragonfly")]
|
target_os = "dragonfly"))]
|
||||||
mod m {
|
mod m {
|
||||||
#[main]
|
#[main]
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(target_arch = "x86")]
|
||||||
@ -32,8 +32,7 @@ mod m {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[main]
|
#[main]
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(any(target_arch = "x86_64", target_arch = "arm"))]
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert_eq!(::rusti::pref_align_of::<u64>(), 8u);
|
assert_eq!(::rusti::pref_align_of::<u64>(), 8u);
|
||||||
|
@ -36,8 +36,7 @@ macro_rules! demo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
fn main() {
|
fn main() {
|
||||||
fn out_write_only_expr_then_in_expr() {
|
fn out_write_only_expr_then_in_expr() {
|
||||||
demo!("=r")
|
demo!("=r")
|
||||||
@ -51,5 +50,5 @@ fn main() {
|
|||||||
out_read_write_expr_then_in_expr();
|
out_read_write_expr_then_in_expr();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "x86"), not(target_arch = "x86_64"))]
|
#[cfg(all(not(target_arch = "x86"), not(target_arch = "x86_64")))]
|
||||||
pub fn main() {}
|
pub fn main() {}
|
||||||
|
@ -28,8 +28,7 @@ pub fn main() {
|
|||||||
assert_eq!(mem::size_of::<Kitty>(), 16 as uint);
|
assert_eq!(mem::size_of::<Kitty>(), 16 as uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "arm"))]
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
assert_eq!(mem::size_of::<Cat>(), 4 as uint);
|
assert_eq!(mem::size_of::<Cat>(), 4 as uint);
|
||||||
assert_eq!(mem::size_of::<Kitty>(), 8 as uint);
|
assert_eq!(mem::size_of::<Kitty>(), 8 as uint);
|
||||||
|
@ -36,8 +36,7 @@ struct Outer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "arm"))]
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
mod m {
|
mod m {
|
||||||
pub fn align() -> uint { 4u }
|
pub fn align() -> uint { 4u }
|
||||||
pub fn size() -> uint { 8u }
|
pub fn size() -> uint { 8u }
|
||||||
|
@ -36,10 +36,10 @@ struct Outer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux",
|
||||||
#[cfg(target_os = "macos")]
|
target_os = "macos",
|
||||||
#[cfg(target_os = "freebsd")]
|
target_os = "freebsd",
|
||||||
#[cfg(target_os = "dragonfly")]
|
target_os = "dragonfly"))]
|
||||||
mod m {
|
mod m {
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(target_arch = "x86")]
|
||||||
pub mod m {
|
pub mod m {
|
||||||
@ -47,8 +47,7 @@ mod m {
|
|||||||
pub fn size() -> uint { 12u }
|
pub fn size() -> uint { 12u }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(any(target_arch = "x86_64", target_arch = "arm"))]
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
pub mod m {
|
pub mod m {
|
||||||
pub fn align() -> uint { 8u }
|
pub fn align() -> uint { 8u }
|
||||||
pub fn size() -> uint { 16u }
|
pub fn size() -> uint { 16u }
|
||||||
|
@ -57,8 +57,7 @@ fn test2() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(any(target_arch = "x86", target_arch = "arm"))]
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
fn test2() {
|
fn test2() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,17 +18,15 @@ pub fn main() {
|
|||||||
if ! cfg!(qux="foo") { fail!() }
|
if ! cfg!(qux="foo") { fail!() }
|
||||||
if cfg!(not(qux="foo")) { fail!() }
|
if cfg!(not(qux="foo")) { fail!() }
|
||||||
|
|
||||||
if ! cfg!(foo, qux="foo") { fail!() }
|
if ! cfg!(all(foo, qux="foo")) { fail!() }
|
||||||
if cfg!(not(foo, qux="foo")) { fail!() }
|
if cfg!(not(all(foo, qux="foo"))) { fail!() }
|
||||||
if cfg!(all(not(foo, qux="foo"))) { fail!() }
|
if cfg!(all(not(all(foo, qux="foo")))) { fail!() }
|
||||||
|
|
||||||
if cfg!(not_a_cfg) { fail!() }
|
if cfg!(not_a_cfg) { fail!() }
|
||||||
if cfg!(not_a_cfg, foo, qux="foo") { fail!() }
|
if cfg!(all(not_a_cfg, foo, qux="foo")) { fail!() }
|
||||||
if cfg!(all(not_a_cfg, foo, qux="foo")) { fail!() }
|
if cfg!(all(not_a_cfg, foo, qux="foo")) { fail!() }
|
||||||
if ! cfg!(any(not_a_cfg, foo)) { fail!() }
|
if ! cfg!(any(not_a_cfg, foo)) { fail!() }
|
||||||
|
|
||||||
if ! cfg!(not(not_a_cfg)) { fail!() }
|
if ! cfg!(not(not_a_cfg)) { fail!() }
|
||||||
if ! cfg!(not(not_a_cfg), foo, qux="foo") { fail!() }
|
if ! cfg!(all(not(not_a_cfg), foo, qux="foo")) { fail!() }
|
||||||
|
|
||||||
if cfg!(trailing_comma, ) { fail!() }
|
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,9 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(any(target_os = "macos",
|
||||||
#[cfg(target_os = "linux")]
|
target_os = "linux",
|
||||||
#[cfg(target_os = "freebsd")]
|
target_os = "freebsd",
|
||||||
#[cfg(target_os = "dragonfly")]
|
target_os = "dragonfly",
|
||||||
#[cfg(target_os = "android")]
|
target_os = "android"))]
|
||||||
pub fn main() { }
|
pub fn main() { }
|
||||||
|
Loading…
Reference in New Issue
Block a user