rust-lang / cfg-if

A if/elif-like macro for Rust #[cfg] statements
Apache License 2.0
557 stars 40 forks source link

Expected `fn` not `fn blah` #10

Closed glmdgrielson closed 5 years ago

glmdgrielson commented 6 years ago
impl Trait for Struct {
    cfg_if! {
        if #[cfg(feature = "blah")] {
            fn blah(&self) {
                unimplemented!();
            }
        } else {
            fn blah(&self) {
                unimplemented!();
            }
        }
    }
}

This generates the error:

expected one of `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`, found `fn blah(?) { unimplemented!(); }`

expected one of 8 possible tokens here

What gives? Putting the attribute myself works but the macro has a weird failure.

alexcrichton commented 6 years ago

Thanks for the report! Currently though this crate only works with "item" AST nodes rather than "impl items" lie functions in an impl

alexcrichton commented 5 years ago

As of https://github.com/alexcrichton/cfg-if/pull/28 this is now supported