dtolnay / rustversion

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

Allow for the `const` keyword to be used in trait impls. #38

Closed JohnBobbo96 closed 1 year ago

JohnBobbo96 commented 1 year ago

Allow for the const keyword to be used in trait impls. This can be used to implement const traits on nightly, for example:

// this requires a feature gate for now.
#![feature(const_trait_impl)]

#[rustversion::attr(nightly, const_trait)]
trait Foo {
    fn foo() -> u32;
}

#[rustversion::attr(nightly, const)]
// this turns into `impl const Foo for u32`.
impl Foo for u32 {
    fn foo() -> u32 {
        42
    }
}