Skip to content

Comments placed in-between a field and type in a struct get deleted after formatting #6551

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

Open
anarchvile opened this issue Apr 26, 2025 · 0 comments

Comments

@anarchvile
Copy link

System/Tool Info

  • Ubuntu 22.04.
  • Rust 2024 edition.
rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)
1.85.1-x86_64-unknown-linux-gnu
1.86.0-x86_64-unknown-linux-gnu (active)

cargo fmt --version
rustfmt 1.8.0-stable (05f9846f89 2025-03-31)

cargo --version
cargo 1.86.0 (adf9b6ad1 2025-02-28)

Repro Steps

I wrote the following snippet of code:

#[derive(Debug)]
struct MyCustomStruct {
    my_really_long_name_with_a_long_type:
        std::sync::Arc<std::sync::Mutex<std::collections::HashSet<String>>>,
}

If I try to add a comment here:

#[derive(Debug)]
struct MyCustomStruct {
    my_really_long_name_with_a_long_type:
    // A comment.
        std::sync::Arc<std::sync::Mutex<std::collections::HashSet<String>>>,
}

And then run cargo fmt, the comment gets deleted and the struct looks like the 1st code snippet again. Not sure whether or not it's expected...

Am happy to provide more details, and apologies if something has already been filed for this (skimming the open issues I saw a few similar, but not quite-the-same, items, but I may have just missed it)!

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

1 participant