Skip to content

panicked at 'index out of bounds: the len is 0 but the index is 0' from chalk code #10390

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

Closed
Tracked by #11387 ...
tmandry opened this issue Sep 29, 2021 · 6 comments
Closed
Tracked by #11387 ...
Labels
A-ty type system / type inference / traits / method resolution Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@tmandry
Copy link
Member

tmandry commented Sep 29, 2021

Anytime I try to use rust-analyzer on the rustc codebase now, I get:

thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/runner/.cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/chalk-ir-0.71.0/src/fold/subst.rs:58:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic_bounds_check
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:69:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: <hir_ty::CallableSig as chalk_ir::fold::Fold<hir_ty::interner::Interner>>::fold_with
   6: <chalk_ir::Ty<hir_ty::interner::Interner> as hir_ty::chalk_ext::TyExt>::callable_sig
   7: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_method_call
   8: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
   9: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  10: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  11: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  12: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  13: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  14: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  15: hir_ty::infer::infer_query
  16: salsa::runtime::Runtime::execute_query_implementation
  17: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  18: salsa::derived::slot::Slot<Q,MP>::read
  19: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  20: <DB as hir_ty::db::HirDatabase>::infer_query
  21: hir_ty::db::infer_wait
  22: hir::source_analyzer::SourceAnalyzer::new_for_body
  23: hir::semantics::SemanticsImpl::analyze_impl
  24: hir::semantics::SemanticsImpl::descend_into_macros
  25: ide::hover::hover
  26: std::panicking::try
  27: rust_analyzer::handlers::handle_hover
  28: std::panicking::try
  29: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 9:29:00 PM] Request textDocument/hover failed.
  Message: server panicked: index out of bounds: the len is 0 but the index is 0
  Code: -32603 
Panic context:
> 
version: 009e6ceb1 2021-09-27 stable
request: rust-analyzer/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/usr/local/google/home/tmandry/rust/compiler/rustc_codegen_llvm/src/attributes.rs",
            query: None,
            fragment: None,
        },
    },
}

It keeps panicking over and over so hopefully shouldn't be hard to reproduce.

Also mentioned in #10386 (comment)

@tmandry tmandry changed the title panicked at 'index out of bounds: the len is 0 but the index is 0' panicked at 'index out of bounds: the len is 0 but the index is 0' from chalk code Sep 29, 2021
@MolotovCherry
Copy link

MolotovCherry commented Sep 30, 2021

I'm getting something similar pretty often too.

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', crates\hir_def\src\nameres\path_resolution.rs:395:33
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 7:15:16 PM] Request textDocument/hover failed.
  Message: server panicked: index out of bounds: the len is 1 but the index is 1
  Code: -32603 
thread '<unnamed>' panicked at 'index out of bounds: the len is 9 but the index is 14', crates\hir_def\src\nameres\path_resolution.rs:395:33
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 009e6ceb1 2021-09-27 stable
request: textDocument/hover HoverParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/d%3A/Users/~/app/jni/kmagick-rs/jni-tools/src/lib.rs",
            query: None,
            fragment: None,
        },
    },
    position: Position(
        Position {
            line: 20,
            character: 89,
        },
    ),
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
}

@lnicola lnicola added A-ty type system / type inference / traits / method resolution Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now labels Sep 30, 2021
@SkiFire13
Copy link
Contributor

@tmandry this looks different than the one in #10386 (comment) since the version of your stacktrace is "009e6ceb1 2021-09-27 stable", which was released before #10305 got merged.

@cherryleafroad your error doesn't happen in chalk, but during name resolution. It may be #10084 instead.

@tmandry
Copy link
Member Author

tmandry commented Oct 1, 2021

Yeah, I thought this was due to a recent change but actually it occurs in the last 3 stable releases. I'm not sure why I was hitting it yesterday but not last week. I'll post more information if I hit it again.

@dovahcrow
Copy link

dovahcrow commented Mar 9, 2022

Got the same issue even with the latest stable / nightly (2022-03-08 / 2022-03-09-nightly)

It seems like due to the const generic order on the fn: changing from fn foo<const S: usize, T>() {} to fn foo<T, const S: usize>() {} solved the issue.

@jyn514
Copy link
Member

jyn514 commented Mar 26, 2022

I see a similar panic in rustdoc.

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   6: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
   7: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
   9: chalk_ir::fold::binder_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Binders<T>>::fold_with
  10: chalk_ir::Binders<T>::substitute
  11: hir_ty::chalk_db::convert_where_clauses
  12: hir_ty::chalk_db::impl_datum_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: salsa::QueryTable<Q>::get
  17: <DB as hir_ty::db::HirDatabase>::impl_datum
  18: chalk_solve::clauses::program_clauses_that_could_match
  19: chalk_recursive::solve::SolveIteration::solve_iteration
  20: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  22: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  23: salsa::runtime::Runtime::execute_query_implementation
  24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  25: salsa::derived::slot::Slot<Q,MP>::read
  26: salsa::QueryTable<Q>::get
  27: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  28: hir_ty::db::trait_solve_wait
  29: <DB as hir_ty::db::HirDatabase>::trait_solve
  30: hir_ty::method_resolution::iterate_trait_method_candidates
  31: hir_ty::method_resolution::iterate_method_candidates_by_receiver
  32: hir_ty::method_resolution::iterate_method_candidates_dyn
  33: hir::Type::iterate_method_candidates_dyn
  34: hir::Type::iterate_method_candidates
  35: ide_completion::completions::dot::complete_dot
  36: ide_completion::completions
  37: std::panicking::try
  38: rust_analyzer::handlers::handle_completion
  39: std::panicking::try
  40: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 12:07:30 AM] Request textDocument/completion failed.
  Message: server panicked: index out of bounds: the len is 1 but the index is 1
  Code: -32603 

@flodiebold
Copy link
Member

I can't reproduce the original error, rust-analyzer analysis-stats . on the rustc repo runs to completion. It's probably been fixed by the recent const generics changes. @jyn514 I don't get any panics on librustdoc either, though yours is during completion, so it may be running some query that we otherwise don't get. If you still encounter it, can you post a new issue? I'm going to close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

7 participants