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

Incorrectly and non-idempotently modifies .. in macro #6300

Open
anchpop opened this issue Aug 29, 2024 · 1 comment
Open

Incorrectly and non-idempotently modifies .. in macro #6300

anchpop opened this issue Aug 29, 2024 · 1 comment
Labels
a-comments a-macros bug Panic, non-idempotency, invalid code, etc.

Comments

@anchpop
Copy link

anchpop commented Aug 29, 2024

Start with this:

fn a() {
    a!(b {
        c: d,
        //
        ..
    });
}

Rust rustfmt, and you get this:

fn a() {
    a!(b {
        c: d,
        //
        ..
        ..
    });
}

Run it a third time, and you get this:

fn a() {
    a!(b {
        c: d,
        //
        ....
    });
}

And then we have a fixed point.

This can cause rustfmt to break certain macro-using code. The behavior still exists if you substitute a rather than a!, and I guess it's weird if it's not idempotent, but it's a bit of an edge case since that is not syntactically valid rust anyway. But you can write fully-compilable code that exhibits this behavior when formatted with rustfmt, if you're using certain macros like assert_matches!.

@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. a-macros labels Aug 29, 2024
@AnBarr45
Copy link

AnBarr45 commented Aug 31, 2024

it seem like this bug is present only for non-doc comments, and it triggers with just struct construction, here's a min example:

const B: b =  b {
    c: d,
    /* block comment, has bug */
    // line comment, has bug
    ..
  };

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.
Projects
None yet
Development

No branches or pull requests

3 participants