Skip to content

thread 'main' panicked at 'SourceAnnotation range (58, 60) is bigger than source length 58' #5888

Closed as not planned
@arifd

Description

@arifd

this fn:

pub(crate) fn sanity_needs_ocr<T: HasWord + HasRect>(collection: &[T]) -> bool {
    let needs_ocr = collection.is_empty()
    // the presence of 'UNICODE REPLACEMENT CHARACTER'
    || collection.iter().any(|c| c.text().contains('�'))  
    // (yes, empty pages will also be OCR'd)
    || collection_is_void_of_text(collection)
    || is_gibberish(&collection.to_rendered_text());

    #[cfg(debug_assertions)]
    if needs_ocr {
        tracing::trace!(
            "sanity check failed, with text: {:?}",
            collection.to_rendered_text()
        );
    }

    needs_ocr
}

will cause this panic:

thread 'main' panicked at 'SourceAnnotation range `(58, 60)` is bigger than source length `58`', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/annotate-snippets-0.9.1/src/display_list/from_snippet.rs:286:9
stack backtrace:
   0:        0x105726ce0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3fbf720fbb1cb41b
   1:        0x105775a84 - core::fmt::write::h8ab6230d6f2a4204
   2:        0x10571cdbc - std::io::Write::write_fmt::h15ecdca1916a179e
   3:        0x105726b34 - std::sys_common::backtrace::print::hb6e94bab886a9ccf
   4:        0x105729598 - std::panicking::default_hook::{{closure}}::h4a0e30e90cb1c7bb
   5:        0x1057293a0 - std::panicking::default_hook::h0bb5bbf65ac7c64d
   6:        0x10dbe299c - rustc_driver_impl[732cfd3dd2e325d3]::install_ice_hook::{closure#0}
   7:        0x105729c4c - std::panicking::rust_panic_with_hook::h17facd9c53870157
   8:        0x105729a2c - std::panicking::begin_panic_handler::{{closure}}::h9eab8195c369d860
   9:        0x1057270c0 - std::sys_common::backtrace::__rust_end_short_backtrace::hce5f67454da3493d
  10:        0x1057297a0 - _rust_begin_unwind
  11:        0x1057a0a00 - core::panicking::panic_fmt::hc7e96873bfc1c7ba
  12:        0x104dfc1e0 - annotate_snippets[df16a5f80ce3f00b]::display_list::from_snippet::format_slice
  13:        0x104df9834 - <annotate_snippets[df16a5f80ce3f00b]::display_list::structs::DisplayList as core[d635094314abd71]::convert::From<annotate_snippets[df16a5f80ce3f00b]::snippet::Snippet>>::from
  14:        0x104c9f934 - <rustfmt_nightly[8e8f5e083afe373d]::format_report_formatter::FormatReportFormatter as core[d635094314abd71]::fmt::Display>::fmt
  15:        0x105775a84 - core::fmt::write::h8ab6230d6f2a4204
  16:        0x10571b1bc - <&std::io::stdio::Stderr as std::io::Write>::write_fmt::he681787e1cd27b2e
  17:        0x10571bbc4 - std::io::stdio::_eprint::h2b97df9945de12f7
  18:        0x104c536e8 - rustfmt[5d1e7ead7f8f506]::format_and_emit_report::<std[efadba9af302a35a]::io::stdio::Stdout>
  19:        0x104c439f8 - <rustfmt_nightly[8e8f5e083afe373d]::Session<std[efadba9af302a35a]::io::stdio::Stdout>>::override_config::<rustfmt[5d1e7ead7f8f506]::format::{closure#0}, ()>
  20:        0x104c52880 - rustfmt[5d1e7ead7f8f506]::execute
  21:        0x104c51354 - rustfmt[5d1e7ead7f8f506]::main
  22:        0x104c46c08 - std[efadba9af302a35a]::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  23:        0x104c46c20 - std[efadba9af302a35a]::rt::lang_start::<()>::{closure#0}
  24:        0x10570fdf8 - std::rt::lang_start_internal::h434fe84e11a92429
  25:        0x104c54130 - _main

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rustfmt/issues/new?labels=bug

note: rustc 1.71.0 (8ede3aae2 2023-07-12) running on aarch64-apple-darwin

query stack during panic:
end of query stack

to fix the panic:

pub(crate) fn sanity_needs_ocr<T: HasWord + HasRect>(collection: &[T]) -> bool {
     let needs_ocr = collection.is_empty()
     // the presence of 'UNICODE REPLACEMENT CHARACTER'
-    || collection.iter().any(|c| c.text().contains('�'))  
+    || collection.iter().any(|c| c.text().contains('�'))
     // (yes, empty pages will also be OCR'd)
     || collection_is_void_of_text(collection)
     || is_gibberish(&collection.to_rendered_text());

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.duplicatee-trailing whitespaceerror[internal]: left behind trailing whitespace

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions