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

version Two no longer able to format code #6157

Open
matthiaskrgr opened this issue May 4, 2024 · 5 comments
Open

version Two no longer able to format code #6157

matthiaskrgr opened this issue May 4, 2024 · 5 comments
Labels
a-comments duplicate e-trailing whitespace error[internal]: left behind trailing whitespace

Comments

@matthiaskrgr
Copy link
Member

fn f() {}

fn main() {
    f(0, 1,);        // f()
    //~^ error: this function takes 0 arguments but 2 arguments were supplied
}

with version = "Two"
it looks like rustfmt does no longer know that the comment on line 5 exists, it thus flags " " as

error[internal]: left behind trailing whitespace
 --> /tmp/im/a.rs:5:5:1
  |
5 |
  | ^^^^
  |

which it isnt because there is a comment after the indentation (unless it tries to remove the entire comment which is spooky as well)

@matthiaskrgr
Copy link
Member Author

rustfmt 1.7.0-nightly (d2d24e3 2024-05-03)

@calebcartwright
Copy link
Member

calebcartwright commented May 5, 2024

@ytmimi I want to highlight this one for discussion and review as I wonder if this may be related to the v2/2024 behavior that avoids trailing comment alignment and I want to ensure we don't have any known bugs there.

It appears to me as if rustfmt is, for whatever reason, attempting to capture the white space between the semi and the trailing comment and just dumping that whitespace on a newline. If this is some odd edge case then that's a bit better, but hopefully not a source of concern for the 2024 style edition

@ytmimi
Copy link
Contributor

ytmimi commented May 6, 2024

When I run cargo run --bin rustfmt on the latest commit d5f1200 this is what I get.

Input:

fn main() {
    f(0, 1,);        // f()
    //~^ error: this function takes 0 arguments but 2 arguments were supplied
}

Output:

fn main() {
    f(0, 1); // f()
    
    //~^ error: this function takes 0 arguments but 2 arguments were supplied
}

A little odd to me that we're adding an indented newline between the comments.

@ytmimi
Copy link
Contributor

ytmimi commented May 6, 2024

@calebcartwright I think this might have more to do with how we handle CommentStyle::Custom comments. The following input isn't formatted strangely.

input

fn main() {
    f(0, 1,);        // f()
    // ~^ error: this function takes 0 arguments but 2 arguments were supplied
}

output

fn main() {
    f(0, 1); // f()
    // ~^ error: this function takes 0 arguments but 2 arguments were supplied
}

@ytmimi
Copy link
Contributor

ytmimi commented May 6, 2024

@calebcartwright @matthiaskrgr looking through the issue tracker this seems like a duplicate of #5391 and #5868

@ytmimi ytmimi added duplicate a-comments e-trailing whitespace error[internal]: left behind trailing whitespace labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments duplicate e-trailing whitespace error[internal]: left behind trailing whitespace
Projects
None yet
Development

No branches or pull requests

3 participants