Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a cfg_attr syntax extension #16230

Closed
wants to merge 2 commits into from
Closed

Commits on Aug 4, 2014

  1. 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> { ... }
    ```
    sfackler committed Aug 4, 2014
    Configuration menu
    Copy the full SHA
    332f0f4 View commit details
    Browse the repository at this point in the history
  2. Deprecate #[ignore(cfg(...))]

    Replace `#[ignore(cfg(a, b))]` with `#[cfg_attr(all(a, b), ignore)]`
    sfackler committed Aug 4, 2014
    Configuration menu
    Copy the full SHA
    b8c51fc View commit details
    Browse the repository at this point in the history