dtolnay / rustversion

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

Add rustversion::cfg! macro #30

Closed dtolnay closed 2 years ago

dtolnay commented 2 years ago

A function-like procedural macro named cfg! was disallowed prior to Rust 1.38:

error: name `cfg` is reserved in macro namespace
   --> src/lib.rs:233:8
    |
233 | pub fn cfg(input: TokenStream) -> TokenStream {
    |        ^^^

but this restriction was lifted by https://github.com/rust-lang/rust/pull/62243 (https://github.com/rust-lang/rust/commit/327450797d460ae011eaaba68fae356117ab883d) and https://github.com/rust-lang/rust/pull/62476.

Usage:

if rustversion::cfg!(nightly) {
    ...
} else {
    ...
}

Closes #7.