Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in macro output between 1.37.0 and 1.38.0 #65207

Closed
djc opened this issue Oct 8, 2019 · 3 comments
Closed

Change in macro output between 1.37.0 and 1.38.0 #65207

djc opened this issue Oct 8, 2019 · 3 comments

Comments

@djc
Copy link
Contributor

djc commented Oct 8, 2019

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

@ehuss
Copy link
Contributor

ehuss commented Oct 8, 2019

This was changed by #63897. cc @petrochenkov

@petrochenkov
Copy link
Contributor

in general we do not guarantee stability of pretty printing

#63897 (comment) -> #63896 (comment)

That's especially true for whitespace in pretty-printing.

@djc
Copy link
Contributor Author

djc commented Oct 9, 2019

Alright, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants