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

rustfmt not idempotent with a comment + or-pattern in a macro #4603

Closed
Nadrieril opened this issue Dec 18, 2020 · 2 comments
Closed

rustfmt not idempotent with a comment + or-pattern in a macro #4603

Nadrieril opened this issue Dec 18, 2020 · 2 comments
Labels
a-comments a-macros bug Panic, non-idempotency, invalid code, etc. help wanted
Milestone

Comments

@Nadrieril
Copy link
Member

Describe the bug

If I start with this code and repeatedly run rustfmt, I get:

#![feature(or_patterns)]
macro_rules! t_or_f {
    () => {
        (true // some comment
        | false)
    };
}

==>>

#![feature(or_patterns)]
macro_rules! t_or_f {
    () => {
        (true // some comment
                | false)
    };
}

==>>

#![feature(or_patterns)]
macro_rules! t_or_f {
    () => {
        (true // some comment
                        | false)
    };
}

etc. After enough iterations the | false) stops moving but it's way off to the right.

This bug doesn't appear without the comment or outside a macro. Note that this macro returns a pattern, and that or-patterns are an unstable feature.

To Reproduce

This works on a fresh project without a rustfmt.toml and with both stable and nightly rustfmt.

Expected behavior

The absence of a | false) glider trying to escape from the file.

Meta

  • rustfmt version: rustfmt 1.4.24-stable (eb894d5 2020-11-05) && rustfmt 1.4.29-nightly (70ce182 2020-12-04)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: tried both rustfmt and cargo fmt
@Nadrieril Nadrieril added the bug Panic, non-idempotency, invalid code, etc. label Dec 18, 2020
davidBar-On added a commit to davidBar-On/rustfmt that referenced this issue Jan 7, 2021
@davidBar-On
Copy link
Contributor

The issue is caused because original code snippet is used, since currently rustfmt is not handling comments in expressions like:

        (true // some comment
        | false)

Submitted PR #4629 with a proposed solution to the extra indentation issue. Did not try to solve the comment issue, as the extra indentation is a general problem when original code snippet is used during macro body formatting.

@calebcartwright
Copy link
Member

Closed in #4697, fix will be in the next release

@calebcartwright calebcartwright added this to the 1.4.37 milestone Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments a-macros bug Panic, non-idempotency, invalid code, etc. help wanted
Projects
None yet
Development

No branches or pull requests

3 participants