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

Comment before a list element is changed to an end-of-line comment for a different element #6132

Open
Zalathar opened this issue Mar 31, 2024 · 2 comments

Comments

@Zalathar
Copy link

Zalathar commented Mar 31, 2024

(playground link)

Input:

fn hello() {
    let _slice = &[
        // First item
        0x0001,

        // Second item
        0x0002,
    ];
    two_arg_fn(
        // First arg
        1,
        
        // Second arg
        2,
    );
}

fn two_arg_fn(_x: u32, _y: u32) {}

Output:

fn hello() {
    let _slice = &[
        // First item
        0x0001, // Second item
        0x0002,
    ];
    two_arg_fn(
        // First arg
        1, // Second arg
        2,
    );
}

fn two_arg_fn(_x: u32, _y: u32) {}

Here the intent was to have a comment associated with the element on the following line, but rustfmt confusingly turned the comment for the second element into an end-of-line comment for the first element.


$ rustfmt --version
rustfmt 1.7.0-stable (7cf61ebd 2024-03-27)
@ytmimi
Copy link
Contributor

ytmimi commented Apr 1, 2024

@Zalathar Thanks for the report. I believe this is related to / is a duplicate of #4108.

@Zalathar
Copy link
Author

Zalathar commented Apr 1, 2024

@Zalathar Thanks for the report. I believe this is related to / is a duplicate of #4108.

It's definitely not a duplicate of that issue, and to me it seems only very loosely related.

  • That issue is about how rustfmt chooses to align end-of-line comments relative to each other.
  • This issue is about rustfmt changing separate-line comments into end-of-line comments in a misleading way.

(There's a good chance it's a duplicate of something, but I couldn't find anything relevant in my searches.)

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

2 participants