rust-analyzer: cargo check failed

Type: Bug

Since today I keep getting an error when I save from the rust analyzer: “cargo check failed Check the server log for additional information”

It seems that the rust analyzer runs cargo check on my directory folder that doesn’t have cargo.toml like locality instead of the folders inside that have it like array2 file or ppmtrans …

Here is the error

[ERROR flycheck] Flycheck failed to run the following command: “cargo” “check” “–workspace” “–message-format=json” “–all-targets”

[ERROR rust_analyzer::lsp_utils] cargo check failed

Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(25856))):

error: could not find Cargo.toml in /Users/librarypatron/locality or any parent directory

Extension version: 0.3.1258 VS Code version: Code 1.72.2 (Universal) (d045a5eda657f4d7b676dedbfa7aab8207f8a075, 2022-10-12T22:16:30.254Z) OS version: Darwin x64 21.6.0 Modes: Sandboxed: No

System Info
Item Value
CPUs Intel® Core™ i5-7360U CPU @ 2.30GHz (4 x 2300)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 4, 4, 3
Memory (System) 8.00GB (0.25GB free)
Process Argv –crash-reporter-id 6d46b371-7dc6-41fc-89d8-01f75f4f4a74
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
i497e931:30553904
pyindex848:30577860
nodejswelcome1:30587005
fc301958:30573243

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 18
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Can you check if the latest pre-release works? The fix for this unfortunately didn’t make it into the stable release

Same problem on Arch Linux. Was tried @trickster solution and it does not work.

This should be fixed on the latest stable release now, if you still have this problem please open a new issue with appropriate details (of your project structure and whether it used to work 2 versions ago)

@Veykril switch to pre-release version only makes the error gone, but rust-analyzer still doesn’t work. all features includes inlay hints / code completion / goto xxx is unavailable

tested under Windows 11 ra version: v0.3.1258 vscode version:

Version: 1.72.2 (user setup)
Commit: d045a5eda657f4d7b676dedbfa7aab8207f8a075
Date: 2022-10-12T22:15:18.074Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22623
Sandboxed: No

open demo folder with the following structure

this works

- demo
  - Cargo.toml

and this not

- demo
  - other-rust-app
    - Cargo.toml 

Stumbled across the same issue today. The pre-release version works fine though.

The pre-release version appears to work on Windows 10 after doing a window reload. I saw the same issue with stable.

Extension version: v0.4.1259 (pre-release)

Version: 1.72.2 (user setup)
Commit: d045a5eda657f4d7b676dedbfa7aab8207f8a075
Date: 2022-10-12T22:15:18.074Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No

I had the same issue.

Running these solved the issue for me.

rustup component add rustfmt
rustup component add clippy