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

Comment before } else { is incorrectly indented #1737

Closed
ghost opened this issue Jun 21, 2017 · 3 comments
Closed

Comment before } else { is incorrectly indented #1737

ghost opened this issue Jun 21, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 21, 2017

Code:

fn main() {
    if true {
        // Create a guard.
        let guard = create_guard();
        // The guard goes out of scope.
    } else {
    }
}

After rustfmt:

fn main() {
    if true {
        // Create a guard.
        let guard = create_guard();
    // The guard goes out of scope.
    } else {
    }
}

Perhaps all lines within blocks (even comments) should always be indented more than the lines with block boundaries?

@topecongiro
Copy link
Contributor

This is intended behavior (cc #1575, #1619).
You can set format_if_else_cond_comment to false to indent the comment.

@ghost ghost closed this as completed Jun 21, 2017
@ghost
Copy link
Author

ghost commented Jun 23, 2017

@topecongiro Would it make sense for rustfmt to simply leave indentation of such comments intact?

To illustrate, I'm suggesting that rustfmt formats the following:

if true {
    foo();
        // a
} else if true {
    bar();
    // b
} else  if true {
    baz();
// c
} else {
    quux();
}

Into this:

if true {
    foo();
// a
} else if true {
    bar();
    // b
} else  if true {
    baz();
// c
} else {
    quux();
}

That strategy would do the right thing in almost all cases.

@sphynx
Copy link
Contributor

sphynx commented May 6, 2019

You can set format_if_else_cond_comment to false to indent the comment.

It looks like this option has been removed from rustfmt and now there is no way to override this behaviour.

This issue was closed.
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

3 participants