Skip to content

Index out of bounds panic on "Find all references" #10090

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
charlespierce opened this issue Aug 30, 2021 · 4 comments · Fixed by #10212
Closed

Index out of bounds panic on "Find all references" #10090

charlespierce opened this issue Aug 30, 2021 · 4 comments · Fixed by #10212
Assignees
Labels
A-ty type system / type inference / traits / method resolution

Comments

@charlespierce
Copy link
Contributor

On some elements in my code base, running "Find all references" causes a panic with the following message:

Panic context:
> 
version: d15f646ff 2021-08-30 stable
request: textDocument/references ReferenceParams {
    text_document_position: TextDocumentPositionParams {
        text_document: TextDocumentIdentifier {
            uri: Url {
                scheme: "file",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: None,
                port: None,
                path: "redacted.rs",
                query: None,
                fragment: None,
            },
        },
        position: Position {
            line: 368,
            character: 21,
        },
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    context: ReferenceContext {
        include_declaration: true,
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.70.0/src/lib.rs:2752:10
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <&chalk_ir::SubstFolder<I,A> 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::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   6: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   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>::check_call_arguments
  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_coerce
  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: rowan::utility_types::TokenAtOffset<T>::map
  26: ide_db::search::FindUsages::search
  27: ide::references::find_all_refs
  28: std::panicking::try
  29: rust_analyzer::handlers::handle_references
  30: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}}::{{closure}}
  31: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 1:14:23 PM] Request textDocument/references failed.
  Message: server panicked: index out of bounds: the len is 1 but the index is 1
  Code: -32603 

Unfortunately, this is a fairly complicated internal project, so I can't find a minimal reproduction or share the code itself 🙁 That said, one thing I noticed is that this works on an older version of R-A (0.2.702), but started failing on the release after that.

@bjorn3 bjorn3 added the A-ty type system / type inference / traits / method resolution label Aug 30, 2021
@ghost
Copy link

ghost commented Aug 31, 2021

same bug on find-references request

@charlespierce
Copy link
Contributor Author

If it helps to triage, I just did a git bisect between the two versions and it looks like this commit is where the behavior changes: e89ad9f

Note: The failure mode in that commit appears to be an infinite hang, rather than a panic that gets reported, in later commits it becomes a panic that shows a message.

@flodiebold flodiebold self-assigned this Sep 4, 2021
@maxbrunsfeld
Copy link

I'm seeing a similar stack trace, but while editing, instead of while running "find all references".

thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.70.0/src/lib.rs:2752:10
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <&chalk_ir::SubstFolder<I,A> 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::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   6: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   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_coerce
  10: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  11: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  12: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  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
  15: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  16: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  17: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  18: hir_ty::infer::infer_query
  19: salsa::runtime::Runtime::execute_query_implementation
  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>::infer_query
  24: hir_ty::db::infer_wait
  25: hir::DefWithBody::diagnostics
  26: hir::Module::diagnostics
  27: ide_diagnostics::diagnostics
  28: ide::Analysis::assists_with_fixes::{{closure}}
  29: std::panicking::try
  30: rust_analyzer::handlers::handle_code_action
  31: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}}::{{closure}}
  32: <F as threadpool::FnBox>::call_box

@maxbrunsfeld
Copy link

If it helps to triage, I just did a git bisect between the two versions and it looks like this commit is where the behavior changes: e89ad9f

Thanks @charlespierce. After reverting that commit and building locally, this error has not happened for me.

bors bot added a commit that referenced this issue Sep 12, 2021
10212: fix: Avoid type inference panic on bitslice methods r=flodiebold a=flodiebold

Should fix #10090, fix #10046, and fix #10179.
This is only a workaround, but the proper fix requires some bigger
refactoring (also related to fixing #10058), and this at least prevents
the crash.

Co-authored-by: Florian Diebold <[email protected]>
@bors bors bot closed this as completed in a2d9f7d Sep 12, 2021
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants