rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
5.95k stars 874 forks source link

panic: `byte index 48 is not a char boundary; it is inside '\u{2029}` #5739

Open langston-barrett opened 1 year ago

langston-barrett commented 1 year ago

This is a fuzzer-generated testcase, please feel free to close and/or let me know if it's not helpful!

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2daf6f1fef79c417c0c9ad35e79d21ad


// compile-flags: -Z dump-mir-spanview=block



thread 'main' panicked at 'byte index 48 is not a char boundary; it is inside '\u{2029}' (bytes 47..50) of `// compile-flags: -Z dump-mir-spanview=block



`', src/tools/rustfmt/src/missed_spans.rs:215:29
stack backtrace:
   0: rust_begin_unwind
             at /rustc/2eaeb1eee1b21772de8b935236d16ff8e03fdcf5/library/std/src/panicking.rs:577:5
   1: core::panicking::panic_fmt
             at /rustc/2eaeb1eee1b21772de8b935236d16ff8e03fdcf5/library/core/src/panicking.rs:67:14
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
             at /rustc/2eaeb1eee1b21772de8b935236d16ff8e03fdcf5/library/core/src/str/mod.rs:86:9
   4: <rustfmt_nightly::visitor::FmtVisitor>::format_missing_indent
   5: rustfmt_nightly::formatting::format_project::<rustfmt_nightly::Session<std::io::stdio::Stdout>>
   6: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::with::<<rustfmt_nightly::Session<std::io::stdio::Stdout>>::format_input_inner::{closure#0}, core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>>
   7: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_span::create_session_if_not_set_then<core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>, <rustfmt_nightly::Session<std::io::stdio::Stdout>>::format_input_inner::{closure#0}>::{closure#0}, core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>>
   8: <rustfmt_nightly::Session<std::io::stdio::Stdout>>::format
   9: rustfmt::format_and_emit_report::<std::io::stdio::Stdout>
  10: <rustfmt_nightly::Session<std::io::stdio::Stdout>>::override_config::<rustfmt::format::{closure#0}, ()>
  11: rustfmt::execute
  12: rustfmt::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
ytmimi commented 1 year ago

@langston-barrett Thanks for the report! I think this is helpful 😁

Just so it's a little clearer for anyone else looking at this, the input snippet is:

// compile-flags: -Z dump-mir-spanview=block\n\n\n\u{2029}\n

and we're failing because of the paragraph separator (\u{2029})