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', compiler/rustc_middle/src/ty/mod.rs:893:14 #80062

Closed
chengniansun opened this issue Dec 15, 2020 · 7 comments · Fixed by #80513
Assignees
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chengniansun
Copy link

Sorry if this is a duplicate. I tried to search but failed to fine a duplicate one.

Code

fn sof<usize>() -> usize {}
fn test<T>() {
    let _: [u8; sof::<T>()];
}

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (fa4163942 2020-12-14)
binary: rustc
commit-hash: fa416394275d2468d104b8f72ac31b1ddf7ee52e
commit-date: 2020-12-14
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

Error output

warning: type parameter `usize` should have an upper camel case name
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:8
  |
1 | fn sof<usize>() -> usize {}
  |        ^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Usize`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

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 | / fn sof<usize>() -> usize {}
2 | | fn test<T>() {
3 | |     let _: [u8; sof::<T>()];
4 | | }
  | |_^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

error[E0308]: mismatched types
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:20
  |
1 | fn sof<usize>() -> usize {}
  |    --- -----       ^^^^^ expected type parameter `usize`, found `()`
  |    |   |
  |    |   this type parameter
  |    implicitly returns `()` as its body has no tail or `return` expression
  |
  = note: expected type parameter `usize`
                  found unit type `()`

error[E0277]: the size for values of type `T` cannot be known at compilation time
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:3:23
  |
1 | fn sof<usize>() -> usize {}
  |        ----- required by this bound in `sof`
2 | fn test<T>() {
  |         - this type parameter needs to be `Sized`
3 |     let _: [u8; sof::<T>()];
  |                       ^ doesn't have a size known at compile-time
  |
help: consider relaxing the implicit `Sized` restriction
  |
1 | fn sof<usize: ?Sized>() -> usize {}
  |             ^^^^^^^^

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/rustc_middle/src/ty/mod.rs:893:14
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:/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.50.0-nightly (fa4163942 2020-12-14) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `test::{constant#0}`
#1 [eval_to_allocation_raw] const-evaluating + checking `test::{constant#0}`
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

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

warning: type parameter `usize` should have an upper camel case name
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:8
  |
1 | fn sof<usize>() -> usize {}
  |        ^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Usize`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

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 | / fn sof<usize>() -> usize {}
2 | | fn test<T>() {
3 | |     let _: [u8; sof::<T>()];
4 | | }
  | |_^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

error[E0308]: mismatched types
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:20
  |
1 | fn sof<usize>() -> usize {}
  |    --- -----       ^^^^^ expected type parameter `usize`, found `()`
  |    |   |
  |    |   this type parameter
  |    implicitly returns `()` as its body has no tail or `return` expression
  |
  = note: expected type parameter `usize`
                  found unit type `()`

error[E0277]: the size for values of type `T` cannot be known at compilation time
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:3:23
  |
1 | fn sof<usize>() -> usize {}
  |        ----- required by this bound in `sof`
2 | fn test<T>() {
  |         - this type parameter needs to be `Sized`
3 |     let _: [u8; sof::<T>()];
  |                       ^ doesn't have a size known at compile-time
  |
help: consider relaxing the implicit `Sized` restriction
  |
1 | fn sof<usize: ?Sized>() -> usize {}
  |             ^^^^^^^^

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/rustc_middle/src/ty/mod.rs:893:14
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fa416394275d2468d104b8f72ac31b1ddf7ee52e/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/fa416394275d2468d104b8f72ac31b1ddf7ee52e/library/core/src/panicking.rs:92:14
   2: core::panicking::panic_bounds_check
             at /rustc/fa416394275d2468d104b8f72ac31b1ddf7ee52e/library/core/src/panicking.rs:69:5
   3: rustc_middle::ty::Generics::param_at
   4: rustc_middle::ty::error::<impl rustc_middle::ty::context::TyCtxt>::note_and_explain_type_err
   5: rustc_infer::infer::error_reporting::<impl rustc_infer::infer::InferCtxt>::note_type_err
   6: rustc_infer::infer::error_reporting::<impl rustc_infer::infer::InferCtxt>::report_and_explain_type_error
   7: rustc_infer::infer::InferCtxt::report_mismatched_types
   8: rustc_typeck::check::demand::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::demand_coerce_diag
   9: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_coercable_to_type
  10: rustc_infer::infer::InferCtxtBuilder::enter
  11: rustc_typeck::check::typeck
  12: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  13: rustc_data_structures::stack::ensure_sufficient_stack
  14: rustc_query_system::query::plumbing::get_query_impl
  15: rustc_middle::ty::context::TyCtxt::typeck_opt_const_arg
  16: rustc_mir::const_eval::eval_queries::eval_to_allocation_raw_provider
  17: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_allocation_raw>::compute
  18: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  19: rustc_query_system::query::plumbing::get_query_impl
  20: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  21: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_const_value_raw>::compute
  22: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  23: rustc_query_system::query::plumbing::get_query_impl
  24: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  25: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_const_value_raw>::compute
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  27: rustc_data_structures::stack::ensure_sufficient_stack
  28: rustc_query_system::query::plumbing::get_query_impl
  29: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  30: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  31: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_const
  32: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  33: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  34: rustc_data_structures::stack::ensure_sufficient_stack
  35: rustc_trait_selection::traits::project::normalize
  36: <rustc_infer::infer::InferCtxt as rustc_trait_selection::infer::InferCtxtExt>::partially_normalize_associated_types_in
  37: rustc_typeck::check::inherited::Inherited::normalize_associated_types_in
  38: <rustc_typeck::check::fn_ctxt::FnCtxt as rustc_typeck::astconv::AstConv>::normalize_ty
  39: <dyn rustc_typeck::astconv::AstConv>::ast_ty_to_ty_inner
  40: <rustc_typeck::check::gather_locals::GatherLocalsVisitor as rustc_hir::intravisit::Visitor>::visit_local
  41: rustc_hir::intravisit::walk_expr
  42: rustc_typeck::check::check::check_fn
  43: rustc_infer::infer::InferCtxtBuilder::enter
  44: rustc_typeck::check::typeck
  45: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute
  46: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  47: rustc_data_structures::stack::ensure_sufficient_stack
  48: rustc_query_system::query::plumbing::get_query_impl
  49: rustc_query_system::query::plumbing::ensure_query_impl
  50: rustc_typeck::check::typeck_item_bodies
  51: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  52: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  53: rustc_data_structures::stack::ensure_sufficient_stack
  54: rustc_query_system::query::plumbing::get_query_impl
  55: rustc_typeck::check_crate
  56: rustc_interface::passes::analysis
  57: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  58: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  59: rustc_data_structures::stack::ensure_sufficient_stack
  60: rustc_query_system::query::plumbing::get_query_impl
  61: rustc_interface::passes::QueryContext::enter
  62: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  63: rustc_span::with_source_map
  64: rustc_interface::interface::create_compiler_and_run
  65: 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:/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.50.0-nightly (fa4163942 2020-12-14) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `test::{constant#0}`
#1 [eval_to_allocation_raw] const-evaluating + checking `test::{constant#0}`
#2 [eval_to_const_value_raw] simplifying constant for the type system `test::{constant#0}`
#3 [eval_to_const_value_raw] simplifying constant for the type system `test::{constant#0}`
#4 [typeck] type-checking `test`
#5 [typeck_item_bodies] type-checking all item bodies
#6 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

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

@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 Dec 15, 2020
fanninpm added a commit to fanninpm/glacier that referenced this issue Dec 17, 2020
fanninpm added a commit to fanninpm/glacier that referenced this issue Dec 19, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 20, 2020
@matthiaskrgr
Copy link
Member

The ice happens since 1.41
@rustbot modify labels: +regression-from-stable-to-stable

@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 20, 2020
@LeSeulArtichaut
Copy link
Contributor

I'd be interested in taking a look into this

@LeSeulArtichaut LeSeulArtichaut self-assigned this Dec 21, 2020
@LeSeulArtichaut
Copy link
Contributor

LeSeulArtichaut commented Dec 21, 2020

FWIW, this has nothing to do with the usize type parameter name, nor the missing return value. Consider the following code:

fn sof<T>() -> T { todo!() }
fn test<T>() {
    let _: [u8; sof::<T>()];
}

Which gives the following error

error[E0277]: the size for values of type `T` cannot be known at compilation time
 --> src/lib.rs:3:23
  |
1 | fn sof<T>() -> T { todo!() }
  |        - required by this bound in `sof`
2 | fn test<T>() {
  |         - this type parameter needs to be `Sized`
3 |     let _: [u8; sof::<T>()];
  |                       ^ doesn't have a size known at compile-time
  |
help: consider relaxing the implicit `Sized` restriction
  |
1 | fn sof<T: ?Sized>() -> T { todo!() }
  |         ^^^^^^^^

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/rustc_middle/src/ty/mod.rs:908:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@LeSeulArtichaut LeSeulArtichaut added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 21, 2020
@LeSeulArtichaut
Copy link
Contributor

@LeSeulArtichaut
Copy link
Contributor

LeSeulArtichaut commented Dec 21, 2020

I suspect #66014 is the culprit for this regression.

EDIT: confirmed this regressed in nightly-2019-11-07 (1423bec...3804876) which contains #66014

@LeSeulArtichaut
Copy link
Contributor

I think this is due to rustc trying to access the generics in the AnonConst instead of the actual function.

@JohnTitor
Copy link
Member

Triage:

The current output with the latest nightly:

error: generic parameters may not be used in const operations
 --> src/main.rs:3:23
  |
3 |     let _: [u8; sof::<T>()];
  |                       ^ cannot perform const operation using `T`
  |
  = note: type parameters may not be used in const expressions
  = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions

warning: type parameter `usize` should have an upper camel case name
 --> src/main.rs:1:8
  |
1 | fn sof<usize>() -> usize {}
  |        ^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Usize`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

error[E0308]: mismatched types
 --> src/main.rs:1:20
  |
1 | fn sof<usize>() -> usize {}
  |    --- -----       ^^^^^ expected type parameter `usize`, found `()`
  |    |   |
  |    |   this type parameter
  |    implicitly returns `()` as its body has no tail or `return` expression
  |
  = note: expected type parameter `usize`
                  found unit type `()`

error: aborting due to 2 previous errors; 1 warning emitted

with #![feature(const_generics)]:

error[E0308]: mismatched types
 --> src/main.rs:4:20
  |
4 | fn sof<usize>() -> usize {}
  |    --- -----       ^^^^^ expected type parameter `usize`, found `()`
  |    |   |
  |    |   this type parameter
  |    implicitly returns `()` as its body has no tail or `return` expression
  |
  = note: expected type parameter `usize`
                  found unit type `()`

error[E0308]: mismatched types
 --> src/main.rs:6:17
  |
5 | fn test<T>() {
  |         - this type parameter
6 |     let _: [u8; sof::<T>()];
  |                 ^^^^^^^^^^ expected `usize`, found type parameter `T`
  |
  = note:        expected type `usize`
          found type parameter `T`

error: aborting due to 2 previous errors; 1 warning emitted

Neither snippet is ICE.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 30, 2020
LeSeulArtichaut added a commit to LeSeulArtichaut/rust that referenced this issue Dec 30, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 30, 2020
Rollup of 9 pull requests

Successful merges:

 - rust-lang#78934 (refactor: removing library/alloc/src/vec/mod.rs ignore-tidy-filelength)
 - rust-lang#79479 (Add `Iterator::intersperse`)
 - rust-lang#80128 (Edit rustc_ast::ast::FieldPat docs)
 - rust-lang#80424 (Don't give an error when creating a file for the first time)
 - rust-lang#80458 (Some Promotion Refactoring)
 - rust-lang#80488 (Do not create dangling &T in Weak<T>::drop)
 - rust-lang#80491 (Miri: make size/align_of_val work for dangling raw ptrs)
 - rust-lang#80495 (Rename kw::Invalid -> kw::Empty)
 - rust-lang#80513 (Add regression test for rust-lang#80062)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 8998e31 Dec 31, 2020
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants