Skip to content

Change in macro output between 1.37.0 and 1.38.0 #65207

Closed
@djc

Description

@djc

The following code changed output between Rust 1.37.0 and 1.38.0:

macro_rules! call_a_or_b_on_tail {
    ((a: $a:expr, b: $b:expr), call a: $($tail:tt)*) => {
        $a(stringify!($($tail)*))
    };
    ((a: $a:expr, b: $b:expr), call b: $($tail:tt)*) => {
        $b(stringify!($($tail)*))
    };
    ($ab:tt, $_skip:tt $($tail:tt)*) => {
        call_a_or_b_on_tail!($ab, $($tail)*)
    };
}

fn compute_len(s: &str) -> usize {
    s.len()
}

fn main() {
    println!(
        "{expr1}\n{expr2}",
        expr1 = call_a_or_b_on_tail!(
            (a: compute_len, b: zero),
                and now, to justify the existence of two paths
                we will also call a: its input should somehow
                be self-referential, so let's make it return
                some ninety one!
        ),
        expr2 = call_a_or_b_on_tail!(
            (a: compute_len, b: zero),
                and now, to justify the existence of two paths
                we will also call a: its input should somehow
                be self-referential, so let's make it return
                some ninety "(\"()"nine!
        ),
    );
}
djc-ing master regress $ cargo run
   Compiling regress v0.1.0 (/Users/djc/src/regress)
    Finished dev [unoptimized + debuginfo] target(s) in 0.35s
     Running `target/debug/regress`
90
98
djc-ing master regress $ cargo +1.37.0 run
   Compiling regress v0.1.0 (/Users/djc/src/regress)
    Finished dev [unoptimized + debuginfo] target(s) in 0.30s
     Running `target/debug/regress`
91
99

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6f67da3ab63067c8186ca702fe1c1910

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