Skip to content

Macro hygiene issue: Parameter value loss in Windows release builds #144332

@SGA-cs

Description

@SGA-cs

I tried this code:

macro_rules! expand_tuple {
    ($kind:path, $param:expr) => {
        $kind($param, $param) // Second $param becomes 0.0
    };
}

enum FigureKind {
    Circle(f64, f64),
}

fn main() {
    let circle = expand_tuple!(FigureKind::Circle, 2.0);
    assert_eq!(circle, FigureKind::Circle(2.0, 2.0)); // Fails in release
}

I expected to see this happen: Macro should generate FigureKind::Circle(2.0, 2.0) where both parameters keep their values

Instead, this happened: Second parameter becomes 0.0 in release builds: FigureKind::Circle(2.0, 0.0)

Meta

Additional observations:

  • Only happens in release builds (--release)
  • Works correctly in debug mode
  • Affects f64 but not i32
  • All standard macro hygiene workarounds fail
    rustc --version --verbose:
rustc --version: rustc 1.87.0 (17067e9ac 2025-05-09)

Suggested labels: A-macros, T-compiler

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions