Skip to content
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

ICE: index out of bounds: the len is 0 but the index is 0 in emitter.rs #100199

Closed
dvdsk opened this issue Aug 6, 2022 · 0 comments · Fixed by #100228
Closed

ICE: index out of bounds: the len is 0 but the index is 0 in emitter.rs #100199

dvdsk opened this issue Aug 6, 2022 · 0 comments · Fixed by #100228
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dvdsk
Copy link
Contributor

dvdsk commented Aug 6, 2022

I am still working on a minimal example however that takes a bit more time. I checked whether this is a duplicate but I would like have a second opinion before I continue as I have missed duplicates in the past :( . Once I have that I will minimize this further. I also would not mind taking a crack at fixing this one (I might need some mentor ship though).

Code

See this commit: dvdsk/dbstruct@744167d the ICE happens when running cargo test simple_impl.

<code>

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (affe0d3a0 2022-08-05)
binary: rustc
commit-hash: affe0d3a00e92fa7885e3f5d2c5073fde432d154
commit-date: 2022-08-05
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

Error output

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/rustc_errors/src/emitter.rs:2161:48
Backtrace

stack backtrace:
   0:     0x7fa09e86f9f0 - std::backtrace_rs::backtrace::libunwind::trace::h74f2a0cc6b6b0bc5
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7fa09e86f9f0 - std::backtrace_rs::backtrace::trace_unsynchronized::h06f3d1adbfc08eec
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa09e86f9f0 - std::sys_common::backtrace::_print_fmt::he5f15b7310953827
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fa09e86f9f0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0481eccec82d418c
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fa09e8cb3bc - core::fmt::write::h609cae14de3da602
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/core/src/fmt/mod.rs:1198:17
   5:     0x7fa09e860a35 - std::io::Write::write_fmt::h01e5a38c3656642d
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/io/mod.rs:1672:15
   6:     0x7fa09e8726d1 - std::sys_common::backtrace::_print::h7b5df4d8c3756e42
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fa09e8726d1 - std::sys_common::backtrace::print::h9d73a5d917f22346
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fa09e8726d1 - std::panicking::default_hook::{{closure}}::hcf9a8bcb350b3a14
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/panicking.rs:295:22
   9:     0x7fa09e87239e - std::panicking::default_hook::hfcc6873a008cb403
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/panicking.rs:314:9
  10:     0x7fa0a10eabe4 - rustc_driver[ca7fdc4c44e2051e]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fa09e872f06 - std::panicking::rust_panic_with_hook::h4a279a71d839a82c
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/panicking.rs:702:17
  12:     0x7fa09e872d57 - std::panicking::begin_panic_handler::{{closure}}::hdef87ce1687e2bad
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/panicking.rs:588:13
  13:     0x7fa09e86ff14 - std::sys_common::backtrace::__rust_end_short_backtrace::h8ecba80cf5d4bb38
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7fa09e872a82 - rust_begin_unwind
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/panicking.rs:584:5
  15:     0x7fa09e8c7e93 - core::panicking::panic_fmt::hba83f67c5144f30e
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/core/src/panicking.rs:142:14
  16:     0x7fa09e8c7dd2 - core::panicking::panic_bounds_check::h1cdec23f81d8a2a9
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/core/src/panicking.rs:84:5
  17:     0x7fa0a0df723d - <rustc_errors[7749712bdedc646d]::emitter::EmitterWriter>::draw_code_line
  18:     0x7fa0a0df3149 - <rustc_errors[7749712bdedc646d]::emitter::EmitterWriter as rustc_errors[7749712bdedc646d]::emitter::Emitter>::emit_diagnostic
  19:     0x7fa0a0ec4503 - <rustc_errors[7749712bdedc646d]::json::Diagnostic>::from_errors_diagnostic
  20:     0x7fa0a0ec3c2e - <rustc_errors[7749712bdedc646d]::json::JsonEmitter as rustc_errors[7749712bdedc646d]::emitter::Emitter>::emit_diagnostic
  21:     0x7fa09fb42db1 - <rustc_errors[7749712bdedc646d]::HandlerInner>::emit_diagnostic
  22:     0x7fa09fa830f1 - <rustc_errors[7749712bdedc646d]::Handler>::emit_diagnostic
  23:     0x7fa0a028a39d - <rustc_errors[7749712bdedc646d]::ErrorGuaranteed as rustc_errors[7749712bdedc646d]::diagnostic_builder::EmissionGuarantee>::diagnostic_builder_emit_producing_guarantee
  24:     0x7fa0a08f12d6 - <rustc_resolve[352a3d4039238523]::Resolver>::report_errors
  25:     0x7fa0a08d676b - <rustc_session[9f63a6f55f156fe5]::session::Session>::time::<(), <rustc_resolve[352a3d4039238523]::Resolver>::resolve_crate::{closure#0}>
  26:     0x7fa0a08d3517 - <rustc_interface[3d3dd0fc21522ad9]::passes::boxed_resolver::BoxedResolver>::access::<<rustc_interface[3d3dd0fc21522ad9]::queries::Queries>::expansion::{closure#0}::{closure#0}, core[ff7cb6048b1d9418]::result::Result<rustc_ast[34ae140d2240e6c3]::ast::Crate, rustc_errors[7749712bdedc646d]::ErrorGuaranteed>>
  27:     0x7fa0a08c524d - <rustc_interface[3d3dd0fc21522ad9]::queries::Queries>::expansion
  28:     0x7fa0a08c2a3d - <rustc_interface[3d3dd0fc21522ad9]::interface::Compiler>::enter::<rustc_driver[ca7fdc4c44e2051e]::run_compiler::{closure#1}::{closure#2}, core[ff7cb6048b1d9418]::result::Result<core[ff7cb6048b1d9418]::option::Option<rustc_interface[3d3dd0fc21522ad9]::queries::Linker>, rustc_errors[7749712bdedc646d]::ErrorGuaranteed>>
  29:     0x7fa0a08b65ca - rustc_span[b823e81b2ca00566]::with_source_map::<core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>, rustc_interface[3d3dd0fc21522ad9]::interface::create_compiler_and_run<core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>, rustc_driver[ca7fdc4c44e2051e]::run_compiler::{closure#1}>::{closure#1}>
  30:     0x7fa0a08b5fa0 - rustc_interface[3d3dd0fc21522ad9]::interface::create_compiler_and_run::<core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>, rustc_driver[ca7fdc4c44e2051e]::run_compiler::{closure#1}>
  31:     0x7fa0a08b4311 - <scoped_tls[1695127579464aca]::ScopedKey<rustc_span[b823e81b2ca00566]::SessionGlobals>>::set::<rustc_interface[3d3dd0fc21522ad9]::interface::run_compiler<core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>, rustc_driver[ca7fdc4c44e2051e]::run_compiler::{closure#1}>::{closure#0}, core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>>
  32:     0x7fa0a08b3fff - std[42edab32bc6d989e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[3d3dd0fc21522ad9]::util::run_in_thread_pool_with_globals<rustc_interface[3d3dd0fc21522ad9]::interface::run_compiler<core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>, rustc_driver[ca7fdc4c44e2051e]::run_compiler::{closure#1}>::{closure#0}, core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>>::{closure#0}, core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>>
  33:     0x7fa0a0f0d7d9 - <<std[42edab32bc6d989e]::thread::Builder>::spawn_unchecked_<rustc_interface[3d3dd0fc21522ad9]::util::run_in_thread_pool_with_globals<rustc_interface[3d3dd0fc21522ad9]::interface::run_compiler<core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>, rustc_driver[ca7fdc4c44e2051e]::run_compiler::{closure#1}>::{closure#0}, core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>>::{closure#0}, core[ff7cb6048b1d9418]::result::Result<(), rustc_errors[7749712bdedc646d]::ErrorGuaranteed>>::{closure#1} as core[ff7cb6048b1d9418]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x7fa09e87ced3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf47b126657473903
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/alloc/src/boxed.rs:1935:9
  35:     0x7fa09e87ced3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h674e0463c0783734
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/alloc/src/boxed.rs:1935:9
  36:     0x7fa09e87ced3 - std::sys::unix::thread::Thread::new::thread_start::ha7dc26e0bc2fdd91
                               at /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/library/std/src/sys/unix/thread.rs:108:17
  37:     0x7fa09e494b43 - <unknown>
  38:     0x7fa09e526a00 - <unknown>
  39:                0x0 - <unknown>

@dvdsk dvdsk added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2022
luqmana added a commit to luqmana/rust that referenced this issue Aug 7, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 8, 2022
Don't ICE while suggesting updating item path.

When an item isn't found, we may suggest an appropriate import to `use`. Along with that, we also suggest updating the path to work with the `use`. Unfortunately, if the code in question originates from a macro, the span used to indicate which part of the path needs updating may not be suitable and cause an ICE (*). Since, such code is not adjustable directly by the user without modifying the macro, just skip the suggestion in such cases.

(*) The ICE happens because the emitter want to indicate to the user what code to delete by referencing a certain span. But in this case, said span has `lo == hi == 0` which means it thinks it's a dummy span. Adding a space before the proc macro attribute is enough to stop it from ICE'ing but even then the suggestion doesn't really make any sense:
```
help: if you import `DataStore`, refer to it directly
  |
1 -  #[dbstruct::dbstruct]
1 +  #[dbstruct::dbstruct]
```

Since suggestions are best-effort, I just gated this one on `can_be_used_for_suggestions` which catches cases like this.

Fixes rust-lang#100199
@bors bors closed this as completed in fac84e8 Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant