问题
I am using Mac for development. I installed Rust 1.13.0 using brew install rust and the Rust plugin 0.1.0.1385 for IntelliJ IDEA. I created my first test project with cargo and while opening it with IDEA I got the message
No standard library sources found, some code insight will not work
I haven't found any sources installed, nor the Rust sources package in Homebrew.
How do I provide sources for the project and what are the practical implication if I ignore this step?
回答1:
As commented, the supported approach is to use rustup:
- Navigate to https://rustup.rs/ and follow the installation instructions for your platform.
- Add the
rust-srccomponent by running:rustup component add rust-src - Create a new Rust project in IntelliJ and choose your existing Rust project source. If the folder already contains previous IntelliJ project files, you may have to delete those first before it will let you proceed.
- IntelliJ-Rust should automatically configure the standard library sources to point to the sources downloaded by
rustup.
回答2:
As a reference, since the question title is broad, for Fedora 28 I had to:
dnf install cargo rust-src
sudo ln -s /usr/lib/rustlib/src /usr/lib/rustlib/x86_64-unknown-linux-gnu/
then give /usr/lib/rustlib/x86_64-unknown-linux-gnu/src/rust/src as "Standard library"
Full setup:
Issue opened to simplify the process
回答3:
I faced the same problem because I was following setup instructions from the Book.
To prove it won't work type $ which rustup and it won't answer.
So to avoid that in IDEA you should uninstall Rust first:
run
/usr/local/lib/rustlib/uninstall.shas root to uninstall Rustfollow installation instructions on https://www.rust-lang.org/en-US/install.html or just
$ curl r/[https://sh.rustup.rs](https://sh.rustup.rs) \-sSf | shnow
$ which rustupshould work, copy that path to IDEA.now it will lose the toolchain, which is here:
/home/username/.cargo/binand the standard library, IDEA will tell it can download it
Now it works.
回答4:
Although the preferred way of installing Rust is by using rustup, as pointed out by the other posts, it is not uncommon to use the packages that your distro makes available.
I use, for example, the packages provided by Gentoo and I share the same problem about the not prefilled field for standard libraries. Nevertheless, you can easily find out where your standard libraries have been installed by typing the following find command:
find /usr/lib* -type d -name "rust" | grep src
or the following if you installed rust in your home
find -type d -name "rust" | grep src
The previous commands will help, unless, of course, in your distro there is a package for the binaries and one for the source and you only installed the binary one.
来源:https://stackoverflow.com/questions/41464063/how-to-provide-standard-library-sources-for-intellij-ideas-rust-project