Skip to content

Unreachable code in crate inside a workspace causes rust-analyzer to crash #15099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dp1 opened this issue Jun 21, 2023 · 0 comments · Fixed by #15104
Closed

Unreachable code in crate inside a workspace causes rust-analyzer to crash #15099

dp1 opened this issue Jun 21, 2023 · 0 comments · Fixed by #15104
Assignees
Labels
C-bug Category: bug

Comments

@dp1
Copy link

dp1 commented Jun 21, 2023

rust-analyzer version: 0.3.1557-standalone

rustc version: rustc 1.70.0 (90c541806 2023-05-31)

relevant settings: All default settings

Hi,
I am hitting a crash in rust-analyzer with some unreachable code inside a crate, which is part of a workspace. I minimized it to the following setup, with no dependencies:

.
├── Cargo.toml
└── ra-crash
    ├── Cargo.toml
    └── src
        └── lib.rs

Cargo.toml

[workspace]
resolver = "2"
members = [
    "ra-crash",
]

ra-crash/Cargo.toml

[package]
name = "ra-crash"
version = "0.1.0"
edition = "2021"

[dependencies]

ra-crash/src/lib.rs

pub fn f() {
    panic!();
    for _ in 0..2 {}
}

When opening the project in vscode, and when clicking/modifying lib.rs in any way, I get this stacktrace:

Panic context:
> publish_diagnostics

thread 'Worker' panicked at 'called `Result::unwrap()` on an `Err` value: SyntheticSyntax', crates/hir/src/lib.rs:2823:61
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
   2: core::result::unwrap_failed
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/result.rs:1687:5
   3: hir::Local::primary_source
   4: ide_diagnostics::handlers::mutability_errors::unused_mut
   5: ide_diagnostics::diagnostics
   6: std::panicking::try
   7: ide::Analysis::diagnostics
   8: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
   9: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
  10: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

The crash happens at an unwrap() with a suspicious looking comment: https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir/src/lib.rs#L2823

The same behaviour happens with a binary crate (renaming lib.rs to main.rs), but it does not crash if the crate is by itself and not inside a workspace. Commenting out the panic!() call also stops the crash from happening.

I'm happy to help to get this fixed, but have never touched the rust-analyzer codebase, so I'd need a few pointers to fix this on my own (and it might be faster if someone else is available to work on it). Please let me know if/how I should provide more details as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants