Skip to content

Undesired reformatting of comments applying to array elements. #6497

Open
@anforowicz

Description

@anforowicz

REPRO:

$ cat fmt-comment-trouble.rs
const RLIB_CRATE_TYPES: [&str; 2] = [
    // https://doc.rust-lang.org/nightly/reference/linkage.html#r-link.lib
    // says:
    //
    //     > The purpose of this generic lib option is to generate
    //     > the “compiler recommended” style of library.
    //
    // For us this means `Rlib`.
    "lib",
    // Naturally "rlib" maps to `LibType::Rlib`.
    "rlib",
];


lukasza2 in /usr/local/google/home/lukasza/scratch
$ rustfmt --version
rustfmt 1.8.0-nightly (3ea711f17e 2025-03-09)

lukasza2 in /usr/local/google/home/lukasza/scratch
$ rustfmt fmt-comment-trouble.rs
Warning: the `fn_args_layout` option is deprecated. Use `fn_params_layout`. instead
Warning: the `version` option is deprecated. Use `style_edition` instead.

lukasza2 in /usr/local/google/home/lukasza/scratch
$ cat fmt-comment-trouble.rs
const RLIB_CRATE_TYPES: [&str; 2] = [
    // https://doc.rust-lang.org/nightly/reference/linkage.html#r-link.lib
    // says:
    //
    //     > The purpose of this generic lib option is to generate
    //     > the “compiler recommended” style of library.
    //
    // For us this means `Rlib`.
    "lib", // Naturally "rlib" maps to `LibType::Rlib`.
    "rlib",
];

EXPECTED BEHAVIOR: // Naturally "rlib" maps to LibType::Rlib. stays below "lib" and above "rlibs".

ACTUAL BEHAVIOR: The comment is no longer on a separate line - the comment got transformed into a trailing comment that seems to apply to "lib" rather than to "rlib".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions