The paths mentioned by the other posts are correct:
- "/usr/bin" for the "toolchain location".
- "/usr/lib/rustlib/src/rust/library" for the "standard library".
After having set them the plugin was able to work correctly but the "autocomplete" for methods/functions that belong to Rust's standard library was still not working (same problem on all my 3 Gentoo notebooks, reproduced with CLion 2021.2 & 2021.3 + Rust plugin 0.4.164 and some other older versions + Rust 1.58.1 & 1.56.1).
For example, when typing "String::" I didn't get the list that shows its functions/methods (e.g. "from()", "as_bytes()", etc...).
To be exact, I that functionality was working the very first time that I set the correct paths, but not anymore after an explicit restart of CLion (it took me a while to realize this, made me crazy).
The root cause of the problem seems to be that the rust-plugin wants to be able to write to the stdlib-directories (I didn't analyze what it writes nor I'm going to speculate).
Example of an error message:
error: failed to write /opt/rust-bin-1.58.1/lib/rustlib/src/rust/library/unwind/Cargo.lock
Until CLion changes this behaviour the workaround would obviously be to make the location of Rust's standard library writeable by the user which is running CLion.
Doing that directly would of course trigger a lot of problems (security + pkg management), thererfore I decided to look for alternatives.
I decided to use OverlayFS to be able to still use Gentoo's original installation of Rust and at the same time to reroute the changes written by CLion to a separate directory.
In my case the details are:
1-
Created the 3 custom dirs needed by OverlayFS:
mkdir /opt/stecustom/clion/clion-rust_stdlib-overlay_upperdir
mkdir /opt/stecustom/clion/clion-rust_stdlib-overlay_workdir
mkdir /mnt/clion-rust_stdlib-overlay-result
2- Did an initial manual "mount":
mount -v -t overlay overlay -o noatime,lowerdir=/usr/lib/rustlib,upperdir=/opt/stecustom/clion/clion-rust_stdlib-overlay_upperdir,workdir=/opt/stecustom/clion/clion-rust_stdlib-overlay_workdir /mnt/clion-rust_stdlib-overlay-result
(the contents of "/usr/lib/rustlib" get on top the additional layer "/opt/stecustom/clion/clion-rust_stdlib-overlay_upperdir" to which all changes will be written - I don't know what "workdir" is supposed to host but it's a required parameter - and the merged layers are made available in " /mnt/clion-rust_stdlib-overlay-result":)
3- Changed in the overlay the ownership of all files:
cd /mnt/clion-rust_stdlib-overlay-result
chown -R MY_NON_ROOT_USER /mnt/clion-rust_stdlib-overlay-result/*
4- Made CLion's Rust plugin use the new overlayed dir:
- "/usr/bin" for the "toolchain location" (same as before).
- "/mnt/clion-rust_stdlib-overlay-result/src/rust/library" for the "standard library" (new!).
5- Restarted CLion and checked that everything worked
6- Made the overlayfs permanent in "/etc/fstab":
overlay /mnt/clion-rust_stdlib-overlay-result overlay noatime,lowerdir=/usr/lib/rustlib,upperdir=/opt/stecustom/clion/clion-rust_stdlib-overlay_upperdir,workdir=/opt/stecustom/clion/clion-rust_stdlib-overlay_workdir 0 2
7- Rebooted and checked again in CLion.
/usr/lib/rustlib/src/rust/library
. – Flight