How to provide standard library sources for IntelliJ IDEA's Rust project?

一笑奈何 提交于 2019-12-05 16:01:01

问题


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-src component 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:

  1. run /usr/local/lib/rustlib/uninstall.sh as root to uninstall Rust

  2. follow 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 | sh

  3. now $ which rustup should work, copy that path to IDEA.

  4. now it will lose the toolchain, which is here: /home/username/.cargo/bin

  5. and 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!