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: panicked at 'index out of bounds: the len is 1 but the index is 1', compiler/rustc_typeck/src/check/method/mod.rs:318:32 #83893

Closed
chengniansun opened this issue Apr 5, 2021 · 0 comments · Fixed by #85339
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@chengniansun
Copy link

Code

#[lang = "add"]
trait Add<'a, T> {}
fn ice() {
    r + a
}

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (c755ee4ce 2021-04-04)
binary: rustc
commit-hash: c755ee4ce8cae6ea977d65a0288480940db721d9
commit-date: 2021-04-04
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Error output

error[E0425]: cannot find value `r` in this scope
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:4:5
  |
4 |     r + a
  |     ^ not found in this scope

error[E0425]: cannot find value `a` in this scope
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:4:9
  |
4 |     r + a
  |         ^ not found in this scope

error[E0658]: language items are subject to change
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | #[lang = "add"]
  | ^^^^^^^^^^^^^^^
  |
  = help: add `#![feature(lang_items)]` to the crate attributes to enable

error[E0601]: `main` function not found in crate `perses_node_priority_with_dfs_delta_reduced_mutant`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | / #[lang = "add"]
2 | | trait Add<'a, T> {}
3 | | fn ice() {
4 | |     r + a
5 | | }
  | |_^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

error[E0152]: found duplicate lang item `add`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:2:1
  |
2 | trait Add<'a, T> {}
  | ^^^^^^^^^^^^^^^^^^^
  |
  = note: the lang item is first defined in crate `core` (which `std` depends on)
  = note: first definition in `core` loaded from /home/cnsun/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-166dae07beec0398.rlib
  = note: second definition in the local crate (`perses_node_priority_with_dfs_delta_reduced_mutant`)

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', compiler/rustc_typeck/src/check/method/mod.rs:318:32
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.53.0-nightly (c755ee4ce 2021-04-04) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `ice`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0152, E0425, E0601, E0658.
For more information about an error, try `rustc --explain E0152`.
Backtrace

error[E0425]: cannot find value `r` in this scope
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:4:5
  |
4 |     r + a
  |     ^ not found in this scope

error[E0425]: cannot find value `a` in this scope
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:4:9
  |
4 |     r + a
  |         ^ not found in this scope

error[E0658]: language items are subject to change
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | #[lang = "add"]
  | ^^^^^^^^^^^^^^^
  |
  = help: add `#![feature(lang_items)]` to the crate attributes to enable

error[E0601]: `main` function not found in crate `perses_node_priority_with_dfs_delta_reduced_mutant`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | / #[lang = "add"]
2 | | trait Add<'a, T> {}
3 | | fn ice() {
4 | |     r + a
5 | | }
  | |_^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

error[E0152]: found duplicate lang item `add`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:2:1
  |
2 | trait Add<'a, T> {}
  | ^^^^^^^^^^^^^^^^^^^
  |
  = note: the lang item is first defined in crate `core` (which `std` depends on)
  = note: first definition in `core` loaded from /home/cnsun/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-166dae07beec0398.rlib
  = note: second definition in the local crate (`perses_node_priority_with_dfs_delta_reduced_mutant`)

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', compiler/rustc_typeck/src/check/method/mod.rs:318:32
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c755ee4ce8cae6ea977d65a0288480940db721d9/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/c755ee4ce8cae6ea977d65a0288480940db721d9/library/core/src/panicking.rs:92:14
   2: core::panicking::panic_bounds_check
             at /rustc/c755ee4ce8cae6ea977d65a0288480940db721d9/library/core/src/panicking.rs:69:5
   3: rustc_middle::ty::subst::<impl rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg>>::fill_item
   4: rustc_middle::ty::subst::<impl rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg>>::for_item
   5: rustc_typeck::check::method::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_method_in_trait
   6: rustc_typeck::check::op::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_op_method
   7: rustc_typeck::check::op::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_overloaded_binop
   8: rustc_typeck::check::op::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_binop
   9: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  10: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  11: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  12: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  13: rustc_typeck::check::check::check_fn
  14: rustc_infer::infer::InferCtxtBuilder::enter
  15: rustc_typeck::check::typeck
  16: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  17: rustc_data_structures::stack::ensure_sufficient_stack
  18: rustc_query_system::query::plumbing::force_query_with_job
  19: rustc_query_system::query::plumbing::get_query_impl
  20: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  21: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  22: rustc_typeck::check::typeck_item_bodies
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::force_query_with_job
  26: rustc_query_system::query::plumbing::get_query_impl
  27: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  28: rustc_session::utils::<impl rustc_session::session::Session>::time
  29: rustc_typeck::check_crate
  30: rustc_interface::passes::analysis
  31: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  32: rustc_data_structures::stack::ensure_sufficient_stack
  33: rustc_query_system::query::plumbing::force_query_with_job
  34: rustc_query_system::query::plumbing::get_query_impl
  35: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  36: rustc_interface::passes::QueryContext::enter
  37: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  38: rustc_span::with_source_map
  39: rustc_interface::interface::create_compiler_and_run
  40: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.53.0-nightly (c755ee4ce 2021-04-04) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `ice`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0152, E0425, E0601, E0658.
For more information about an error, try `rustc --explain E0152`.

@chengniansun chengniansun 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 Apr 5, 2021
@bjorn3 bjorn3 added requires-nightly This issue requires a nightly compiler in some way. and removed requires-nightly This issue requires a nightly compiler in some way. labels Apr 5, 2021
fanninpm added a commit to fanninpm/glacier that referenced this issue Apr 9, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 10, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 18, 2021
Report an error if a lang item has the wrong number of generic arguments

This pull request fixes rust-lang#83893. The issue is that the lang item code currently checks whether the lang item has the correct item kind (e.g. a `#[lang="add"]` has to be a trait), but not whether the item has the correct number of generic arguments.

This can lead to an "index out of bounds" ICE when the compiler tries to create more substitutions than there are suitable types available (if the lang item was declared with too many generic arguments).

For instance, here is a reduced ("reduced" in the sense that it does not trigger additional errors) version of the example given in rust-lang#83893:
```rust
#![feature(lang_items,no_core)]
#![no_core]
#![crate_type="lib"]

#[lang = "sized"]
trait MySized {}

#[lang = "add"]
trait MyAdd<'a, T> {}

fn ice() {
    let r = 5;
    let a = 6;
    r + a
}
```
On current nightly, this immediately causes an ICE without any warnings or errors emitted. With the changes in this PR, however, I get no ICE and two errors:
```
error[E0718]: `add` language item must be applied to a trait with 1 generic argument
 --> pr-ex.rs:8:1
  |
8 | #[lang = "add"]
  | ^^^^^^^^^^^^^^^
9 | trait MyAdd<'a, T> {}
  |            ------- this trait has 2 generic arguments, not 1

error[E0369]: cannot add `{integer}` to `{integer}`
  --> pr-ex.rs:14:7
   |
14 |     r + a
   |     - ^ - {integer}
   |     |
   |     {integer}

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0369, E0718.
For more information about an error, try `rustc --explain E0369`.
```
@bors bors closed this as completed in 1bfd987 May 18, 2021
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. glacier ICE tracked in rust-lang/glacier. 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.

3 participants