Skip to content

Regression w.r.t. lazy evaluation of cfg predicates #96018

Closed
@danielhenrymantilla

Description

@danielhenrymantilla

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 cfgs are an incredibly convenient place to smuggle those:

https://github.com/getditto/safer_ffi/blob/277f3e7b9c382532a7b2bb5499d296a8d78b6d8e/src/ffi_export.rs#L137-L138

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions