dtolnay / rustversion

Conditional compilation according to rustc compiler version
Apache License 2.0
326 stars 15 forks source link

Analog to std::cfg! macro #7

Closed CreepySkeleton closed 2 years ago

CreepySkeleton commented 4 years ago

Sometimes it's neat to have a macro expanding to true orfalse instead of attribute. I propose to implement rusversion::cfg!(stable...) macro.

By the way, I believe it can be implemented via

macro_rules! cfg {
    ($(tts:tt)*) => {{
        #[rustversion::$(tts)*] fn do_cfg() { true }
        #[rustversion::not($(tts)*)] fn do_cfg() { false }

        do_cfg()
    }}
}
jhpratt commented 3 years ago

@dtolnay Function-like and attribute macros can exist in the same crate with the same name, correct? If so, I think this should be relatively easy to modify the existing code to add support for this. I may be able to do it if my understanding is correct.