2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
//@ compile-flags:--cfg set1 --cfg set2
|
|
|
|
#![allow(dead_code)]
|
2015-01-20 23:45:07 +00:00
|
|
|
use std::fmt::Debug;
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
struct NotDebugable;
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(set1, derive(Debug))]
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
struct Set1;
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(notset, derive(Debug))]
|
|
|
|
struct Notset(NotDebugable);
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(not(notset), derive(Debug))]
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
struct NotNotset;
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(not(set1), derive(Debug))]
|
|
|
|
struct NotSet1(NotDebugable);
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(all(set1, set2), derive(Debug))]
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
struct AllSet1Set2;
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(all(set1, notset), derive(Debug))]
|
|
|
|
struct AllSet1Notset(NotDebugable);
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(any(set1, notset), derive(Debug))]
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
struct AnySet1Notset;
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(any(notset, notset2), derive(Debug))]
|
|
|
|
struct AnyNotsetNotset2(NotDebugable);
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(all(not(notset), any(set1, notset)), derive(Debug))]
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
struct Complex;
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(any(notset, not(any(set1, notset))), derive(Debug))]
|
|
|
|
struct ComplexNot(NotDebugable);
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[cfg_attr(any(target_endian = "little", target_endian = "big"), derive(Debug))]
|
2014-08-04 00:41:58 +00:00
|
|
|
struct KeyValue;
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
fn is_show<T: Debug>() {}
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
is_show::<Set1>();
|
|
|
|
is_show::<NotNotset>();
|
|
|
|
is_show::<AllSet1Set2>();
|
|
|
|
is_show::<AnySet1Notset>();
|
|
|
|
is_show::<Complex>();
|
2014-08-04 00:41:58 +00:00
|
|
|
is_show::<KeyValue>();
|
Add a cfg_attr syntax extension
This extends cfg-gating to attributes.
```rust
#[cfg_attr(<cfg pattern>, <attr>)]
```
will expand to
```rust
#[<attr>]
```
if the `<cfg pattern>` matches the current cfg environment, and nothing
if it does not. The grammar for the cfg pattern has a simple
recursive structure:
* `value` and `key = "value"` are cfg patterns,
* `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`
does not.
* `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the
`<cfg pattern>`s do.
* `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the
`<cfg pattern>`s do.
Examples:
```rust
// only derive Show for assert_eq! in tests
#[cfg_attr(test, deriving(Show))]
struct Foo { ... }
// only derive Show for assert_eq! in tests and debug builds
#[cfg_attr(any(test, not(ndebug)), deriving(Show))]
struct Foo { ... }
// ignore a test in certain cases
#[test]
#[cfg_attr(all(not(target_os = "linux"), target_endian = "big"), ignore)]
fn test_broken_thing() { ... }
// Avoid duplication when fixing staging issues in rustc
#[cfg_attr(not(stage0), lang="iter")]
pub trait Iterator<T> { ... }
```
2014-08-03 21:25:30 +00:00
|
|
|
}
|