rust-lang / rust-analyzer

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

rust-analyzer panic when call `callHierarchy/outgoingCalls` #17762

Open eval-exec opened 2 months ago

eval-exec commented 2 months ago

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P) 1.81.0-nightly (9c3bc80 2024-06-27) rustc version: (eg. output of rustc -V)

rustc 1.81.0-nightly (9c3bc805d 2024-06-27)
binary: rustc
commit-hash: 9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9
commit-date: 2024-06-27
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable) Emacs with lsp-mode.el relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): (eg. rust-analyzer) https://github.com/BurntSushi/ripgrep/blob/master/crates/core/messages.rs#L124

code snippet to reproduce:

  1. Put cursor on https://github.com/BurntSushi/ripgrep/blob/master/crates/core/messages.rs#L124
  2. call callHierarchy/outgoingCalls will got the panci:
    
    Panic context:
    > 
    version: 1.81.0-nightly (9c3bc80 2024-06-27)
    request: callHierarchy/outgoingCalls CallHierarchyOutgoingCallsParams {
    item: CallHierarchyItem {
        name: "atomic_store",
        kind: Function,
        tags: None,
        detail: Some(
            "unsafe fn atomic_store<T>(dst: *mut T, val: T, order: Ordering)\nwhere\n    T: Copy,",
        ),
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/exec/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs",
            query: None,
            fragment: None,
        },
        range: Range {
            start: Position {
                line: 3292,
                character: 0,
            },
            end: Position {
                line: 3305,
                character: 1,
            },
        },
        selection_range: Range {
            start: Position {
                line: 3294,
                character: 10,
            },
            end: Position {
                line: 3294,
                character: 22,
            },
        },
        data: None,
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    }

thread 'Worker' panicked at /rust/deps/line-index-0.1.1/src/lib.rs:111:35: invalid offset stack backtrace: 0: 0x7fb87118c325 - std::backtrace_rs::backtrace::libunwind::trace::h07b28210221fdfcf at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x7fb87118c325 - std::backtrace_rs::backtrace::trace_unsynchronized::h57474388c6dca70e at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7fb87118c325 - std::sys::backtrace::_print_fmt::hf65679b3b8aa3de9 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/sys/backtrace.rs:68:5 3: 0x7fb87118c325 - ::fmt::h3b74abb4c59b311d at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/sys/backtrace.rs:44:22 4: 0x7fb8711dbeeb - core::fmt::rt::Argument::fmt::h2e8bf0997b20ef74 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/core/src/fmt/rt.rs:165:63 5: 0x7fb8711dbeeb - core::fmt::write::h411a68a005ab8995 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/core/src/fmt/mod.rs:1168:21 6: 0x7fb871180fbf - std::io::Write::write_fmt::he4dc34d02cbce267 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/io/mod.rs:1835:15 7: 0x7fb87118c0fe - std::sys::backtrace::_print::ha6b310959102561f at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/sys/backtrace.rs:47:5 8: 0x7fb87118c0fe - std::sys::backtrace::print::h85fe5852cea7cec8 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/sys/backtrace.rs:34:9 9: 0x7fb87118ea49 - std::panicking::default_hook::{{closure}}::ha3c5796eabdb9549 10: 0x7fb87118e7ec - std::panicking::default_hook::hd5d9e6ee76a17e6c at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/panicking.rs:292:9 11: 0x55bf6013f4b2 - <stdx[6ea13dea3eae90fa]::panic_context::PanicContext>::init::{closure#0} 12: 0x7fb87118f31f - <alloc::boxed::Box<F,A> as core::ops::function::Fn>::call::hd3484a16c3465019 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/alloc/src/boxed.rs:2078:9 13: 0x7fb87118f31f - std::panicking::rust_panic_with_hook::hf1adc754e9701eca at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/panicking.rs:804:13 14: 0x7fb87118ef47 - std::panicking::begin_panic_handler::{{closure}}::hee50761a1b454f3e at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/panicking.rs:670:13 15: 0x7fb87118c7e9 - std::sys::backtrace::rust_end_short_backtrace::h54a0955362eadbbb at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/sys/backtrace.rs:171:18 16: 0x7fb87118ec24 - rust_begin_unwind at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/panicking.rs:661:5 17: 0x7fb8711d84a3 - core::panicking::panic_fmt::h55e93124dd288cd7 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/core/src/panicking.rs:74:14 18: 0x7fb8711d82db - core::panicking::panic_display::ha354ffe96c543f97 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/core/src/panicking.rs:264:5 19: 0x7fb8711d82db - core::option::expect_failed::h7aa7b38d428aaaec at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/core/src/option.rs:2023:5 20: 0x55bf5f91ba51 - <line_index[5872198562828a97]::LineIndex>::line_col 21: 0x55bf5f1512a9 - rust_analyzer[36e1672cec1b44b9]::lsp::to_proto::range 22: 0x55bf5f109bad - rust_analyzer[36e1672cec1b44b9]::handlers::request::handle_call_hierarchy_outgoing 23: 0x55bf5ef8b070 - <<stdx[6ea13dea3eae90fa]::thread::pool::Pool>::spawn<<rust_analyzer[36e1672cec1b44b9]::task_pool::TaskPool<rust_analyzer[36e1672cec1b44b9]::main_loop::Task>>::spawn<<rust_analyzer[36e1672cec1b44b9]::dispatch::RequestDispatcher>::on_with_thread_intent<true, false, lsp_types[bff49e2f37f6d3b7]::request::CallHierarchyOutgoingCalls>::{closure#0}>::{closure#0}>::{closure#0} as core[d16126bd6b552dfc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 24: 0x55bf6013c291 - std[74439f15b62b8a55]::sys::backtrace::rust_begin_short_backtrace::<<stdx[6ea13dea3eae90fa]::thread::Builder>::spawn<<stdx[6ea13dea3eae90fa]::thread::pool::Pool>::new::{closure#0}, ()>::{closure#0}, ()> 25: 0x55bf6013d3e2 - <<std[74439f15b62b8a55]::thread::Builder>::spawnunchecked<<stdx[6ea13dea3eae90fa]::thread::Builder>::spawn<<stdx[6ea13dea3eae90fa]::thread::pool::Pool>::new::{closure#0}, ()>::{closure#0}, ()>::{closure#2} as core[d16126bd6b552dfc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 26: 0x7fb8711991ab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once::h1961d6f9f91f3c82 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/alloc/src/boxed.rs:2064:9 27: 0x7fb8711991ab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once::hde4b94e543ba1278 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/alloc/src/boxed.rs:2064:9 28: 0x7fb8711991ab - std::sys::pal::unix::thread::Thread::new::thread_start::h726d268d34ef4439 at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/sys/pal/unix/thread.rs:108:17 29: 0x7fb870e90272 - start_thread 30: 0x7fb870f0bdec - clone3 31: 0x0 -

lnicola commented 2 months ago

Can't reproduce with a recent version and VS Code, can you try using https://github.com/rust-lang/rust-analyzer/releases/download/nightly/rust-analyzer-x86_64-unknown-linux-gnu.gz instead of the rustup component?

eval-exec commented 2 months ago

Can't reproduce with a recent version and VS Code, can you try using https://github.com/rust-lang/rust-analyzer/releases/download/nightly/rust-analyzer-x86_64-unknown-linux-gnu.gz instead of the rustup component?

I used the rust-analyzer your provided, it panic too:

❯ ./rust-analyzer --version
rust-analyzer 0.4.2057-standalone
Panic context:
> 
version: 0.4.2057-standalone
request: callHierarchy/outgoingCalls CallHierarchyOutgoingCallsParams {
    item: CallHierarchyItem {
        name: "atomic_store",
        kind: Function,
        tags: None,
        detail: Some(
            "unsafe fn atomic_store<T>(dst: *mut T, val: T, order: Ordering)\nwhere\n    T: Copy,",
        ),
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/exec/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs",
            query: None,
            fragment: None,
        },
        range: Range {
            start: Position {
                line: 3292,
                character: 0,
            },
            end: Position {
                line: 3305,
                character: 1,
            },
        },
        selection_range: Range {
            start: Position {
                line: 3294,
                character: 10,
            },
            end: Position {
                line: 3294,
                character: 22,
            },
        },
        data: 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.1/src/lib.rs:111:35:
invalid offset
stack backtrace:
   0:     0x557f5f06c6cb - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3692694645b1bb6a
   1:     0x557f5dba764b - core::fmt::write::h5131d80b4c69b88d
   2:     0x557f5f0688a3 - std::io::Write::write_fmt::h1fb327a7d8b0eb36
   3:     0x557f5f06c43e - std::sys_common::backtrace::print::h998d75b840f75a73
   4:     0x557f5f06e116 - std::panicking::default_hook::{{closure}}::h18ec7fe6a38b9da0
   5:     0x557f5f06de35 - std::panicking::default_hook::hfb3f22c2e4075a6a
   6:     0x557f5f090e52 - stdx::panic_context::PanicContext::init::{{closure}}::h2c29768384586c53
   7:     0x557f5f06e74b - std::panicking::rust_panic_with_hook::h51af00bcb4660c4e
   8:     0x557f5f06e4f4 - std::panicking::begin_panic_handler::{{closure}}::h39f76aa863fbe8ce
   9:     0x557f5f06cb99 - std::sys_common::backtrace::__rust_end_short_backtrace::h4d10fc2251b89840
  10:     0x557f5f06e257 - rust_begin_unwind
  11:     0x557f5da42a33 - core::panicking::panic_fmt::h319840fcbcd912ef
  12:     0x557f5da429fb - core::option::expect_failed::h1726eaf02b540434
  13:     0x557f5ed4249b - rust_analyzer::lsp::to_proto::range::h289531fdafc8a2ee
  14:     0x557f5ebbcf7a - alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter::hb6b503b55d7ef03b
  15:     0x557f5ed1234d - rust_analyzer::handlers::request::handle_call_hierarchy_outgoing::h711545a5c2bc4fe3
  16:     0x557f5ef31474 - std::panicking::try::h68d70f666145fcf0
  17:     0x557f5ee5f2fa - core::ops::function::FnOnce::call_once{{vtable.shim}}::h76410eae3db8e129
  18:     0x557f5f08eb46 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb17c3634218202f2
  19:     0x557f5f08e1f6 - core::ops::function::FnOnce::call_once{{vtable.shim}}::he2e5b9186ce57935
  20:     0x557f5f07310b - std::sys::pal::unix::thread::Thread::new::thread_start::h3b8e81128811868f
  21:     0x7f7fe0f4d272 - start_thread
  22:     0x7f7fe0fc8dec - __GI___clone3
  23:                0x0 - <unknown>

Process rust-analyzer stderr finished
eval-exec commented 2 months ago

Can't reproduce with a recent version and VS Code, can you try using https://github.com/rust-lang/rust-analyzer/releases/download/nightly/rust-analyzer-x86_64-unknown-linux-gnu.gz instead of the rustup component?

After you call callHierarchy/outgoingCalls, you can try expand the child nodes.

eval-exec commented 2 months ago

Can you reproduce, if you put cursor on /home/exec/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:3295 (put cursor on atomic_store) then call callHierarchy/outgoingCalls ?


#[inline]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
unsafe fn atomic_store<T: Copy>(dst: *mut T, val: T, order: Ordering) {
    // SAFETY: the caller must uphold the safety contract for `atomic_store`.
    unsafe {
        match order {
            Relaxed => intrinsics::atomic_store_relaxed(dst, val),
            Release => intrinsics::atomic_store_release(dst, val),
            SeqCst => intrinsics::atomic_store_seqcst(dst, val),
            Acquire => panic!("there is no such thing as an acquire store"),
            AcqRel => panic!("there is no such thing as an acquire-release store"),
        }
    }
}
lnicola commented 2 months ago

Looks like ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs has some smart quotes at line 31, can you check if you're running a recent version of lsp-mode?

Or can you try replace those quotes, then restart? Cf.