Skip to content

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

Open
@Zalathar

Description

@Zalathar

(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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions