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

nightly ICE: panicked at 'index out of bounds: the len is 0 but the index is 1', /checkout/src/liballoc/vec.rs:1564:14 #44021

Closed
zhendongsu opened this issue Aug 21, 2017 · 4 comments · Fixed by #44332
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

@zhendongsu
Copy link

The test also causes 1.18 and 1.19 to loop indefinitely.

$ rustc-nightly --version
rustc 1.21.0-nightly (8c303ed87 2017-08-20)
$ 
$ rustc-nightly tmp.rs
error: expected expression, found `}`
 --> tmp.rs:4:1
  |
4 | } 
  | ^

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.21.0-nightly (8c303ed87 2017-08-20) running on i686-unknown-linux-gnu

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 1', /checkout/src/liballoc/vec.rs:1564:14
note: Run with `RUST_BACKTRACE=1` for a backtrace.

$ 
$ cat tmp.rs
impl Struct
{ 
  fn static_meth_struct () -> Struct {|} 
} 
$ 
@zhendongsu
Copy link
Author

$ RUST_BACKTRACE=1 rustc-nightly tmp.rs
error: expected expression, found `}`
 --> tmp.rs:4:1
  |
4 | }
  | ^

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.21.0-nightly (8c303ed87 2017-08-20) running on i686-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 1', /checkout/src/liballoc/vec.rs:1564:14
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:611
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:572
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::panicking::panic_bounds_check
             at /checkout/src/libcore/panicking.rs:58
  10: syntax::parse::parser::Parser::parse_impl_item
  11: syntax::parse::parser::Parser::parse_item_impl
  12: syntax::parse::parser::Parser::parse_item_
  13: syntax::parse::parser::Parser::parse_item
  14: syntax::parse::parser::Parser::parse_mod_items
  15: syntax::parse::parser::Parser::parse_crate_mod
  16: syntax::parse::parse_crate_from_file
  17: rustc_driver::driver::phase_1_parse_input::{{closure}}
  18: rustc_driver::driver::phase_1_parse_input
  19: rustc_driver::driver::compile_input
  20: rustc_driver::run_compiler

$

@arielb1
Copy link
Contributor

arielb1 commented Aug 21, 2017

With more line numbers:

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 1', /home/ariel/Rust/rust/src/liballoc/vec.rs:1564:14
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /home/ariel/Rust/rust/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /home/ariel/Rust/rust/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /home/ariel/Rust/rust/src/libstd/sys_common/backtrace.rs:60
             at /home/ariel/Rust/rust/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /home/ariel/Rust/rust/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /home/ariel/Rust/rust/src/libstd/panicking.rs:611
   5: std::panicking::begin_panic
             at /home/ariel/Rust/rust/src/libstd/panicking.rs:572
   6: std::panicking::begin_panic_fmt
             at /home/ariel/Rust/rust/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /home/ariel/Rust/rust/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /home/ariel/Rust/rust/src/libcore/panicking.rs:71
   9: core::panicking::panic_bounds_check
             at /home/ariel/Rust/rust/src/libcore/panicking.rs:58
  10: syntax::parse::parser::Parser::parse_impl_item
             at /home/ariel/Rust/rust/src/liballoc/vec.rs:1564
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:6102
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:4760
  11: syntax::parse::parser::Parser::parse_item_impl
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:5016
  12: syntax::parse::parser::Parser::parse_item_
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:5954
  13: syntax::parse::parser::Parser::parse_item
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:6125
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:6098
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:6124
  14: syntax::parse::parser::Parser::parse_mod_items
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:5267
  15: syntax::parse::parser::Parser::parse_crate_mod
             at /home/ariel/Rust/rust/src/libsyntax/parse/parser.rs:6236
  16: syntax::parse::parse_crate_from_file
             at /home/ariel/Rust/rust/src/libsyntax/parse/mod.rs:101
  17: rustc_driver::driver::phase_1_parse_input::{{closure}}
             at /home/ariel/Rust/rust/src/librustc_driver/driver.rs:543
  18: rustc_driver::driver::phase_1_parse_input
             at /home/ariel/Rust/rust/src/librustc/util/common.rs:48
             at /home/ariel/Rust/rust/src/librustc_driver/driver.rs:540
  19: rustc_driver::driver::compile_input
             at /home/ariel/Rust/rust/src/librustc_driver/driver.rs:112
  20: rustc_driver::run_compiler
             at /home/ariel/Rust/rust/src/librustc_driver/lib.rs:316

@Mark-Simulacrum Mark-Simulacrum 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 22, 2017
@tirr-c
Copy link
Contributor

tirr-c commented Sep 5, 2017

After investigating the parser, I found out it panicked after trying to parse closure argument list.

impl Struct
{
  fn static_meth_struct () -> Struct {|x, y} // incomplete argument list
}
error: expected expression, found `}`
 --> src/lib.rs:7:1
  |
7 | }
  | ^

error: internal compiler error: unexpected panic

On stable(1.20.0), the compiler falls into the infinite loop.


parse_fn_block_decl incorrectly consumes (or, discards) } if matching | does not exist, because it assumes that | follows directly after the argument list.

@tirr-c
Copy link
Contributor

tirr-c commented Sep 5, 2017

I'm trying to fix this. expect instead of bump might help?

frewsxcv added a commit to frewsxcv/rust that referenced this issue Sep 9, 2017
Expect pipe symbol after closure parameter list

Fixes rust-lang#44021.

---

Originally, the parser just called `bump` to discard following token after parsing closure parameter list, because it assumes `|` is following. However, the following code breaks the assumption:

```rust
struct MyStruct;
impl MyStruct {
   fn f() {|x, y}
}
```

Here, the parameter list is `x, y` and the following token is `}`. The parser discards `}`, and then we have a curly bracket mismatch.

Indeed, this code has a syntax error. On current nightly, the compiler emits an syntax error, but with incorrect message and span, followed by an ICE.

```
error: expected expression, found `}`
 --> 44021.rs:4:1
  |
4 | }
  | ^

error: internal compiler error: unexpected panic
```

Even worse, on current stable(1.20.0), the compiler falls into an infinite loop.

This pull request fixes this problem. Now the compiler emits correct error message and span, and does not ICE.

```
error: expected one of `:`, `@`, or `|`, found `}`
 --> 44021.rs:3:20
  |
3 |     fn foo() {|x, y}
  |                    ^ expected one of `:`, `@`, or `|` here
```
frewsxcv added a commit to frewsxcv/rust that referenced this issue Sep 9, 2017
Expect pipe symbol after closure parameter list

Fixes rust-lang#44021.

---

Originally, the parser just called `bump` to discard following token after parsing closure parameter list, because it assumes `|` is following. However, the following code breaks the assumption:

```rust
struct MyStruct;
impl MyStruct {
   fn f() {|x, y}
}
```

Here, the parameter list is `x, y` and the following token is `}`. The parser discards `}`, and then we have a curly bracket mismatch.

Indeed, this code has a syntax error. On current nightly, the compiler emits an syntax error, but with incorrect message and span, followed by an ICE.

```
error: expected expression, found `}`
 --> 44021.rs:4:1
  |
4 | }
  | ^

error: internal compiler error: unexpected panic
```

Even worse, on current stable(1.20.0), the compiler falls into an infinite loop.

This pull request fixes this problem. Now the compiler emits correct error message and span, and does not ICE.

```
error: expected one of `:`, `@`, or `|`, found `}`
 --> 44021.rs:3:20
  |
3 |     fn foo() {|x, y}
  |                    ^ expected one of `:`, `@`, or `|` here
```
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 10, 2017
Expect pipe symbol after closure parameter list

Fixes rust-lang#44021.

---

Originally, the parser just called `bump` to discard following token after parsing closure parameter list, because it assumes `|` is following. However, the following code breaks the assumption:

```rust
struct MyStruct;
impl MyStruct {
   fn f() {|x, y}
}
```

Here, the parameter list is `x, y` and the following token is `}`. The parser discards `}`, and then we have a curly bracket mismatch.

Indeed, this code has a syntax error. On current nightly, the compiler emits an syntax error, but with incorrect message and span, followed by an ICE.

```
error: expected expression, found `}`
 --> 44021.rs:4:1
  |
4 | }
  | ^

error: internal compiler error: unexpected panic
```

Even worse, on current stable(1.20.0), the compiler falls into an infinite loop.

This pull request fixes this problem. Now the compiler emits correct error message and span, and does not ICE.

```
error: expected one of `:`, `@`, or `|`, found `}`
 --> 44021.rs:3:20
  |
3 |     fn foo() {|x, y}
  |                    ^ expected one of `:`, `@`, or `|` here
```
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.

4 participants