rust-analyzer: Popups about language server requests failing

Every few minutes I keep getting popups in VSCode about textDocument/documentHighlight, textDocument/inlayHint etc failing. The log shows the following:


thread 'Worker' panicked at crates/hir-def/src/attr.rs:368:40:
index out of bounds: the len is 4 but the index is 9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_bounds_check
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:180:5
   3: hir_def::attr::AttrsWithOwner::attrs_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>::read
  11: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  12: <DB as hir_def::db::DefDatabase>::import_map::__shim
  13: hir_def::find_path::calculate_best_path
  14: hir_def::find_path::find_path_for_module
  15: hir_def::find_path::calculate_best_path
  16: hir_def::find_path::find_path_inner
  17: hir_def::find_path::find_path
  18: <chalk_ir::Ty<hir_ty::interner::Interner> as hir_ty::display::HirDisplay>::hir_fmt
  19: hir_ty::display::HirDisplay::display_source_code
  20: ide::inlay_hints::ty_to_text_edit
  21: ide::inlay_hints::bind_pat::hints
  22: ide::inlay_hints::hints
  23: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  24: ide::inlay_hints::inlay_hints
  25: salsa::Cancelled::catch
  26: rust_analyzer::handlers::request::handle_inlay_hints
  27: std::panicking::try
  28: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 11:57:44] Request textDocument/inlayHint failed.
  Message: request handler panicked: index out of bounds: the len is 4 but the index is 9
  Code: -32603 
Panic context:
> 
version: 0.3.1740-standalone
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/tmgarn/.rustup/toolchains/1.74.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs",
            query: None,
            fragment: None,
        },
    },
    position: Position(
        Position {
            line: 36,
            character: 10,
        },
    ),
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
}


thread 'Worker' panicked at crates/hir-def/src/nameres/path_resolution.rs:422:37:
index out of bounds: the len is 2 but the index is 2
stack backtrace:
   0: rust_begin_unwind
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_bounds_check
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:180:5
   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_trait
  25: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  26: <core::iter::adapters::flatten::Flatten<I> as core::iter::traits::iterator::Iterator>::next
  27: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  28: ide::goto_implementation::goto_implementation
  29: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  30: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  31: rust_analyzer::handlers::request::handle_hover
  32: std::panicking::try
  33: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 12:00:38] Request textDocument/hover failed.
  Message: request handler panicked: index out of bounds: the len is 2 but the index is 2
  Code: -32603 
Panic context:
> 
version: 0.3.1740-standalone
request: textDocument/documentHighlight DocumentHighlightParams {
    text_document_position_params: TextDocumentPositionParams {
        text_document: TextDocumentIdentifier {
            uri: Url {
                scheme: "file",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: None,
                port: None,
                path: "/home/tmgarn/workspace/acms_application_shell/services/web/backend/src/drillplan/models.rs",
                query: None,
                fragment: None,
            },
        },
        position: Position {
            line: 29,
            character: 66,
        },
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
}

thread 'Worker' panicked at /github/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rowan-0.15.11/src/cursor.rs:751:9:
Bad offset: range 0..800 offset 801
stack backtrace:
   0: rust_begin_unwind
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
   2: rowan::cursor::SyntaxNode::token_at_offset
   3: ide::highlight_related::highlight_related
   4: std::panicking::try
   5: rust_analyzer::handlers::request::handle_document_highlight
   6: std::panicking::try
   7: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 13:12:46] Request textDocument/documentHighlight failed.
  Message: request handler panicked: Bad offset: range 0..800 offset 801
  Code: -32603 

I don’t know what exactly I’m doing to make it happen. I think possibly it happens when rebasing things in git in another terminal window sometimes? Sometimes when I’m reading documentation and not doing anything with the code. Sometimes when I’m writing or refactoring code.

It doesn’t seem to me like anything is actually broken in the user experience. Apart from the popups themselves that is.

Unfortunately the code base I’m working on that is causing this is not open source (so I can’t link it), but it is basically a graph QL micro service that makes GRPC requests as it’s backend. It uses axum, tonic, prost, tower, async-graphql and tracing.

rust-analyzer version: 0.3.1740-standalone

rustc version: rustc 1.74.0 (79e9716c9 2023-11-13) (installed with rustup)

OS: Ubuntu 22.04, using KDE Plasma as my desktop environment

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

I am using the following workspace config (this is a mixed language project, only a small part is Rust currently, most of it is legacy C++ with CMake) as there is no Cargo.toml in the workspace root:

{
    "rust-analyzer.linkedProjects": [
        "services/web/backend/Cargo.toml"
    ]
}

In the user level VSCode settings I have:

    "rust-analyzer.diagnostics.warningsAsInfo": [
        "dead_code"
    ],
    "rust-analyzer.assist.emitMustUse": true,

(the former makes a lot of sense since I tend to write code bottom up and it gets annoying otherwise)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (7 by maintainers)

Most upvoted comments

The same error happens when working on the open-source deno codebase. I often have both https://github.com/denoland/deno and https://github.com/denoland/deno_core checked out, and the language server will often crash with this error.


> impl_trait_query(ImplId(173247) -> ItemLoc { container: ModuleId { krate: Idx::<CrateData>(62), block: None, local_id: Idx::<ModuleData>(2) }, id: ItemTreeId { tree: TreeId { file: FileId(FileId(906)), block: None }, value: Idx::<Impl>(0) } } -> ImplData { target_trait: None, self_ty: Path(Normal { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("StrippedStr"))] }, generic_args: Some([Some(GenericArgs { args: [Lifetime(LifetimeRef { name: Name(Text("'s")) })], has_self_type: false, bindings: [], desugared_from_fn: false })]) }), items: [FunctionId(FunctionId(190416)), FunctionId(FunctionId(190417))], is_negative: false, is_unsafe: false, attribute_calls: None })

> impl_self_ty_query(ImplId(173247) -> ItemLoc { container: ModuleId { krate: Idx::<CrateData>(62), block: None, local_id: Idx::<ModuleData>(2) }, id: ItemTreeId { tree: TreeId { file: FileId(FileId(906)), block: None }, value: Idx::<Impl>(0) } } -> ImplData { target_trait: None, self_ty: Path(Normal { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("StrippedStr"))] }, generic_args: Some([Some(GenericArgs { args: [Lifetime(LifetimeRef { name: Name(Text("'s")) })], has_self_type: false, bindings: [], desugared_from_fn: false })]) }), items: [FunctionId(FunctionId(190416)), FunctionId(FunctionId(190417))], is_negative: false, is_unsafe: false, attribute_calls: None })

thread 'Worker' panicked at crates/hir-def/src/nameres/path_resolution.rs:422:37:
index out of bounds: the len is 2 but the index is 2
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>::read
  29: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  30: salsa::QueryTable<Q>::get
  31: <DB as hir_ty::db::HirDatabase>::trait_impls_in_deps
  32: hir_ty::chalk_db::<impl chalk_solve::RustIrDatabase<hir_ty::interner::Interner> for hir_ty::traits::ChalkContext>::impls_for_trait
  33: chalk_solve::clauses::program_clauses_that_could_match
  34: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  35: chalk_recursive::solve::SolveIteration::solve_iteration
  36: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  37: <chalk_recursive::recursive::RecursiveSolver<I> as chalk_solve::solve::Solver<I>>::solve_limited
  38: hir_ty::traits::solve::{{closure}}
  39: hir_ty::traits::trait_solve_query
  40: salsa::runtime::Runtime::execute_query_implementation
  41: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  42: salsa::derived::slot::Slot<Q,MP>::read
  43: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  44: salsa::QueryTable<Q>::get
  45: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  46: hir_ty::db::trait_solve_wait
  47: hir_ty::infer::unify::InferenceTable::try_obligation
  48: hir_ty::autoderef::deref_by_trait
  49: hir_ty::autoderef::autoderef_step
  50: <hir_ty::autoderef::Autoderef as core::iter::traits::iterator::Iterator>::next
  51: hir_ty::method_resolution::autoderef_method_receiver
  52: hir_ty::method_resolution::iterate_method_candidates_dyn
  53: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  54: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  55: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  56: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  57: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  58: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  59: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  60: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  61: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  62: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_return
  63: hir_ty::infer::infer_query
  64: salsa::runtime::Runtime::execute_query_implementation
  65: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  66: salsa::derived::slot::Slot<Q,MP>::read
  67: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  68: <DB as hir_ty::db::HirDatabase>::infer_query::__shim
  69: hir_ty::db::infer_wait
  70: hir::source_analyzer::SourceAnalyzer::new_for_body
  71: hir::semantics::SemanticsImpl::analyze_impl
  72: ide_db::defs::NameRefClass::classify
  73: ide_db::search::FindUsages::found_name_ref
  74: ide_db::search::FindUsages::search
  75: ide_assists::handlers::inline_call::inline_into_callers
  76: ide_assists::assists
  77: std::panicking::try
  78: ide::Analysis::assists_with_fixes
  79: rust_analyzer::handlers::request::handle_code_action
  80: std::panicking::try
  81: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

There is a known regression wrt to include! https://github.com/rust-lang/rust-analyzer/issues/16109 which is caused by the tokenmap rewrite, but i haven’t looked into it yet.