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

Panic with wrap_comments and non-ascii character at comment wrap boundary #5023

Closed
TOETOE55 opened this issue Oct 13, 2021 · 1 comment · Fixed by #5089
Closed

Panic with wrap_comments and non-ascii character at comment wrap boundary #5023

TOETOE55 opened this issue Oct 13, 2021 · 1 comment · Fixed by #5089
Labels
a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce

Comments

@TOETOE55
Copy link

TOETOE55 commented Oct 13, 2021

There is a piece of code in my project like:

fn main() {
    if xxx {
        let xxx = xxx
            .into_iter()
            .filter(|(xxx, xxx)| {
                if let Some(x) = Some(1) {
                    // xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
                    // xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
                    // 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
                    if false {
                        return true;
                    }
                }
                false
            })
            .collect();
    }
}

When I execute cargo fmt, I got an error:

thread 'main' panicked at 'index out of bounds: the len is 48 but the index is 18446744073709551615', src/tools/rustfmt/src/string.rs:285:27
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The rustfmt.toml is the following:

wrap_comments = true

I can't understand why a few lines of comments can make fmt crash...

@TOETOE55 TOETOE55 changed the title A few line of comments make cargo fmt panic A few lines of comments make cargo fmt panic Oct 13, 2021
@calebcartwright
Copy link
Member

calebcartwright commented Oct 14, 2021

It's not related to having comments nor the quantity of lines of comments, but the fact that there's a non-ascii char at a comment line boundary.

Do you have wrap_comments enabled and/or any other non-default config options set?

(Edit - i see you do have wrap_comments enabled, missed that on the first read!)

@calebcartwright calebcartwright changed the title A few lines of comments make cargo fmt panic Panic with wrap_comments and non-ascii character at comment wrap boundary Oct 14, 2021
@calebcartwright calebcartwright added a-comments only-with-option requires a non-default option value to reproduce bug Panic, non-idempotency, invalid code, etc. labels Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants