Skip to content

rust-analyzer failed to load workspace again #6020

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
rsignavong opened this issue Sep 16, 2020 · 23 comments
Closed

rust-analyzer failed to load workspace again #6020

rsignavong opened this issue Sep 16, 2020 · 23 comments

Comments

@rsignavong
Copy link

rsignavong commented Sep 16, 2020

Sorry to reopen this issue #4172 but the issue is still running and is not due to local toolchain installation.
It is more the difference of folders of rust-src between stable and nightly.

I have both stable and nightly and both have rust-src component installed but the folder inside rust-src is not the same for both toolchains.

In stable, rust-src contains an src folder and the requested libcore folder inside to load the workspace.
In nightly, rust-src contains only library and so rust-analyzer still tries to load src/libcore in nightly active toolchain.

And so the following still error occurs:

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /Users/.../workspace/.../Cargo.toml. Is rust-src installed?:
 could not find libcore in sysroot path `/Users/.../.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src`
@rsignavong rsignavong changed the title rust-analyzer failed to load workspace rust-analyzer failed to load workspace again Sep 16, 2020
@bjorn3
Copy link
Member

bjorn3 commented Sep 16, 2020

What rust-analyzer version are you using?

@rsignavong
Copy link
Author

I tried the latest release 0d03fe6.
And just now I tried with 3877421 built from source master branch, I still got the same error.

@bjorn3
Copy link
Member

bjorn3 commented Sep 16, 2020

What is the output of ls -R $(rustc --print sysroor)/lib/rustlib/src/rust?

@rsignavong
Copy link
Author

There are many lines with the -R option.

Here is what I have

~ on ☁️  us-east-1
❯ rustup override set stable
info: using existing install for 'stable-x86_64-apple-darwin'
info: override toolchain for '/Users/rockysignavong' set to 'stable-x86_64-apple-darwin'

  stable-x86_64-apple-darwin unchanged - rustc 1.46.0 (04488afe3 2020-08-24)


~ on ☁️  us-east-1
❯ rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/rockysignavong/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin

active toolchain
----------------

stable-x86_64-apple-darwin (directory override for '/Users/rockysignavong')
rustc 1.46.0 (04488afe3 2020-08-24)


~ on ☁️  us-east-1
❯ ls $(rustc --print sysroot)/lib/rustlib/src/rust

 Cargo.lock   src

~ on ☁️  us-east-1
❯ rustup override set nightly
info: using existing install for 'nightly-x86_64-apple-darwin'
info: override toolchain for '/Users/rockysignavong' set to 'nightly-x86_64-apple-darwin'

  nightly-x86_64-apple-darwin unchanged - rustc 1.48.0-nightly (6af1bdda5 2020-09-15)


~ on ☁️  us-east-1
❯ rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/rockysignavong/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin

installed targets for active toolchain
--------------------------------------

wasm32-unknown-unknown
x86_64-apple-darwin

active toolchain
----------------

nightly-x86_64-apple-darwin (directory override for '/Users/rockysignavong')
rustc 1.48.0-nightly (6af1bdda5 2020-09-15)


~ on ☁️  us-east-1
❯ ls $(rustc --print sysroot)/lib/rustlib/src/rust

 Cargo.lock   library

@rsignavong
Copy link
Author

as you can see, there is src in stable and library in nightly

@rsignavong
Copy link
Author

and using grep libcore

~ on ☁️  us-east-1
❯ rustup override set stable
info: using existing install for 'stable-x86_64-apple-darwin'
info: override toolchain for '/Users/rockysignavong' set to 'stable-x86_64-apple-darwin'

  stable-x86_64-apple-darwin unchanged - rustc 1.46.0 (04488afe3 2020-08-24)


~ on ☁️  us-east-1
❯ ls -R $(rustc --print sysroot)/lib/rustlib/src/rust | rg libcore

libcore
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/alloc:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/array:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/benches:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/benches/ascii:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/benches/char:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/benches/hash:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/benches/num:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/benches/num/dec2flt:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/benches/num/flt2dec:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/benches/num/flt2dec/strategy:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/char:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/convert:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/fmt:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/fmt/rt:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/future:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/hash:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/iter:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/iter/adapters:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/iter/traits:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/macros:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/mem:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/num:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/num/dec2flt:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/num/flt2dec:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/num/flt2dec/strategy:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ops:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/prelude:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ptr:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/slice:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/str:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/sync:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/task:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/tests:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/tests/fmt:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/tests/hash:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/tests/num:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/tests/num/dec2flt:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/tests/num/flt2dec:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/tests/num/flt2dec/strategy:
/Users/rockysignavong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/unicode:

~ on ☁️  us-east-1
❯ rustup override set nightly
info: using existing install for 'nightly-x86_64-apple-darwin'
info: override toolchain for '/Users/rockysignavong' set to 'nightly-x86_64-apple-darwin'

  nightly-x86_64-apple-darwin unchanged - rustc 1.48.0-nightly (6af1bdda5 2020-09-15)


~ on ☁️  us-east-1
❯ ls -R $(rustc --print sysroot)/lib/rustlib/src/rust | rg libcore


~ on ☁️  us-east-1
❯

@sunjay
Copy link
Member

sunjay commented Sep 17, 2020

It looks like this issue is being caused by the recent reorg of the rust-lang/rust repo. As mentioned in the original issue, the src directory is now named library.

I ran rustup update so the info below is with rustc 1.48.0-nightly (6af1bdda5 2020-09-15) (from rustc 1.48.0-nightly (a1947b3f9 2020-09-10)).

rust-analyzer is trying to find the path:

~/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src

But the actual path that exists is:

~/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library

If anyone else is looking to temporarily work around the solution just to get their setup working again, you can use:

ln -s ~/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library ~/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src

Simply renaming the directory to src will probably work too, though I haven't tried that.

@rsignavong
Copy link
Author

rsignavong commented Sep 17, 2020

I didn't think that aliasing will work as I thought rust-analyzer was looking for libcore that doesn't exist inside library but I tried @sunjay temporary solution with alias ln -s library src for nightly toolchain and it works! 👍

Thank you!

I hope this will be fixed soon.

@lnicola
Copy link
Member

lnicola commented Sep 17, 2020

This should have been fixed in #5586. Do you have a RUST_SRC RUST_SRC_PATH environment variable?

@rsignavong
Copy link
Author

I have RUST_SRC_PATH and changing src to library didn't work.
So I added RUST_SRC that target library and it works without the symlink src -> library (that I removed before testing).

Here is my .zshrc config for rust

# Rust
export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"
export RUST_SRC="$(rustc --print sysroot)/lib/rustlib/src/rust/library"

@lnicola
Copy link
Member

lnicola commented Sep 17, 2020

Try unsetting those.

@rsignavong
Copy link
Author

It works without those environment variable. Thank you! 👍
I thought it was mandatory to specify those. I don't really remember why I needed to set RUST_SRC_PATH, maybe for RLS and Racer.

@lnicola lnicola closed this as completed Sep 17, 2020
@sunjay
Copy link
Member

sunjay commented Sep 17, 2020

Ah! Yup. I had that variable too. It used to be mandatory for RLS. Thanks @lnicola! 🎉

svenstaro added a commit to svenstaro/dotfiles that referenced this issue Sep 19, 2020
@vv9k
Copy link

vv9k commented Oct 8, 2020

Same for me! Issue resolved :) Thanks @lnicola

JP-Ellis added a commit to JP-Ellis/dotfiles that referenced this issue Oct 12, 2020
@Nevsden
Copy link

Nevsden commented Oct 28, 2020

For me setting the RUST_SRC_PATH environment variable to C:\Users\<USERNAME>\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust did the fix.

@flodiebold
Copy link
Member

flodiebold commented Oct 28, 2020

That would help, but it'd still be better to unset it completely if you're just using rustup.

@Nevsden
Copy link

Nevsden commented Oct 28, 2020

I'm curious what you mean with unsetting it completely. I am not aware that I had it set before. Or am I missing something?

@flodiebold
Copy link
Member

If RUST_SRC_PATH isn't set, rust-analyzer should discover the path automatically if you're using rustup. Using the variable should only be necessary if you're getting the standard library sources some other way. Make sure you're using the newest rust-analyzer version (you can check using the "Rust Analyzer: Show RA Version" command); then if the problem still occurs, it will tell you "(RUST_SRC_PATH might be incorrect, try unsetting it)" in the error message if you've still got the variable set somewhere.

@ntn888
Copy link

ntn888 commented Nov 9, 2020

those variables are not set for me but i'm getting the error! pls help

@ntn888
Copy link

ntn888 commented Nov 9, 2020

ls $(rustc --print sysroot)/lib/rustlib/src/rust/src
ls: cannot access '/home/ajit/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src': No such file or directory

@flodiebold
Copy link
Member

That's the old path, it's not supposed to exist. Please check that you're using the newest rust-analyzer version using the "Show RA version" command, provide the full error message and the rustc version, and check whether $(rustc --print sysroot)/lib/rustlib/src exists.

@ntn888
Copy link

ntn888 commented Nov 9, 2020

thanks for your prompt response! i switched to installing the rust-analyser from source and this fixed the problem. i guess the binary download isn't updated yet. thanks again.

@uninhm
Copy link

uninhm commented May 31, 2021

I'm getting that error!! I don't have RUST_SRC_PATH nor RUST_SRC set

$ ls /usr/lib/rustlib/
rustc-src  x86_64-unknown-linux-gnu

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

No branches or pull requests

9 participants