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

error[internal]: left behind trailing whitespace, preventing all formatting #6428

Closed
Paladynee opened this issue Jan 1, 2025 · 1 comment
Labels
a-binop a-comments e-trailing whitespace error[internal]: left behind trailing whitespace

Comments

@Paladynee
Copy link

Paladynee commented Jan 1, 2025

fn rustfmt_internal_error() {
    if true 
    // comment
        || false
    {}
}
error[internal]: left behind trailing whitespace
   --> \\?\C:\Users\eurydice\Desktop\folders\osumapchecker\src\test.rs:108:108:12
    |
108 |     if true
    |            ^
    |

warning: rustfmt has failed to format. See previous 1 errors.

There must be a space after true, and the comment needs to be on a newline.

I discovered this while writing the safety document on an unsafe function called on || control flow:

fn r#match(&mut self, expected: u8) -> bool {
    if self.is_at_end() 
        // Safety: control flow of the `||` operator guarantees that we are not at the end
        || unsafe { *self.source.get_unchecked(self.index) } != expected
    {
        false
    } else {
        self.index += 1;
        true
    }
}

so it is pretty elementary.

@ytmimi
Copy link
Contributor

ytmimi commented Jan 2, 2025

rustfmt doesn't handle comments between binary operators well, and won't format binary expression that contain comments (See #3591). The left behind trailing whitespace message you're seeing means there's trailing whitespace in the source code that rustfmt can't remove.

@ytmimi ytmimi closed this as completed Jan 2, 2025
@ytmimi ytmimi added a-comments a-binop e-trailing whitespace error[internal]: left behind trailing whitespace labels Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-binop a-comments e-trailing whitespace error[internal]: left behind trailing whitespace
Projects
None yet
Development

No branches or pull requests

2 participants