RFC: #[cfg(accessible(..) / version(..))] by Centril · Pull Request #2523 · rust-lang/rfcs (original) (raw)
Another point is that things that are gated sill need to use valid rust grammar.
Let's assume that the version 1.42 adds support for throwing function, and using .if:
#[cfg(version(1.42))]
fn foo(x : bool) -> u32 throw(SomeError) {
x.if { something() } else { 0 }
}
This won't compile in current rust, even after this rfc is implemented, because this is not valid grammar, and rustc still check the grammar of items even if they are going to be removed by attribute macro or cfg attribute.
I suppose it would not make sense to relax the parsing rules of items that are disabled by #[cfg]
So one must wrap the item inside a macro such as cfg-if!{...}
but which would not expand the items for the disabled configuration. Something like this should work: #[cfg($cfg)] identity!{ <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span></span></span></span>body)* }
.
Btw, I've made a crate with a macro if_rust_version
with macro_rules that allows conditional like that depending on the rust version: https://github.com/ogoffart/if_rust_version