rust-lang / rust-lang/rust-analyzer

Panics with "invalid offset" errors ( code: -32603) on "Go to definition" calls

Open
#22,482 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: 0.3.2896

rustc version: rustc 1.95.0 (59807616e 2026-04-14)

editor: both VSCode and Zed

OS / Distro: Ubuntu 24.04 (WSL2) and Ubuntu 25.10

repository link: libpnet

Hi, I encountered an rust-analyzer panic when trying to go to any pnet::packet::*::*Packet packet abstraction struct implementation. Example:

// ...
let ethernet_frame = EthernetPacket::new(&packet).unwrap();
if ethernet_frame.get_ethertype() == EtherTypes::Ipv4 { ... }

when I try to peek the get_ethertype definition I get the following error:

thread 'Worker1' (13429) panicked at /github/home/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/line-index-0.1.2/src/lib.rs:111:35:
invalid offset
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::option::expect_failed
   3: line_index::LineIndex::line_col
   4: rust_analyzer::lsp::to_proto::position
   5: rust_analyzer::lsp::to_proto::location_info
   6: rust_analyzer::lsp::to_proto::location_link
   7: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
   8: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::next
   9: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  10: core::iter::adapters::try_process
  11: rust_analyzer::lsp::to_proto::goto_definition_response
  12: rust_analyzer::handlers::request::handle_goto_definition
  13: core::ops::function::FnOnce::call_once{{vtable.shim}}
  14: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
additional context:
   0: 
version: 0.3.2896-standalone
request: textDocument/definition GotoDefinitionParams {
    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: ".../src/main.rs",
                query: None,
                fragment: None,
            },
        },
        position: Position {
            line: 105,
            character: 26,
        },
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
}

[Error - 6:47:32 PM] Request textDocument/definition failed.
  Message: request handler panicked: invalid offset
  Code: -32603

Seems like the custom derive(Packet) messes with rust-analyzer lsp

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the panic with libpnet by using Go to definition on a Packet method such as get_ethertype. Start with the stack frames in line-index-0.1.2/src/lib.rs and rust_analyzer::lsp::to_proto::position/location_link, then trace the textDocument/definition handler. Done means the request returns a valid definition location without an invalid-offset panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.