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 in let statement prevents formatting #5590

Open
mfurak opened this issue Nov 5, 2022 · 1 comment
Open

comment in let statement prevents formatting #5590

mfurak opened this issue Nov 5, 2022 · 1 comment

Comments

@mfurak
Copy link

mfurak commented Nov 5, 2022

When running the rustfmt on a line that contains a block comment, the lines doesn't get formatted at all. My expectation is that the line gets formatted correctly as if the comment block wasn't there.
rustfmt version: rustfmt 1.5.1-stable
Test case:

fn main() {
    let tup = (1, 2);
    let (first,         second)/* your pattern here */ = tup;
}

Expectation:

fn main() {
    let tup = (1, 2);
    let (first, second)/* your pattern here */ = tup;
}

Actual:

fn main() {
    let tup = (1, 2);
    let (first,         second)/* your pattern here */ = tup;
}
@ytmimi
Copy link
Contributor

ytmimi commented Nov 5, 2022

Thanks for reaching out!

rustfmt doesn't currently handle comments between the pattern and the = in let statements, and out of an abundance of caution doesn't reformat the let statement because doing so would result in losing the comment. For now I'd encourage you not to place comments in that position.

let statements are represented by ast::Local AST nodes, and for anyone interested in working on this you should look into the Rewrite impl for ast::Local

@ytmimi ytmimi changed the title Line containing a comment block does not get formatted comment in let statement prevents formatting Nov 5, 2022
@ytmimi ytmimi added the p-low label Nov 5, 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

2 participants