Closed
Description
Hi! I encountered this ICE while putting bad code into my compiler while learning FFI for the first time. It also reproduced on stable 1.45.2, with the different location:
thread 'rustc' panicked at 'index out of bounds: the len is 13 but the index is 25', /rustc/d3fb005a39e62501b8b0b356166e515ae24e2e54/src/librustc_hir/definitions.rs:347:9
Code
extern "C" {
fn lol() {
println!("hello world!");
// whoops, forgot to close my function block
}
Meta
rustc --version --verbose
:
dev/nix-doc - [main●] » rustc --version --verbose
rustc 1.47.0-nightly (6c8927b0c 2020-07-26)
binary: rustc
commit-hash: 6c8927b0cf80ceee19386026cf9d7fd4fd9d486f
commit-date: 2020-07-26
host: x86_64-unknown-linux-gnu
release: 1.47.0-nightly
LLVM version: 10.0
# STABLE
dev/nix-doc - [main●] » rustup run stable rustc --version --verbose
rustc 1.45.2 (d3fb005a3 2020-07-31)
binary: rustc
commit-hash: d3fb005a39e62501b8b0b356166e515ae24e2e54
commit-date: 2020-07-31
host: x86_64-unknown-linux-gnu
release: 1.45.2
LLVM version: 10.0
Error output
dev/nix-doc - [main●] » RUST_BACKTRACE=0 rustc -Zno-codegen ice-repro.rs
error: this file contains an unclosed delimiter
--> ice-repro.rs:4:3
|
1 | extern "C" {
| - unclosed delimiter
2 | fn lol() {
| - this delimiter might not be properly closed...
3 | println!("hello world!");
4 | }
| - ^
| |
| ...as it matches this but it has different indentation
error: incorrect function inside `extern` block
--> ice-repro.rs:2:8
|
1 | extern "C" {
| ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
2 | fn lol() {
| ________^^^___-
| | |
| | cannot have a body
3 | | println!("hello world!");
4 | | }
| |_- help: remove the invalid body: `;`
|
= help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
thread 'rustc' panicked at 'index out of bounds: the len is 13 but the index is 25', src/librustc_ast_lowering/lib.rs:577:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.47.0-nightly (6c8927b0c 2020-07-26) running on x86_64-unknown-linux-gnu
note: compiler flags: -Z no-codegen
error: aborting due to 2 previous errors
Backtrace
thread 'rustc' panicked at 'index out of bounds: the len is 13 but the index is 25', src/librustc_ast_lowering/lib.rs:577:29
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:78
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:59
4: core::fmt::write
at src/libcore/fmt/mod.rs:1117
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1508
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:198
9: std::panicking::default_hook
at src/libstd/panicking.rs:217
10: rustc_driver::report_ice
11: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:530
12: rust_begin_unwind
at src/libstd/panicking.rs:437
13: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
14: core::panicking::panic_bounds_check
at src/libcore/panicking.rs:62
15: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
16: rustc_ast_lowering::lower_crate
17: rustc_interface::passes::BoxedResolver::access::{{closure}}
18: rustc_interface::passes::configure_and_expand::{{closure}}
19: rustc_interface::passes::BoxedResolver::access
20: rustc_interface::queries::Queries::lower_to_hir
21: rustc_interface::queries::Queries::global_ctxt
22: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
23: rustc_span::with_source_map
24: rustc_interface::interface::create_compiler_and_run
25: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.