rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.31k stars 1.62k forks source link

Panic (Code: -32603) when editing proc-macro invocation #18513

Closed NekoiNemo closed 5 days ago

NekoiNemo commented 1 week ago

rust-analyzer version: 0.3.2180-standalone

rustc version: 1.82.0 (f6e511eec 2024-10-15)

editor or extension: VSCode, v0.3.2180

Attempting to write/edit procedural macro invocation causes a immediate crash of RA

code snippet to reproduce:

[dependencies]
log = "0.4"
fn main() {
    log::error!("foo // attempting to finish this line will cause the panic
}

Log

Panic context:
> 
version: 0.3.2180-standalone
request: textDocument/diagnostic DocumentDiagnosticParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/nekoinemo/projects/ra_fail/src/main.rs",
            query: None,
            fragment: None,
        },
    },
    identifier: None,
    previous_result_id: None,
    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/line-index-0.1.2/src/lib.rs:111:35:
invalid offset
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::option::expect_failed
   3: rust_analyzer::lsp::to_proto::range
   4: rust_analyzer::diagnostics::convert_diagnostic
   5: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
   6: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
   7: rust_analyzer::handlers::request::handle_document_diagnostics
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 23:14:02] Request textDocument/diagnostic failed.
  Message: request handler panicked: invalid offset
  Code: -32603 
[Error - 23:14:02] Document pull failed for text document file:///home/nekoinemo/projects/ra_fail/src/main.rs
  Message: request handler panicked: invalid offset
  Code: -32603
NekoiNemo commented 1 week ago

Downgraded extension to v0.3.2154 and this no longer happens. Seems like the issue started with 2162

ChayimFriedman2 commented 1 week ago

@rustbot claim

ChayimFriedman2 commented 5 days ago

BTW this is not a proc macro, it's a declarative macro.