I installed rust with brew on MacOS, and I'm noticing this error on a hello world project with VS Code:
rust-analyzer failed to load workspace:
Failed to find sysroot for Cargo.toml file ./rust_new/Cargo.toml.
Is rust-src installed?: rustup component add rust-src failed
I didn't install with rustup, and I figured I wouldn't need to. This suggests I must, but why? Does this suggest I need the complier source to use your package in my editor?
rust-src is the standard library, not compiler source code. rust-analyzer needs it to know what the standard library types are.
Isn't that rust-std? Rust's homepage describes rust-src as the Rust source code.
https://github.com/rust-lang/rustup#can-rustup-download-the-rust-source-code
rust-src is the source code of the standard library. rust-std is the compiled version of the standard library.
Hey,
I just upgraded to the newest rust-analyzer version, and I've just started having the same issue.
rustup updaterustup comonent add rust-srcRUST_SRC_PATH but I'm not sure what to set that to/why I only now have to set it.What is the output of ls $(rustc --print sysroot)/lib/rustlib/src/rust/src? For me it is:
build_helper libcore libpanic_unwind libprofiler_builtins librustc_asan librustc_msan libstd libterm libunwind tools
liballoc libpanic_abort libproc_macro librustc librustc_lsan librustc_tsan libsyntax libtest stdarch
it seems like I only have the path up to lib/rustlib I don't have src/rust/src, should I reinstall stuff? What I have in rustlib is
components manifest-rustc
etc rust-installer-version
manifest-rust-docs x86_64-apple-darwin
manifest-rust-std-x86_64-apple-darwin
Quick update, I uninstalled all of the rust toolchain, and then reinstalled and the issue has gone away
Closing the issue, as it seems to be the problem with local toolchain installation. it would be awesome if we could diagnose and warn about this on our side, but I doubt we can provide info more useful then the existing error message.
I have the same issue with nightly-x86_64-unknown-linux-gnu (1.48.0-nightly) on ubintu linux and vs code. I have completely uninstalled rust and reinstalled, but I get
rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /mnt/md2/woelper/dircpy/Cargo.toml.
Is rust-src installed?:
can't load standard library from sysroot /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src (discovered via `rustc --print sysroot`)
try running `rustup component add rust-src` or set `RUST_SRC_PATH`
running rustup component add rust-src yields info: component 'rust-src' is up to date.
it looks like I am missing the src folder: ls /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust shows just Cargo.lock library.
$(rustc --print sysroot) points to /home/woelper/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu, which does exist.
I should add that this is a VS code remote session, maybe this complicates things?
Try rustup component add rust-src --toolchain nightly.
rustup component add rust-src --toolchain nightly
Thanks for your reply, this produces the following result:
rustup component add rust-src --toolchain nightly
info: component 'rust-src' is up to date
I am able to reproduce this with Mac OS 10.15.6 and 1.48.0-nightly as well:
rust-analyzer failed to load workspace:
Failed to find sysroot for Cargo.toml file /Users/woelper/catapult-imgui/Cargo.toml. Is rust-src installed?
Caused by: can't load standard library from sysroot /Users/woelper/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src (discovered via `rustc --print sysroot`) try running `rustup component add rust-src` or set `RUST_SRC_PATH`
I also ran rustup component add rust-src --toolchain nightly, which caused info: component 'rust-src' is up to date
rust-src changed the path layout, which is the source of the problem.
September:

August:

Lastly, this should be fixed if you take recent version from master:
https://github.com/rust-analyzer/rust-analyzer/commit/6b8bc132dc6dee538964fffa0720480beb5b25dd#diff-30888fefce138d15c65ceb40b37b7ad2R146
This should have been fixed in https://github.com/rust-analyzer/rust-analyzer/pull/5586.
Thanks @lnicola I feel that maybe the official extension isn't picking up that change yet, which causes the breakage, even though everything should work by now. That's why I build and install from source.
I still have the same issue with MacOS 10.15.6, 1.48.0-nightly even I build and install from source.
There's only Cargo.lock, library
Here's what I got.
$ cd $(rustc --print sysroot)/lib/rustlib/src/rust
$ ls
Cargo.lock library
$ rustup component add rust-src --toolchain nightly
info: component 'rust-src' is up to date
I believe at this stage its just a matter of verifying that you actually use rust-analyzer from source (first uninstall from your VSCode, then install)
My rust environment is not working, so I decided to uninstall and reinstall entire rust system.
However I still struggling with this issue.
Emacs version 27.1(9.0)
Here's what I did.
~ % curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
~ % rustup install nightly
~ % rustup default nightly
~ % git clone https://github.com/rust-analyzer/rust-analyzer.git && cd rust-analyzer
rust-analyzer % cargo xtask install --server
~ % rustup component add rust-src
Emacs lsp says
LSP :: Connected to [rust-analyzer:94373 status:starting]. [2 times]
LSP :: rust-analyzer:94373 initialized successfully
LSP :: rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /Users/yufuku/Develop/Rust/hello/Cargo.toml. Is rust-src installed?: could not find libcore in sysroot path `/Users/yufuku/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src`
LSP :: Error from the Language Server: Rust Analyzer is still loading... (Unknown error) [4 times]
$(rustc --print sysroot)/lib/rustlib/src/rust % ls
Cargo.lock library
There's no src directory.
It's not working for me too.
The latest release 0d03fe6 is trying to load libcore from rust-src/src from rustc stable version but it doesn't read the rust-src/library folder in rustcnightly version
Just running rustup component add rust-src worked fine for me with latest macOS catalina.
I'm having the same problem too on Arch Linux. Maybe the rust-src path changes ever so often?
I think the path for me is $(rustc --print sysroot)/lib/rustlib/src/rust/library/std/src or is this something else?
@LU15W1R7H the path changed only once (recently), and while rust-analyzer supports both locations, for that to work you must unset RUST_SRC_PATH. See the discussion in #6178.
I got same problem on Arch Linux.
Here is the error log in Emacs buffer *rust-analyzer::stderr*:
[ERROR rust_analyzer::reload] failed to load workspace: Failed to find sysroot for Cargo.toml file /home/stardiviner/Documents/learning/Rust/hello/Cargo.toml. Is rust-src installed?: could not find libcore in sysroot path `/home/stardiviner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src`
I create a test project using command cargo new hello-world.
Did uninstall & reinstall nightly toolchain, and here is the output of command:
$ ls $(rustc --print sysroot)/lib/rustlib/src/rust/src
llvm-project
And I execute command:
$ rustup update && rustup component add rust-src
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-30, rust version 1.49.0-nightly (6bdae9edd 2020-10-29)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-29-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-29, rust version 1.49.0-nightly (31ee872db 2020-10-28)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-28-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-28, rust version 1.49.0-nightly (07e968b64 2020-10-27)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-27-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-27, rust version 1.49.0-nightly (fd542592f 2020-10-26)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-26-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-26, rust version 1.49.0-nightly (4760b8fb8 2020-10-25)
info: skipping nightly which is missing installed components 'rls-preview', 'rustfmt-preview'
info: syncing channel updates for 'nightly-2020-10-25-x86_64-unknown-linux-gnu'
nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
info: cleaning up downloads & tmp directories
info: component 'rust-src' is up to date
I have following setting in ~/.zshrc:
export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"
@stardiviner try to unset RUST_SRC_PATH and check what which rust-analyzer prints.
@lnicola After unset RUST_SRC_PATH, The command which rust-analyzer points to /usr/bin/rust-analyzer.
It seems from my Arch Linux installed package rust-analyzer.
That's strange, recent versions print a "RUST_SRC_PATH might be incorrect, try unsetting it" message if the variable is set.
Anyway, is it working now? I think RUST_SRC_PATH should point to the sysroot, not to the source code directory, but it generally works without the variable.
Still not work.
Same error:
[ERROR rust_analyzer::reload] failed to load workspace: Failed to find sysroot for Cargo.toml file /home/stardiviner/Documents/learning/Rust/hello/Cargo.toml. Is rust-src installed?: could not find libcore in sysroot path `/home/stardiviner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src`
I'm sure I installed rust-src component. But why I don't have libcore in sysroot path? I checked the upper path. I found I only have llvm-project directory. Is this correct and normal?
Hmm, no, not really:
$ ls .rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src
libcore libstd llvm-project
$ rustup update
[snip]
$ ls .rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src
libcore libstd llvm-project
Oh, sorry, that's the old path. Look at ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library. The path changed recently and rust-analyzer tries both but ends up printing the old one in case of an error, IIRC.
Here is my output:
โฏ cd ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library
โฏ ls
alloc panic_unwind rustc-std-workspace-alloc stdarch
backtrace proc_macro rustc-std-workspace-core term
core profiler_builtins rustc-std-workspace-std test
panic_abort rtstartup std unwind
Still don't have libcore. where the libcore comes from? Is it rust-src component?
Still don't have libcore. where the libcore comes from? Is it rust-src component?
You do, it's the third on the first column.
Maybe your emacs or emacs LSP client sets RUST_SRC_PATH to the wrong value?
Still don't have libcore. where the libcore comes from? Is it rust-src component?
You do, it's the third on the first column.
So rls should use core instead of libcore. Is it renamed or it is as it is?
Maybe your emacs or emacs LSP client sets RUST_SRC_PATH to the wrong value?
I searched all my ~/.config/emacs/ directory, have not found any RUST_SRC_PATH settings.
So rls should use core instead of libcore. Is it renamed or it is as it is?
Yes, rust-analyzer can load it from .rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core.
I searched all my ~/.config/emacs/ directory, have not found any RUST_SRC_PATH settings.
Neither does emacs-lsp seem to set it, strange.
I finally figured out why. I forgot to exit tmux session..... How stupid I am. Sorry for wasted you much time.
After restarted terminal, the problem is gone. Thanks so so much!!
Does it mean that I need to upgrade rust-analyzer to a more recent version to get this issue resolve?
I'm pinning the version to 20200615 because of #5344 and now I have to choose between rust-analyzer stuck with 100% CPU or just keep crashing...?
Does it mean that I need to upgrade rust-analyzer to a more recent version to get this issue resolve?
Didn't work out for me, I tried building it from the 'nightly' and 'master' branches with the same result -- that is "Rust Analyzer is still loading... (Unknown error)". No tmux/screen, tried launching it with emacs-lsp from both 'clean' bash session and from Plasma shell.
~ echo $RUST_SRC_PATH
~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src
libcore is in ...rustlib/src/rust/src, core is in .../rust/library
You should unset RUST_SRC_PATH.
BTW this seems to have been fixed for me today by 2c408c68a4a27e9a85ce85ec1342e3af58c1571f - thank you!
You should unset RUST_SRC_PATH.
It probably should have worked. My build of Emacs (master) got a bit further when loading rust-analyzer and complained about exactly that when I unsetted the env var in a bash session. When I have restarted it without the RUST_SRC_PATH variable ever being set due the session, the issue persists.
Edit: I've encountered some peculiar behavior of Emacs with regards to this env variable. While RUST_SRC_PATH is not set anywhere in the system environment, emacs has this variable set for some odd reason (I can echo it in the M-x shell, nowhere else).
I don't have RUST_SRC_PATH set, tried to use both auto downloaded via coc-rust-analyzer, and local build:
~/.config/coc/extensions/coc-rust-analyzer-data/rust-analyzer --version
rust-analyzer e8c8039
Same error.
@kushaldas Can you provide more info about your system and editor etc? and try to get env variable info from editor.
Edit: I've encountered some peculiar behavior of Emacs with regards to this env variable. While RUST_SRC_PATH is not set anywhere in the system environment, emacs has this variable set for some odd reason (I can echo it in the M-x shell, nowhere else).
If you're using Spacemacs, it has this thing where it saves the environment in a file and reproduces it from there (see ~/.spacemacs.env). Or if you're not, maybe there's something similar going on. We're ignoring RUST_SRC_PATH now if it doesn't contain core though, so it shouldn't matter much anymore.
Same error.
Please post the exact error message you're getting, and the output from rustc --print sysroot in your project directory.
@kushaldas Can you provide more info about your system and editor etc? and try to get env variable info from editor.
I am using neovim and coc-rust-analyzer. After fighting for the whole day, I removed all rust* from the system, and did a fresh install. Now everything is again working. Thank you for the help.
@kushaldas Can you provide more info about your system and editor etc? and try to get env variable info from editor.
I am using neovim and coc-rust-analyzer. After fighting for the whole day, I removed all rust* from the system, and did a fresh install. Now everything is again working. Thank you for the help.
How did you install rust? I'm just experiencing the same issue now
Most helpful comment
@LU15W1R7H the path changed only once (recently), and while
rust-analyzersupports both locations, for that to work you must unsetRUST_SRC_PATH. See the discussion in #6178.