Crash in parse_snippet
phansch opened this issue · 0 comments
phansch commented
While working on rust-lang/rust#59398 I encountered this crash where rustfix crashes on retrieving the suggestions:
Expand backtrace
thread 'everything' panicked at 'byte index 2 is out of bounds of `}`', src/libcore/str/mod.rs:2010:9
stack backtrace:
0: 0x564b396bb7d3 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h3ea4e797e65a328d
at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
1: 0x564b396b757b - std::sys_common::backtrace::_print::hf58574b7d5a741ab
at src/libstd/sys_common/backtrace.rs:71
2: 0x564b396ba476 - std::panicking::default_hook::{{closure}}::hed8b316a41353ca9
at src/libstd/sys_common/backtrace.rs:59
at src/libstd/panicking.rs:197
3: 0x564b396ba19e - std::panicking::default_hook::h8f4ba314e61c5eff
at src/libstd/panicking.rs:208
4: 0x564b396bab7f - std::panicking::rust_panic_with_hook::hde5d2bfa491b5add
at src/libstd/panicking.rs:474
5: 0x564b396ba701 - std::panicking::continue_panic_fmt::h928c357471014704
at src/libstd/panicking.rs:381
6: 0x564b396ba5e5 - rust_begin_unwind
at src/libstd/panicking.rs:308
7: 0x564b396d5d3c - core::panicking::panic_fmt::h5ab350f3b9a2b236
at src/libcore/panicking.rs:85
8: 0x564b396d75cf - core::str::slice_error_fail::h8551c49db625e656
at src/libcore/str/mod.rs:0
9: 0x564b3948ea8f - core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index::{{closure}}::h2b84c086
6fdd5130
at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/libcore/str/mod.rs:1751
10: 0x564b394938af - core::option::Option<T>::unwrap_or_else::he9ebd301cf0dbcdb
at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/libcore/option.rs:386
11: 0x564b39492f25 - core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index::ha86fa6cbfda6a990
at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/libcore/str/mod.rs:1751
12: 0x564b3948ec10 - core::str::traits::<impl core::ops::index::Index<I> for str>::index::h12989e8413e52b49
at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/libcore/str/mod.rs:1616
13: 0x564b3943eb20 - <alloc::string::String as core::ops::index::Index<core::ops::range::Range<usize>>>::index::hc28f4c5a88ab385d
at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/liballoc/string.rs:1953
14: 0x564b3944a30b - rustfix::parse_snippet::h40fa32a6f9ed0564
at src/lib.rs:120
15: 0x564b393a816f - rustfix::collect_suggestions::{{closure}}::h396f64ade2bb2873
at /home/phansch/code/rustfix/src/lib.rs:166
Minimal repro:
fn main() {
"""; //~ ERROR unterminated double quote
}
Rusts error message looks like this:
error: unterminated double quote string
--> $DIR/tab_2.rs:4:7
|
LL | """;
| ___________________^
LL | | }
| |__^
error: aborting due to previous error
I'm not sure if it's worth investigating because this particular error doesn't provide a suggestion.
The DiagnosticSpan
looks like this:
DiagnosticSpan {
file_name: "./tests/everything/tab_2.rs",
byte_start: 485,
byte_end: 526,
line_start: 12,
line_end: 13,
column_start: 7,
column_end: 3,
is_primary: true,
text: [
DiagnosticSpanLine {
text: " \"\"\"; //~ ERROR unterminated double quote",
highlight_start: 7,
highlight_end: 45
},
DiagnosticSpanLine {
text: "}",
highlight_start: 1,
highlight_end: 3
}
],
label: None,
suggested_replacement: None,
suggestion_applicability: None,
expansion: None
}
The second DiagnosticSpanLine
causes the crash in parse_snippet
.