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

Strange formatting of macro_rules! macro #6131

Open
Andlon opened this issue Mar 31, 2024 · 6 comments
Open

Strange formatting of macro_rules! macro #6131

Andlon opened this issue Mar 31, 2024 · 6 comments

Comments

@Andlon
Copy link

Andlon commented Mar 31, 2024

With Rust 1.77.1 and rustfmt 1.7.0, as well as on current nightly 2024-03-30, the following macro definition (playground)

macro_rules! assert_eq_and_type {
    ($left:expr, $right:expr $(,)?) => {
        {
            fn check_statically_same_type<T>(_: &T, _: &T) {}
            check_statically_same_type(&$left, &$right);
        }
        assert_eq!($left, $right);
    };
}

formats to

macro_rules! assert_eq_and_type {
    ($left:expr, $right:expr $(,)?) => {{
        fn check_statically_same_type<T>(_: &T, _: &T) {}
        check_statically_same_type(&$left, &$right);
    }
    assert_eq!($left, $right);};
}

This certainly doesn't look right to me. I looked at other reported macro-related issues but couldn't find any very similar issues.

@ytmimi
Copy link
Contributor

ytmimi commented Apr 1, 2024

@Andlon thanks for the report. This definitely feels like a distinct formatting issue. When you get a chance can you run rustfmt +1.77.1 --version and rustfmt +nightly --version so we get exact version numbers. Also, are you using a configuration options?

@Andlon
Copy link
Author

Andlon commented Apr 1, 2024

@ytmimi: The command rustfmt +1.77.1 --version does not work for me, complaining that error: toolchain '1.77.1-x86_64-unknown-linux-gnu' is not installed (though rustc is definitely 1.77.1).

In any case, the issue can be reproduced on the playground (see my link in the first issue). There it says that for:

  • for stable 1.77.1, it's using rustfmt 1.7.0-stable (2024-03-27 7cf61eb).
  • for 1.79.0-nightly (2024-03-31 805813650248c1a2f6f2) it's using rustfmt 1.7.0-nightly (2024-03-31 8058136).

I hope that helps!

@Andlon
Copy link
Author

Andlon commented Apr 1, 2024

As for configuration options, I assume the playground uses default options? The code base I was working on locally had a rustfmt.toml like this:

edition = "2018"
use_try_shorthand = true
use_field_init_shorthand = true

@ytmimi
Copy link
Contributor

ytmimi commented Apr 1, 2024

Thanks for the extra info! I'm also guessing that the playground uses default options, and I think it's unlikely that the configuration options you're currently using lead to this issue.

@correabuscar

This comment was marked as off-topic.

@ytmimi
Copy link
Contributor

ytmimi commented May 22, 2024

@correabuscar my guess is that this is unrelated. rustfmt doesn't format macros that use repetition so that likely explains why your manual edits are left unchanged.

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

No branches or pull requests

3 participants