Skip to content

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

@TOETOE55

Description

@TOETOE55

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-commentsArea: commentsC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEonly-with-optionRequires a non-default option value to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions