Skip to content

cfg: composing/nested and+not does not work #10546

Closed
@pnkfelix

Description

@pnkfelix

It is hard (maybe impossible) to compile certain combinations of cfg flags.
E.g.: I believe the following should always compile, for any choice of a and b cfg switches:

#[cfg(and(not(a),not(b)))]
fn f() { println!("Got it"); }

#[cfg(a)]
fn f() { println!("in a"); }

#[cfg(b)]
fn f() { println!("in b"); }

fn main() {
    f();
}

But currently you get:

% rustc d.rs
d.rs:11:4: 11:5 error: unresolved name `f`.
d.rs:11     f();
            ^
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /Users/fklock/Dev/Mozilla/rust.git/src/libsyntax/diagnostic.rs:101
task '<main>' failed at 'explicit failure', /Users/fklock/Dev/Mozilla/rust.git/src/librustc/lib.rs:396

I believe this is because our current cfg implementation is largely just a hack, rather than a proper expression evaluator. See also #2119.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions