Skip to content

Index out of bounds: the len is 1 but the index is 1 #5366

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
MikailBag opened this issue Jul 14, 2020 · 13 comments
Closed

Index out of bounds: the len is 1 but the index is 1 #5366

MikailBag opened this issue Jul 14, 2020 · 13 comments
Labels
A-nameres name, path and module resolution Broken Window Bugs / technical debt to be addressed immediately I-panic

Comments

@MikailBag
Copy link
Contributor

panic message:

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', crates/ra_hir_def/src/nameres/path_resolution.rs:275:33
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/gb.xjqchip.workers.dev-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:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1504
   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:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:511
  11: rust_begin_unwind
             at src/libstd/panicking.rs:419
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:111
  13: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:69
  14: ra_hir_def::nameres::path_resolution::<impl ra_hir_def::nameres::CrateDefMap>::resolve_path_fp_with_macro
  15: ra_hir_def::resolver::Resolver::resolve_path_in_type_ns
  16: ra_hir_ty::lower::<impl ra_hir_ty::Ty>::from_hir_ext
  17: ra_hir_ty::lower::impl_self_ty_query
  18: salsa::runtime::Runtime::execute_query_implementation
  19: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  20: salsa::derived::slot::Slot<Q,MP>::read
  21: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  22: <DB as ra_hir_ty::db::HirDatabase>::impl_self_ty::__shim
  23: <DB as ra_hir_ty::db::HirDatabase>::impl_self_ty
  24: ra_hir_ty::lower::impl_trait_query
  25: salsa::runtime::Runtime::execute_query_implementation
  26: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  27: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  28: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  29: salsa::derived::slot::MemoRevisions::validate_memoized_value
  30: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  31: salsa::derived::slot::Slot<Q,MP>::read
  32: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  33: <DB as ra_hir_ty::db::HirDatabase>::trait_impls_in_crate::__shim
  34: ra_hir_ty::method_resolution::TraitImpls::trait_impls_in_deps_query
  35: salsa::runtime::Runtime::execute_query_implementation
  36: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  37: salsa::derived::slot::Slot<Q,MP>::read
  38: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  39: <DB as ra_hir_ty::db::HirDatabase>::trait_impls_in_deps::__shim
  40: ra_hir_ty::traits::chalk::<impl chalk_solve::RustIrDatabase<ra_hir_ty::traits::chalk::interner::Interner> for ra_hir_ty::traits::ChalkContext>::impls_for_trait
  41: chalk_solve::clauses::program_clauses_that_could_match
  42: chalk_solve::clauses::program_clauses_for_goal
  43: chalk_recursive::recursive::Solver<I>::solve_new_subgoal
  44: <chalk_recursive::recursive::Solver<I> as chalk_recursive::solve::SolveDatabase<I>>::solve_goal
  45: <chalk_recursive::recursive::RecursiveSolver<I> as chalk_solve::solve::Solver<I>>::solve_limited
  46: ra_hir_ty::traits::trait_solve_query
  47: salsa::runtime::Runtime::execute_query_implementation
  48: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  49: salsa::derived::slot::Slot<Q,MP>::read
  50: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  51: <DB as ra_hir_ty::db::HirDatabase>::trait_solve::__shim
  52: <DB as ra_hir_ty::db::HirDatabase>::trait_solve
  53: ra_hir_ty::autoderef::deref
  54: <core::iter::sources::Successors<T,F> as core::iter::traits::iterator::Iterator>::next
  55: core::iter::traits::iterator::Iterator::find_map
  56: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
  57: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr
  58: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
  59: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr
  60: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
  61: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_coerce
  62: ra_hir_ty::infer::infer_query
  63: salsa::runtime::Runtime::execute_query_implementation
  64: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  65: salsa::derived::slot::Slot<Q,MP>::read
  66: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  67: <DB as ra_hir_ty::db::HirDatabase>::infer_query::__shim
  68: ra_hir_ty::db::infer_wait
  69: ra_hir::source_analyzer::SourceAnalyzer::new_for_body
  70: ra_hir::semantics::SemanticsImpl::analyze2
  71: ra_hir::semantics::SemanticsImpl::descend_into_macros
  72: ra_ide::hover::hover
  73: std::panicking::try
  74: ra_ide::Analysis::hover
  75: rust_analyzer::handlers::handle_hover
  76: <F as threadpool::FnBox>::call_box

Installed via xtask from source.

$ git rev-parse HEAD
510866b4a1a812414568bd96f1d197587ead78c0
@bjorn3
Copy link
Member

bjorn3 commented Jul 14, 2020

What project is this on?

@bjorn3 bjorn3 added the A-ty type system / type inference / traits / method resolution label Jul 14, 2020
@jonas-schievink
Copy link
Contributor

@MikailBag Can you provide the source code that causes this panic?

@MikailBag
Copy link
Contributor Author

MikailBag commented Jul 24, 2020

I don't remember neither source file name, nor git commit unfortunately. If I see this panic again, I'll reopen.

@chanks
Copy link

chanks commented Sep 23, 2020

Just hit this myself, on a closed-source project. The line number is a little different, I'm assuming it drifted since this last report.

Tried to reproduce but wasn't able to. It happened as I was adding a mod declaration (the referenced file already existed, but wasn't syntactically valid yet), and then a pub(crate) use declaration for a struct in that file.

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 4', crates/hir_def/src/nameres/path_resolution.rs:283:33
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/gb.xjqchip.workers.dev-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:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   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: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:526
  11: rust_begin_unwind
             at src/libstd/panicking.rs:437
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  13: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:62
  14: hir_def::nameres::path_resolution::<impl hir_def::nameres::CrateDefMap>::resolve_path_fp_with_macro
  15: hir_def::resolver::Resolver::resolve_path_in_type_ns
  16: hir_ty::lower::<impl hir_ty::Ty>::from_hir_ext
  17: hir_ty::lower::impl_self_ty_query
  18: salsa::runtime::Runtime::execute_query_implementation
  19: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  20: salsa::derived::slot::Slot<Q,MP>::read
  21: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  22: <DB as hir_ty::db::HirDatabase>::impl_self_ty::__shim
  23: <DB as hir_ty::db::HirDatabase>::impl_self_ty
  24: hir_ty::lower::impl_trait_query
  25: salsa::runtime::Runtime::execute_query_implementation
  26: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  27: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  28: hir_ty::db::HirDatabaseGroupStorage__::maybe_changed_since
  29: salsa::derived::slot::MemoRevisions::validate_memoized_value
  30: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  31: salsa::derived::slot::Slot<Q,MP>::read
  32: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  33: <DB as hir_ty::db::HirDatabase>::trait_impls_in_crate::__shim
  34: hir_ty::method_resolution::TraitImpls::trait_impls_in_deps_query
  35: salsa::runtime::Runtime::execute_query_implementation
  36: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  37: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  38: hir_ty::db::HirDatabaseGroupStorage__::maybe_changed_since
  39: salsa::derived::slot::MemoRevisions::validate_memoized_value
  40: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  41: salsa::derived::slot::Slot<Q,MP>::read
  42: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  43: <DB as hir_ty::db::HirDatabase>::trait_solve::__shim
  44: <DB as hir_ty::db::HirDatabase>::trait_solve
  45: hir_ty::autoderef::deref
  46: core::iter::traits::iterator::Iterator::find_map
  47: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  48: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  49: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  50: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  51: hir_ty::infer::infer_query
  52: salsa::runtime::Runtime::execute_query_implementation
  53: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  54: salsa::derived::slot::Slot<Q,MP>::read
  55: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  56: <DB as hir_ty::db::HirDatabase>::infer_query::__shim
  57: hir_ty::db::infer_wait
  58: hir_ty::diagnostics::validate_body
  59: hir::code_model::Module::diagnostics
  60: ide::diagnostics::diagnostics
  61: ide::Analysis::diagnostics
  62: rust_analyzer::handlers::publish_diagnostics
  63: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  64: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  65: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@jonas-schievink
Copy link
Contributor

Let's keep the issue open regardless, this seems important to track.

The panicking line is this:

https://github.com/rust-analyzer/rust-analyzer/blob/4ddb8124b01a04adcc7d42444f7ca8d377bb60ae/crates/hir_def/src/nameres/path_resolution.rs#L283

@flodiebold flodiebold added S-unactionable Issue requires feedback, design decisions or is blocked on other work and removed A-ty type system / type inference / traits / method resolution labels Dec 22, 2020
@jonas-schievink jonas-schievink added the A-nameres name, path and module resolution label Mar 25, 2021
@injecto
Copy link

injecto commented Oct 12, 2021

I've had the similar issue (VS Code output):

Panic context:
> 
version: ed4b312fa 2021-10-11 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: "/home/injecto/dev/adv/core/actors/entity_streamer/src/streamer.rs",
            query: None,
            fragment: None,
        },
    },
    position: Position(
        Position {
            line: 68,
            character: 23,
        },
    ),
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
}

> impl_trait_query(ImplId(15627) -> ItemLoc { container: ModuleId { krate: CrateId(1134), block: None, local_id: Idx::<ModuleData>(4) }, id: ItemTreeId { tree: TreeId { file: HirFileId(FileId(FileId(3925))), block: None }, value: Idx::<Impl>(0) } } -> ImplData { target_trait: None, self_ty: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("CpuSet"))] }, generic_args: [None] }), items: [FunctionId(FunctionId(28448)), FunctionId(FunctionId(28449)), FunctionId(FunctionId(28450)), FunctionId(FunctionId(28451)), FunctionId(FunctionId(28452)), FunctionId(FunctionId(28453)), FunctionId(FunctionId(28454)), FunctionId(FunctionId(28455)), FunctionId(FunctionId(28456)), FunctionId(FunctionId(28457)), FunctionId(FunctionId(28458)), FunctionId(FunctionId(28459))], is_negative: false })

> impl_self_ty_query(ImplId(15627) -> ItemLoc { container: ModuleId { krate: CrateId(1134), block: None, local_id: Idx::<ModuleData>(4) }, id: ItemTreeId { tree: TreeId { file: HirFileId(FileId(FileId(3925))), block: None }, value: Idx::<Impl>(0) } } -> ImplData { target_trait: None, self_ty: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("CpuSet"))] }, generic_args: [None] }), items: [FunctionId(FunctionId(28448)), FunctionId(FunctionId(28449)), FunctionId(FunctionId(28450)), FunctionId(FunctionId(28451)), FunctionId(FunctionId(28452)), FunctionId(FunctionId(28453)), FunctionId(FunctionId(28454)), FunctionId(FunctionId(28455)), FunctionId(FunctionId(28456)), FunctionId(FunctionId(28457)), FunctionId(FunctionId(28458)), FunctionId(FunctionId(28459))], is_negative: false })

> DefMap CrateId(1134) crate_name=Some(CrateDisplayName { crate_name: CrateName("build_script_build"), canonical_name: "build-script-build" }) block=None path=CpuSet

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 4', crates/hir_def/src/nameres/path_resolution.rs:389:33
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: hir_def::nameres::path_resolution::<impl hir_def::nameres::DefMap>::resolve_path_fp_with_macro_single
   4: hir_def::resolver::Resolver::resolve_path_in_type_ns
   5: hir_ty::lower::TyLoweringContext::lower_ty_ext
   6: hir_ty::lower::impl_self_ty_query
   7: salsa::runtime::Runtime::execute_query_implementation
   8: salsa::derived::slot::Slot<Q,MP>::read_upgrade
   9: salsa::derived::slot::Slot<Q,MP>::read
  10: salsa::QueryTable<Q>::get
  11: <DB as hir_ty::db::HirDatabase>::impl_self_ty
  12: hir_ty::lower::impl_trait_query
  13: salsa::runtime::Runtime::execute_query_implementation
  14: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  15: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  16: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  17: salsa::derived::slot::MemoRevisions::validate_memoized_value
  18: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  19: salsa::derived::slot::Slot<Q,MP>::read
  20: salsa::QueryTable<Q>::get
  21: <DB as hir_ty::db::HirDatabase>::trait_impls_in_crate
  22: hir::Impl::all_for_type
  23: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  24: <core::iter::adapters::flatten::Flatten<I> as core::iter::traits::iterator::Iterator>::next
  25: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  26: ide::goto_implementation::goto_implementation
  27: std::panicking::try
  28: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  29: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  30: rust_analyzer::handlers::handle_hover
  31: std::panicking::try
  32: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 3:03:45 PM] Request textDocument/hover failed.
  Message: server panicked: index out of bounds: the len is 1 but the index is 4
  Code: -32603 

@jeromegn
Copy link

Adding to the data here, my vscode output:

> DefMap CrateId(600) crate_name=Some(CrateDisplayName { crate_name: CrateName("build_script_build"), canonical_name: "build-script-build" }) block=None path=serde_if_integer128

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 12', crates/hir_def/src/nameres/path_resolution.rs:389:33
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:101:14
   2: core::panicking::panic_bounds_check
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:77:5
   3: hir_def::nameres::path_resolution::<impl hir_def::nameres::DefMap>::resolve_path_fp_with_macro_single
   4: hir_def::nameres::path_resolution::<impl hir_def::nameres::DefMap>::resolve_path_fp_with_macro
   5: hir_def::macro_call_as_call_id
   6: hir_def::body::Expander::enter_expand
   7: hir_def::data::collect_items
   8: hir_def::data::TraitData::trait_data_query
   9: salsa::runtime::Runtime::execute_query_implementation
  10: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  11: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  12: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  13: salsa::derived::slot::MemoRevisions::validate_memoized_value
  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::fulfill::Fulfill<I,Solver>::prove
  22: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  23: chalk_recursive::solve::SolveIteration::solve_iteration
  24: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  25: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  26: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  27: salsa::runtime::Runtime::execute_query_implementation
  28: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  29: salsa::derived::slot::Slot<Q,MP>::read
  30: salsa::QueryTable<Q>::get
  31: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  32: hir_ty::db::trait_solve_wait
  33: <DB as hir_ty::db::HirDatabase>::trait_solve
  34: hir_ty::infer::unify::InferenceTable::register_obligation_in_env
  35: hir_ty::infer::unify::unify
  36: hir::Type::could_unify_with
  37: ide_completion::render::compute_type_match
  38: ide_completion::render::function::FunctionRender::render
  39: ide_completion::render::function::render_method
  40: hir::Type::iterate_method_candidates::{{closure}}
  41: hir_ty::method_resolution::iterate_trait_method_candidates
  42: hir_ty::method_resolution::iterate_method_candidates_by_receiver
  43: hir_ty::method_resolution::iterate_method_candidates_dyn
  44: hir::Type::iterate_method_candidates
  45: ide_completion::completions::dot::complete_dot
  46: ide_completion::completions
  47: std::panicking::try
  48: rust_analyzer::handlers::handle_completion
  49: std::panicking::try
  50: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 7:17:02 a.m.] Request textDocument/completion failed.
  Message: server panicked: index out of bounds: the len is 1 but the index is 12
  Code: -32603 

@lnicola lnicola added Broken Window Bugs / technical debt to be addressed immediately I-panic and removed S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Jul 21, 2023
@lnicola lnicola changed the title Index out of bounds Index out of bounds: the len is 1 but the index is 1 Jul 21, 2023
@evbo
Copy link

evbo commented Sep 13, 2023

Still hitting this issue in v0.4.1659 Pre-Release: #15468

@95th
Copy link

95th commented Oct 1, 2023

Getting this consistently these days:

thread 'Worker' panicked at 'attempted to access data of empty ItemTree', crates/hir-def/src/item_tree.rs:184:28
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::option::expect_failed
   3: hir_def::data::ImplData::impl_data_with_diagnostics_query
   4: salsa::runtime::Runtime::execute_query_implementation
   5: salsa::derived::slot::Slot<Q,MP>::read_upgrade
   6: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
   7: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
   8: salsa::derived::slot::MemoRevisions::validate_memoized_value
   9: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  10: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  11: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  12: salsa::derived::slot::MemoRevisions::validate_memoized_value
  13: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  14: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  15: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  16: salsa::derived::slot::MemoRevisions::validate_memoized_value
  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_def::db::DefDatabase>::lang_item::__shim
  21: hir_def::lang_item::LangItems::lang_item_query
  22: salsa::runtime::Runtime::execute_query_implementation
  23: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  24: salsa::derived::slot::Slot<Q,MP>::read
  25: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  26: <DB as hir_def::db::DefDatabase>::lang_item::__shim
  27: hir_def::lang_item::LangItems::lang_item_query
  28: salsa::runtime::Runtime::execute_query_implementation
  29: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  30: salsa::derived::slot::Slot<Q,MP>::read
  31: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  32: <DB as hir_def::db::DefDatabase>::lang_item::__shim
  33: hir_def::lang_item::LangItems::lang_item_query
  34: salsa::runtime::Runtime::execute_query_implementation
  35: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  36: salsa::derived::slot::Slot<Q,MP>::read
  37: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  38: <DB as hir_def::db::DefDatabase>::lang_item::__shim
  39: hir_def::body::lower::ExprCollector::maybe_collect_expr
  40: hir_def::body::lower::ExprCollector::maybe_collect_expr
  41: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  42: hir_def::body::lower::ExprCollector::maybe_collect_expr
  43: hir_def::body::lower::ExprCollector::collect_stmt
  44: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  45: hir_def::body::lower::ExprCollector::collect_block_
  46: hir_def::body::lower::ExprCollector::maybe_collect_expr
  47: hir_def::body::lower::ExprCollector::collect_macro_as_stmt
  48: hir_def::body::lower::ExprCollector::collect_stmt
  49: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  50: hir_def::body::lower::ExprCollector::collect_block_
  51: hir_def::body::lower::ExprCollector::maybe_collect_expr
  52: hir_def::body::lower::lower
  53: hir_def::body::Body::body_with_source_map_query
  54: salsa::runtime::Runtime::execute_query_implementation
  55: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  56: salsa::derived::slot::Slot<Q,MP>::read
  57: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  58: salsa::QueryTable<Q>::get
  59: <DB as hir_def::db::DefDatabase>::body_with_source_map
  60: hir::source_analyzer::SourceAnalyzer::new_for_body_no_infer
  61: hir::semantics::SemanticsImpl::analyze_impl
  62: hir::semantics::SemanticsImpl::descend_into_macros_impl
  63: hir::semantics::SemanticsImpl::descend_node_into_attributes
  64: ide::inlay_hints::chaining::hints
  65: ide::inlay_hints::hints
  66: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  67: ide::inlay_hints::inlay_hints
  68: salsa::Cancelled::catch
  69: rust_analyzer::handlers::request::handle_inlay_hints
  70: std::panicking::try
  71: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 11:10:16] Request textDocument/inlayHint failed.
  Message: request handler panicked: attempted to access data of empty ItemTree
  Code: -32603 

@95th
Copy link

95th commented Oct 1, 2023

Another:

thread 'Worker' panicked at 'index out of bounds: the len is 1 but the index is 1', crates/hir-def/src/nameres/path_resolution.rs:431:33
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: hir_def::nameres::path_resolution::<impl hir_def::nameres::DefMap>::resolve_path_fp_with_macro_single
   4: hir_def::resolver::ModuleItemMap::resolve_path_in_type_ns
   5: hir_def::resolver::Resolver::resolve_path_in_type_ns
   6: hir_ty::lower::TyLoweringContext::lower_ty_ext
   7: hir_ty::lower::impl_self_ty_query
   8: salsa::runtime::Runtime::execute_query_implementation
   9: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  10: salsa::derived::slot::Slot<Q,MP>::read
  11: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  12: salsa::QueryTable<Q>::get
  13: <DB as hir_ty::db::HirDatabase>::impl_self_ty
  14: hir_ty::lower::impl_trait_query
  15: salsa::runtime::Runtime::execute_query_implementation
  16: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  17: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  18: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  19: salsa::derived::slot::MemoRevisions::validate_memoized_value
  20: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  21: salsa::derived::slot::Slot<Q,MP>::read
  22: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  23: <DB as hir_ty::db::HirDatabase>::trait_impls_in_crate::__shim
  24: hir::Impl::all_for_type
  25: ide_assists::handlers::generate_delegate_trait::Field::new
  26: ide_assists::handlers::generate_delegate_trait::generate_delegate_trait
  27: ide_assists::assists
  28: std::panicking::try
  29: ide::Analysis::assists_with_fixes
  30: rust_analyzer::handlers::request::handle_code_action
  31: std::panicking::try
  32: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@95th
Copy link

95th commented Oct 1, 2023

Code in my main.rs:

fn main() {
    println!("Hello, world!");
}


struct AppState {
    url: String,
    method: // I am typing here
}

@zhixinwen
Copy link

similar error:

thread 'Worker' panicked at crates/hir-def/src/nameres/path_resolution.rs:431:37:
index out of bounds: the len is 4 but the index is 5
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: hir_def::nameres::path_resolution::<impl hir_def::nameres::DefMap>::resolve_path_fp_with_macro_single
   4: hir_def::resolver::ModuleItemMap::resolve_path_in_type_ns
   5: hir_def::resolver::Resolver::resolve_path_in_type_ns
   6: hir_ty::lower::TyLoweringContext::lower_ty_ext
   7: hir_ty::lower::impl_self_ty_query
   8: salsa::runtime::Runtime::execute_query_implementation
   9: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  10: salsa::derived::slot::Slot<Q,MP>::read
  11: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  12: salsa::QueryTable<Q>::get
  13: <DB as hir_ty::db::HirDatabase>::impl_self_ty
  14: hir_ty::lower::impl_trait_query
  15: salsa::runtime::Runtime::execute_query_implementation
  16: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  17: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  18: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  19: salsa::derived::slot::MemoRevisions::validate_memoized_value
  20: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  21: salsa::derived::slot::Slot<Q,MP>::read
  22: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  23: <DB as hir_ty::db::HirDatabase>::trait_impls_in_crate::__shim
  24: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  25: hir_ty::method_resolution::TraitImpls::trait_impls_in_deps_query
  26: salsa::runtime::Runtime::execute_query_implementation
  27: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  28: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  29: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  30: salsa::derived::slot::MemoRevisions::validate_memoized_value
  31: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  32: salsa::derived::slot::Slot<Q,MP>::read
  33: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  34: salsa::QueryTable<Q>::get
  35: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  36: hir_ty::db::trait_solve_wait
  37: hir_ty::infer::coerce::<impl hir_ty::infer::unify::InferenceTable>::coerce_inner
  38: hir_ty::infer::coerce::<impl hir_ty::infer::unify::InferenceTable>::coerce
  39: hir_ty::infer::coerce::<impl hir_ty::infer::InferenceContext>::coerce
  40: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  41: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  42: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  43: hir_ty::infer::infer_query
  44: salsa::runtime::Runtime::execute_query_implementation
  45: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  46: salsa::derived::slot::Slot<Q,MP>::read
  47: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  48: <DB as hir_ty::db::HirDatabase>::infer_query::__shim
  49: hir_ty::db::infer_wait
  50: hir::DefWithBody::diagnostics
  51: hir::ModuleDef::diagnostics
  52: hir::Module::diagnostics
  53: ide_diagnostics::diagnostics
  54: salsa::Cancelled::catch
  55: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  56: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
  57: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'LspServer' panicked at /Users/runner/work/rust-analyzer/rust-analyzer/crates/stdx/src/thread/pool.rs:86:35:
called `Result::unwrap()` on an `Err` value: "SendError(..)"

@Veykril
Copy link
Member

Veykril commented Apr 30, 2025

Closing this as presumably a salsa bug which should be fixed now

@Veykril Veykril closed this as completed Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-nameres name, path and module resolution Broken Window Bugs / technical debt to be addressed immediately I-panic
Projects
None yet
Development

No branches or pull requests