How to protect nightly feature 'extended_key_value_attributes' behind a crate feature?

615 views Asked by At

I run code using stable and document it using nightly, mostly because of the automatic links.

I tried to include a long inner documentation by #![doc = include_str!("doc.md")] in the code, but only use it if using nightly, as it is unstable. The standard way to do it seems to be with an explicit feature.

I declared a nightly feature on my Cargo.toml, and tried:

#![cfg_attr(feature = "nightly", 
    feature(extended_key_value_attributes),
    doc = include_str!("doc.md"))]

which works as expected with cargo +nightly doc --features nightly, but is not supported by stable:

> cargo +stable build
[...]
error[E0658]: arbitrary expressions in key-value attributes are unstable

I suspect the cfg_attr has to parse all its arguments even if not using them, so the macro syntax within the #[]makes things more complicated.

How can I do this correctly?

0

There are 0 answers