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

Undesired reformatting of comments applying to array elements. #6497

Open
anforowicz opened this issue Mar 10, 2025 · 1 comment
Open

Undesired reformatting of comments applying to array elements. #6497

anforowicz opened this issue Mar 10, 2025 · 1 comment

Comments

@anforowicz
Copy link
Contributor

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".

@ytmimi
Copy link
Contributor

ytmimi commented Mar 10, 2025

Thanks for the report. I'm fairly certain this is a duplicate, but I can't find the issue right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants