37

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?

Bastien Jansen
  • 8,756
  • 2
  • 35
  • 53
wst
  • 4,040
  • 4
  • 41
  • 59
  • 4
    I would recommend using `rustup`, it downloads the correct sources, updates them together with the compiler tools and allows version switching. https://rustup.rs/ Without sources, IDEA will not know about any `std` types or values, which basically makes code completion completely useless. – This company is turning evil. Jan 04 '17 at 13:19
  • I had the same question on in linux because I used `asdf-vm` to install rust - https://github.com/asdf-community/asdf-rust/issues/18 – Tim Abell Feb 06 '22 at 16:52

8 Answers8

48

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.
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
w.brian
  • 16,296
  • 14
  • 69
  • 118
15

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: enter image description here

Issue opened to simplify the process

eddygeek
  • 4,236
  • 3
  • 25
  • 32
  • 6
    who do you need to use a symlink here? it works fine for me without the symlink by just selecting `/usr/lib/rustlib/src/rust/src` in intellij – msrd0 May 20 '18 at 19:40
  • @msrd0 see the *Issue* link. It is (was?) a bug. – eddygeek Jun 12 '20 at 16:24
6

When not using the rustup installer, one can install the source package and direct the rust plugin to use those:

enter image description here

(Tested with CLion 2020.2.1, rust-1.46.0-x86_64-pc-windows-gnu.msi, rustc-1.46.0-src.tar.gz. Offline Rust installers and source archive from there: https://forge.rust-lang.org/infra/other-installation-methods.html )

Rainer Schwarze
  • 4,725
  • 1
  • 27
  • 49
5

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.

Raffaele
  • 61
  • 1
  • 2
  • 4
    I'm also using Gentoo. Having installed: [I] dev-lang/rust 1.32 (-clippy -debug -doc -libressl -rls -rustfmt -system-llvm -wasm) I cannot seem to find the standard libraries anywhere... Any ideas why they are missing here? – opncow Mar 15 '19 at 12:19
  • 1
    @opncow, I had the same trouble, found the answer here: https://stackoverflow.com/a/60576683/2598608 - Use the "rls" useflag for rust to have sources installed. – Scott Tiger May 05 '20 at 10:03
  • Thanks you @ScottTiger! Completely missed this useflag. – opncow May 06 '20 at 09:11
5

I know the question is for MacOS but this answer is shown up when searching for it on Linux. Below I will answer for Ubuntu.

The path is /usr/lib/rustlib/src/rust/src for Ubuntu 20.04


The way I did is:

  • Installed rustc from the repositories, which includes cargo
sudo apt install rustc
  • Then installed rust source package
sudo apt install rust-src
  • I used apt-file (can be installed with sudo apt install apt-file) to search for the install path of the sources
sudo apt-file update
apt-file list rust-src

This show the path as /usr/src/rustc-1.41.0/src .

But a ls -la in /usr/lib/rustlib/ will reveal symlinks and /usr/lib/rustlib/src/rust/src points to the previous found directory.

Using the symlink on IntelliJ will survive new rust versions.

eri0o
  • 2,285
  • 4
  • 27
  • 43
4

For Fedora 32 install Rust using command:

dnf install cargo rust-src

and the path to standard libary source is:

/usr/lib/rustlib/src/rust
MariuszS
  • 30,646
  • 12
  • 114
  • 155
3

I used Ubuntu. I follow these steps:

  1. sudo apt install rust-src
    wait for the install, then
  2. dpkg -L rust-src
    copy the last line. For me it is the standard library path:

/usr/lib/rustlib/src/rust

2

For MacOS, you need to put /opt/homebrew/bin/.

Saturnin Pugnet
  • 394
  • 2
  • 8