Skip to content

SourceAnnotation range (137, 138) is bigger than source length 124 #6516

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

Closed
Swiftie13st opened this issue Mar 20, 2025 · 4 comments
Closed
Labels
duplicate needs-mcve needs a Minimal Complete and Verifiable Example

Comments

@Swiftie13st
Copy link

Swiftie13st commented Mar 20, 2025

Panic when exec cargo fmt

thread 'main' panicked at /rust/deps/annotate-snippets-0.9.2/src/display_list/from_snippet.rs:275:9:
SourceAnnotation range `(137, 138)` is bigger than source length `124`
stack backtrace:
   0:        0x10cc9aee4 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6e25c13836847e70
   1:        0x10a4a1cb4 - core::fmt::write::h37cdb50ab8af3d55
   2:        0x10cc8eec4 - std::io::Write::write_fmt::hd4c273f34c4c0a33
   3:        0x10cc9ada4 - std::sys::backtrace::BacktraceLock::print::h1df7364dde63dc75
   4:        0x10cc9d2d0 - std::panicking::default_hook::{{closure}}::h646e398272c5759a
   5:        0x10cc9d0cc - std::panicking::default_hook::hf65fd28e95db7176
   6:        0x10af0ca9c - std[aa188197e8159e73]::panicking::update_hook::<alloc[9f1bd423a4adc305]::boxed::Box<rustc_driver_impl[e63c773a3409b95a]::install_ice_hook::{closure#1}>>::{closure#0}
   7:        0x10cc9dcf8 - std::panicking::rust_panic_with_hook::hc9e2ec2a12b10e12
   8:        0x10cc9d864 - std::panicking::begin_panic_handler::{{closure}}::h3b6449e2eb83bf4c
   9:        0x10cc9b374 - std::sys::backtrace::__rust_end_short_backtrace::h38d85099ddd107a3
  10:        0x10cc9d528 - _rust_begin_unwind
  11:        0x10f36bac4 - core::panicking::panic_fmt::hd4003258f6ab7b29
  12:        0x100c8d74c - <annotate_snippets[3077853116046083]::display_list::structs::DisplayList as core[fdda186248748d6b]::convert::From<annotate_snippets[3077853116046083]::snippet::Snippet>>::from
  13:        0x100b23a90 - <rustfmt_nightly[41d7da3084c6412f]::format_report_formatter::FormatReportFormatter as core[fdda186248748d6b]::fmt::Display>::fmt
  14:        0x10a4a1cb4 - core::fmt::write::h37cdb50ab8af3d55
  15:        0x10cc8d128 - <&std::io::stdio::Stderr as std::io::Write>::write_fmt::hce344aed64ff222a
  16:        0x10cc8dc00 - std::io::stdio::_eprint::hc45f0fb6947c71c9
  17:        0x100a4a624 - rustfmt[21f995291d81ceb8]::format_and_emit_report::<std[aa188197e8159e73]::io::stdio::Stdout>
  18:        0x100a49508 - rustfmt[21f995291d81ceb8]::execute
  19:        0x100a458ac - rustfmt[21f995291d81ceb8]::main
  20:        0x100a3c354 - std[aa188197e8159e73]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  21:        0x100a3c72c - std[aa188197e8159e73]::rt::lang_start::<()>::{closure#0}
  22:        0x10cc804b4 - std::rt::lang_start_internal::h5f91760815528aa2
  23:        0x100a4b448 - _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.85.0 (4d91de4e4 2025-02-17) running on aarch64-apple-darwin

query stack during panic:
end of query stack

After a period of exploration, I found that the following code is the main cause. I can't show the source code directly, so

async fn foo(a: &str, b: &str) -> hyper::body::Bytes {
    //some commment
    let res = /* comment but with an extra space in the back, I use '_' to refer */_
        if !a.is_empty() {
            bar()
        } else {
            bar()
        };

    http(res).await
}


when I del the extra space (right after the '*/'), and fix it.

Hope the above provides enough information to help the troubleshoot.

@ytmimi
Copy link
Contributor

ytmimi commented Mar 20, 2025

Thanks for the report. I'm unable to reproduce the error with the snippet you gave me (replacing the trailing _ with a space).

async fn foo(a: &str, b: &str) -> hyper::body::Bytes {
    //some commment
    let res = /* comment but with an extra space in the back, I use '_' to refer */ 
        if !a.is_empty() {
            bar()
        } else {
            bar()
        };

    http(res).await
}

Any chance that the comment in the original source code had any multi-byte unicode characters or tabs?

@ytmimi ytmimi added the needs-mcve needs a Minimal Complete and Verifiable Example label Mar 20, 2025
@ytmimi
Copy link
Contributor

ytmimi commented Mar 20, 2025

Also, are you using any non-default configuration options when running rustfmt?

@Swiftie13st
Copy link
Author

@ytmimi

Also, are you using any non-default configuration options when running rustfmt?

Didn't change any config, just run cargo fmt. Also using the RustRover right click Reformat File with Rustfmt will resolve the same panic.

Any chance that the comment in the original source code had any multi-byte unicode characters or tabs?

The comment has some Chinese characters.
Like this:

 /* if A || B -- some Chinese comment */ 

@ytmimi
Copy link
Contributor

ytmimi commented Mar 21, 2025

Yep, it's definitely the Chinese characters that's causing the issue here. Pretty sure this is a duplicate of #6083, which was using Cyrillic characters. That issue is fixed in source, but not yet released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate needs-mcve needs a Minimal Complete and Verifiable Example
Projects
None yet
Development

No branches or pull requests

2 participants