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

Configuration option request: don't reindent comments #4030

Closed
carols10cents opened this issue Jan 24, 2020 · 3 comments
Closed

Configuration option request: don't reindent comments #4030

carols10cents opened this issue Jan 24, 2020 · 3 comments

Comments

@carols10cents
Copy link
Member

There are cases where personal comment placement style might differ from the rustfmt style, and it'd be nice to be able to choose, but I don't see an option about aligning/reindenting/moving comments around or not.

I don't know that my issues here are bugs necessarily, because I could see what rustfmt is doing being the right thing in other situations. 🤷‍♀

This might be a duplicate of #763 but this comment says comments are skipped by default, but that's not what I'm seeing...? Perhaps that issue means something different than I do by "formatting comments".

Examples:

rustfmt 1.4.11-nightly (2019-12-03 1838235)

fn main() {
    {              // I would like to talk about this scope
        let x = 3; // and continue the comment here
    }              // and even down here
    // but here is a different topic that I don't want aligned
}

rustfmt changes this into:

fn main() {
    {
        // I would like to talk about this scope
        let x = 3; // and continue the comment here
    } // and even down here
      // but here is a different topic that I don't want aligned
}

Possibly related issues that might not be bugs that could instead be dealt with by turning off comment moving/formatting:

@phi-gamma
Copy link

Seconding the issue. With Rust 1.45 and cargo +stable fmt
rustfmt produces nonsensical indentation like this:

+            }

-//          eprintln!("ClientOpts: invoking client using opts=[{:?}] ⇒ argv=[{:?}]",
-//                    self, argv);
+            //          eprintln!("ClientOpts: invoking client using opts=[{:?}] ⇒ argv=[{:?}]",
+            //                    self, argv);

             Client::run_with_argv(&argv, &prefix)

and damages comments like this:

 /** A status code used with all API functions. Further results
-    have to be transported as out parameters. */
+have to be transported as out parameters. */
 #[repr(C)]
 #[allow(non_camel_case_types)]
 #[derive(PartialEq, Debug, Clone, Copy)]
 pub enum APX_status {

Adorning all comments with skip attributes isn’t a workable solution.

It would be great if there was at least a way to indicate to rustfmt that it
should leave comments alone. Even better if it were possible to teach it the
commenting style of a given project.

@georgefst
Copy link

#4108 is similar, and points out that this is inconsistent with rustfmt's apparent decision to stick to block based indentation.

This is annoying for me mostly because of the interaction with version control. For example, adding one value to an enum can cause the entire declaration to become part of a diff.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 26, 2022

Closing this as a duplicate of #1264

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2022
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

4 participants