Rust source disappeared

VSCode told me that racer crashed. When I restarted VSCode, it told me the rust-analyzer failed to load workspace and asked, "Is rust-src installed?" When I looked at the directory

~/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust

I saw that it only has .DS_Store, Cargo.lock, and library. No src.

I tried rustup component add rust-src and rustup update stable, but both said I was up to date. I also tried rustup component remove rust-src followed by rustup component add rust-src, but no source.

How do I get my rust source back? Will I lose anything important if I uninstall rust and reinstall it?

Check if the env var RUST_SRC_PATH is set and unset it if so. If you update rust-analyzer to today's release it should tell you to do so if that variable is set.

RUST_SRC_PATH was set. (I think I may have set it in an attempt to fix the problem.) I unset it and restarted VSCode, but I got the same notification,

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /Users/alan/Documents/Eclipse/multicell/userspace/actix_server/Cargo.toml. Is rust-src installed?: could not find libcore in sysroot path `/Users/alan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src` (`RUST_SRC_PATH` might be incorrect, try unsetting it)

The VSCode terminal shows that RUST_SRC_PATH is not set. I tried uninstalling and reinstalling rust-analyzer in VSCode, but that didn't fix the problem. VSCode says I am using v0.2.344. Is that the latest?

The odd thing is that the VSCode editor seems to be working correctly. I get autocomplete and syntax errors are highlighted. The only anomalies are the notification and the status bar saying Racer: Crashed. The instructions for rust-analyzer say it may cause conflicts with the official Rust plugin, so I disabled it. I lose highlighting of syntax errors, and I still get the notification.

The standard library moved to library/std in 1.47. racer might still be looking for the old path.

If the error contains this part, it means that the variable is still set.

(RUST_SRC_PATH might be incorrect, try unsetting it)

Good suggestions, @jyn514. How can I tell racer where to look? I tried changing rust.rustLangSrcPath in settings.json, and I get a slightly different notification.

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /Users/alan/Documents/Eclipse/multicell/userspace/actix_server/Cargo.toml. Is rust-src installed?: RUST_SRC_PATH must be absolute: 

@jschievink: RUST_SRC_PATH does not show up when I echo $RUST_SRC_PATH or when I env | grep RUST in the VSCode terminal.

No, your source code and everything will still be there, rustup only modifies the toolchain (compiler, tools, and documentation).

I don't know anything about racer so I can't help besides that, sorry.

In desperation, I uninstalled rust and reinstalled it. I then added the necessary components

rustup component add rust-src
rustup toolchain add nightly
cargo +nightly install racer
cargo install rustsym

I then shut down VScode and restarted it. I verified that RUST_SRC_PATH is not set, but I still get

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /Users/alan/Documents/Eclipse/multicell/userspace/cellagent/Cargo.toml. Is rust-src installed?: RUST_SRC_PATH must be absolute: 

and the status bar says Racer: Crashed.

I'm back where I started this thread, except no autocomplete doesn't show variables from my program. AAARRRGGGHHH!!!

Hi! The rust-analyzer extension does not use racer. Racer was the first attempt at providing autocomplete (correct me if I am wrong). Maybe you have two different rust ide support extensions installed?

racer is probably not updated anymore, because the official rls and rust-analyzer exist today.

In frustration, I took a (masked and socially distanced) walk. During my walk I remembered reading in the racer installation instructions that you could set RUST_SRC_PATH, but racer would find what it needed if you didn't. I realized that the environment variable wasn't set, but I had an entry for it in my settings.json. I removed that entry, restarted VSCode, and racer doesn't crash.

I was so proud of myself. Now @ruabmbua tells me that I don't need racer if I'm using rust-analyzer. I renamed racer in my .cargo/bin, restarted VSCode, and autocomplete works, verifying what he said. Of course, VSCode complains that a Rust tool is missing, but I can ignore that notification. Still, I might want to use racer with another editor, but I can't figure out how to tell VSCode not to even try to use it.

Oh, and by the way, I'm still getting

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /Users/alan/Documents/Eclipse/multicell/userspace/cellagent/Cargo.toml. Is rust-src installed?: RUST_SRC_PATH must be absolute: 

every time I start VSCode, which is why I started this whole thread in the first place.

I can get my work done, but my Outline says No symbols found in 'foo.rs' and syntax errors don't show up as squiggly lines in the editor.

Please disable the official Rust extension when using rust-analyzer. They tend to run into conflicts.

I had tried that before, but just to be sure I disabled the official Rust extension again and restarted VSCode. The VSCode status line tells me Racer: Not found and Rust Tools Missing. If I click on the latter I get a notification asking if I'd like to install racer. I still get the notification that rust-analyzer failed to load workspace.

Hm there is something strange going on then. Can you share a code --list-extensions?

code --list-extensions
bungcip.better-toml
hiro-sun.vscode-emacs
kalitaalexey.vscode-rust
matklad.rust-analyzer
nickdemayo.vscode-json-editor
rust-lang.rust
saviorisdead.RustyCode
serayuzgur.crates
Swellaby.rust-pack
vadimcn.vscode-lldb

The official Rust extension is disabled, and the rust analyzer is enabled.

saviorisdead.RustyCode

really suspicious. Try to disable that one as well.

Disabling didn't make a difference, but uninstalling did. VSCode no longer complains about racer. I still get the rust-analyzer failed to load workspace.

A bunch of stuff doesn't work in the editor. My OUTLINE is empty, no squiggly lines for syntax errors, and no type information shown when I hover. Those are all things that worked at one time or another. I can work without them, but they are nice to have.

It's fixed. I no longer get the rust-analyzer failed notification, and all editor features are working. The trick was disabling the Rust Extension Pack, which includes RLS. I did have to set rust.rustLangSrcPath in my settings.json. The only annoyance left is the VSCode status bar says Racer: Crashed.

For those who are interested:

bungcip.better-toml
hiro-sun.vscode-emacs
kalitaalexey.vscode-rust
matklad.rust-analyzer
nickdemayo.vscode-json-editor
serayuzgur.crates
Swellaby.rust-pack
vadimcn.vscode-lldb

You'll notice that rust-lang.rust was in the previous list but not this one.

Thanks to everyone who helped me get through this mess.

kalitaalexey.vscode-rust

This one should be disabled too

I think vscode should add a feature, where conflicting extensions could detect conflicts.

E.g. add it to the package metadata.

1 Like

kalitaalexey.vscode-rust is disabled, but it still shows up in code --list-extensions.