rust-lang / rust-analyzer

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

Panic when trying to provide diagnostics #16796

Closed OleStrohm closed 4 months ago

OleStrohm commented 5 months ago

rust-analyzer version: rust-analyzer 2024-02-26

rustc version: rustc 1.75.0

relevant settings: This is on NixOS, and these are the latest unstable packages

repository link: https://github.com/OleStrohm/codecrafters-git-rust/tree/151cbf86149e5e06894f317a4573c806343732ed

Notes on setup: This is on NixOS, using the latest unstable packages for cargo, rustc, rust-analyzer etc. on a Neovim (v0.10.0-dev-39928a7) using the builtin lsp client.

How to reproduce: I haven't been able to isolate any individual thing that causes the issue to appear, but it works fine for a minute or two, but eventually it just stops giving any further diagnostics and then gives some errors that are similar to the ones below

RA Log:

LSP Log ```rust [START][2024-03-09 19:32:47] LSP logging initiated 2024-03-09T19:32:47.553380Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /build/rustc-1.75.0-src/library/core/src/slice/mod.rs 2024-03-09T19:32:47.553433Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /build/rustc-1.75.0-src/library/core/src/slice/mod.rs Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. 2024-03-09T19:32:51.873659Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /build/rustc-1.75.0-src/library/core/src/slice/mod.rs 2024-03-09T19:32:51.873858Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /build/rustc-1.75.0-src/library/core/src/slice/mod.rs 2024-03-09T19:32:53.466201Z ERROR rust_analyzer::dispatch: unknown request: Request { id: RequestId(I32(26)), method: "workspace/executeCommand", params: Object {"title": String("triggerParameterHints"), "command": String("rust-analyzer.triggerParameterHints")} } Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. 2024-03-09T19:32:53.658411Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /build/rustc-1.75.0-src/library/core/src/result.rs 2024-03-09T19:32:53.658638Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /build/rustc-1.75.0-src/library/core/src/result.rs 2024-03-09T19:32:53.685554Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /build/rustc-1.75.0-src/library/core/src/slice/mod.rs 2024-03-09T19:32:53.685823Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /build/rustc-1.75.0-src/library/core/src/slice/mod.rs Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: >::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Panic context: > fetch_native_diagnostics thread 'Worker' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/ra-ap-rustc_pattern_analysis/src/constructor.rs:947:63: called `Option::unwrap()` on a `None` value stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: ra_ap_rustc_pattern_analysis::constructor::ConstructorSet::split 4: ra_ap_rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness 5: ra_ap_rustc_pattern_analysis::usefulness::compute_match_usefulness 6: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect 7: hir::DefWithBody::diagnostics 8: hir::ModuleDef::diagnostics 9: hir::Module::diagnostics 10: ide_diagnostics::diagnostics 11: salsa::Cancelled::catch 12: ide::Analysis::with_db 13: ide::Analysis::diagnostics 14: core::ops::function::impls:: for &mut F>::call_mut 15: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter 16: rust_analyzer::diagnostics::fetch_native_diagnostics 17: core::ops::function::FnOnce::call_once{{vtable.shim}} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. thread 'LspServer' panicked at /build/source/crates/stdx/src/thread/pool.rs:86:35: called `Result::unwrap()` on an `Err` value: \"SendError(..)\" stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::result::unwrap_failed 3: stdx::thread::pool::Pool::spawn 4: rust_analyzer::task_pool::TaskPool::spawn 5: rust_analyzer::main_loop::::handle_event 6: rust_analyzer::main_loop::::run 7: rust_analyzer::main_loop::main_loop 8: rust_analyzer::run_server note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. thread '' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/lsp-server/src/stdio.rs:28:37: receiver was dropped, failed to send a message: \"SendError(..)\" stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::result::unwrap_failed note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. thread 'main' panicked at /build/rust-analyzer-unwrapped-2024-02-26-vendor.tar.gz/jod-thread/src/lib.rs:33:22: called `Result::unwrap()` on an `Err` value: Any { .. } stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::result::unwrap_failed 3: jod_thread::JoinHandle::join 4: rust_analyzer::with_extra_thread 5: rust_analyzer::main note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```
wyatt-herkamp commented 5 months ago

So the current version of Rust Analyzer is 2024-03-04. Could you try updating? I am unable to reproduce. But I am getting a regular compiler error due to split_once accepting a FnMut not a u8. I am on rust-analyzer version: 0.4.1874-standalone (2397e7a88 2024-03-08)

OleStrohm commented 5 months ago

The compiler warning doesn't matter too much, I didn't see it because RA wasn't working :P I managed to upgrade to rust-analyzer 1.78.0-nightly (46b180e 2024-03-08) (I also tested 2024-02-04, and it doesn't seem to panic, but I do have another issue which is that completion doesn't work at all, and there's a lot of errors like this in the log, which explain the issue at least:

[ERROR rust_analyzer::main_loop] flycheck 0: File with cargo diagnostic not found in VFS: file not found: /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/string.rs
[ERROR rust_analyzer::main_loop] flycheck 0: File with cargo diagnostic not found in VFS: file not found: /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/mod.rs

This might be a NixOS issue though, which makes it impossible to test whether this happens on those versions. I'll keep trying.

OleStrohm commented 5 months ago

Alright after a bit more difficulty I've managed to verify that I still run into this on rust-analyzer 1.78.0-nightly (46b180e 2024-03-08)

Adoni5 commented 4 months ago

I can confirm I have recently started seeing this as well. Ubuntu 2022, 1.76.0-stable

Veykril commented 4 months ago

There have been some fixes to exhaustiveness check panics. Please open a new issue with a new backtrace if you still run into this on the latest version.