Description
Code
I tried this code:
#[cfg(any(all(), __super_useful_macro_rules_hack = 42))]
fn main ()
{}
I expected to see this happen: code compiles fine, since the previous cfg resolves to true
, short-circuiting the any
until it reaches __super_useful_macro_rules_hack = 42
Instead, this happened: on a non-stable Rust compiler, these last attributes are nonetheless evaluated, and the compiler triggers an error for code that otherwise compiles fine.
Version it worked on
It most recently worked on: Rust 1.60.0
Version with regression
rustc --version --verbose
:
1.61.0-beta.2
2022-04-09 7c13df853721b60a03e7
Backtrace
Backtrace
<backtrace>
@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged
I suspect this has to do with #94175 (comment) (cc @Urgau)
Why that code
This pattern is an incredibly useful trick for macro_rules!
authors, at least until we get something like empty captures or other operators.
When using $( … )*
and $( … )?
Kleene operators, the metavar guiding that repetition count needs to be inside those parenthesis. But sometimes we have no use for the metavariable.
When the metavariable is of kind :literal
, lazily unchecked cfg
s are an incredibly convenient place to smuggle those: