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

buggy formatting on expression attributes with comments #5871

Closed
meetmangukiya opened this issue Aug 1, 2023 · 2 comments · Fixed by #5913
Closed

buggy formatting on expression attributes with comments #5871

meetmangukiya opened this issue Aug 1, 2023 · 2 comments · Fixed by #5913
Labels
a-comments bug Panic, non-idempotency, invalid code, etc.

Comments

@meetmangukiya
Copy link

Example code:

#![feature(stmt_expr_attributes)]
fn main() {
    let some_function_call = || {};

    let filter = || {
        (
            // comment
            #[allow(clippy::disallowed_methods)]
            some_function_call()
        )
    };
}

Everytime you format it it replicates the attribute and doubles it:

#![feature(stmt_expr_attributes)]
fn main() {
    let some_function_call = || {};

    let filter = || {
        (
            // comment
            #[allow(clippy::disallowed_methods)]
            #[allow(clippy::disallowed_methods)]
            some_function_call()
        )
    };
}

Version: rustfmt 1.6.0-nightly (39f42ad9 2023-07-19)

@ytmimi
Copy link
Contributor

ytmimi commented Aug 1, 2023

Thanks for the report!

Confirming that I can reproduce this with rustfmt 1.6.0-nightly (a9ae7462 2023-07-19). I don't have time to look into the details right now, but I'll follow up once I've had a chance to dig into this.

@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. a-comments labels Aug 1, 2023
@ytmimi
Copy link
Contributor

ytmimi commented Aug 1, 2023

The input without the parens doesn't seem to have the issue so wrapping the call in parens seems to be trigging this issue.

#![feature(stmt_expr_attributes)]
fn main() {
    let some_function_call = || {};

    let filter = || {
        // comment
        #[allow(clippy::disallowed_methods)]
        some_function_call()
    };
}

GambitingMan added a commit to GambitingMan/rustfmt that referenced this issue Sep 16, 2023
calebcartwright added a commit that referenced this issue Sep 20, 2023
* Fix #5871

* Only idempotence test is necessary

* Update src/expr.rs

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

---------

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants