rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
95.68k stars 12.33k forks source link

`cargo check --workspace` randomly crashes during invocations made by rust-analyzer vscode-extension #127642

Open archaephyrryx opened 3 weeks ago

archaephyrryx commented 3 weeks ago

Meta

rustc --version --verbose:

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

Error output

2024-07-12T06:49:54.002776Z ERROR flycheck: Flycheck failed to run the following command: CommandHandle { program: "<HOME_DIRECTORY>/.cargo/bin/cargo", arguments: ["check", "--workspace", "--message-format=json-diagnostic-rendered-ansi", "--manifest-path", "<PATH_TO_PROJECT>/./Cargo.toml", "--all-targets"], current_dir: Some("<PATH_TO_PROJECT>") }, error=Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(25856))):
    Checking <PROJECT_NAME> v0.1.0 (<PATH_TO_PROJECT>)
thread 'rustc' panicked at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/compiler/rustc_query_system/src/dep_graph/serialized.rs:192:9:
assertion `left == right` failed
  left: 13287424
 right: 0
stack backtrace:
thread 'rustc' panicked at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/compiler/rustc_query_system/src/dep_graph/serialized.rs:192:9:
assertion `left == right` failed
  left: 13901824
 right: 0
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:409:17
   3: core::panicking::assert_failed::<usize, usize>
   4: rustc_incremental::persist::load::setup_dep_graph
   5: <rustc_interface::queries::Queries>::global_ctxt
   6: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:409:17
   3: core::panicking::assert_failed::<usize, usize>
   4: rustc_incremental::persist::load::setup_dep_graph
   5: <rustc_interface::queries::Queries>::global_ctxt
   6: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: rustc 1.79.0 (129f3b996 2024-06-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: the compiler unexpectedly panicked. this is a bug.

note: rustc 1.79.0 (129f3b996 2024-06-10) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `<PROJECT NAME>` (lib test)
warning: build failed, waiting for other jobs to finish...
error: could not compile `<PROJECT_NAME>` (lib)
veera-sivarajan commented 3 weeks ago

Thank you for the report. Could you please add the code causing this crash.

@rustbot label +S-needs-repro

saethlin commented 3 weeks ago

This assertion detects when another process has corrupted the incremental compilation artifacts. Based on the issue title, it sounds like you're running cargo check at the same time as some IDE is also trying to run the compiler. That sounds bad, the two compilations are probably corrupting each other's output.

chenyukang commented 3 weeks ago

it's easy to get conflicted or hang when two processes are checking at the same time, so for the daily project I'm working on, this is my always setting:

"rust-analyzer.check.overrideCommand": [
        "cargo",
        "check",
        "--workspace",
        "--message-format=json",
        "--target-dir=/tmp/check-ckb",
    ],
bjorn3 commented 3 weeks ago

You can use "rust-analyzer.cargo.targetDir": true too. That will make rust-analyzer pick a subdirectory in target as target directory for all rust-analyzer invoked cargo commands.