emacs-racer icon indicating copy to clipboard operation
emacs-racer copied to clipboard

emacs-racer seems to have a different idea about RUST_SRC_PATH than the system

Open ElectricCoffee opened this issue 6 years ago • 5 comments

This is a bit of a curiosity.

I've set the RUST_SRC_PATH to point to the source directory:

$ echo $RUST_SRC_PATH
/home/coffee/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src

But racer insists that the variable is set to "/usr/local/src/rust/src" via this error:

The last racer command was:

$ cd /home/coffee/Documents/code/rust/word-gen/
$ export CARGO_HOME=/home/coffee/.cargo
$ export RUST_SRC_PATH=/usr/local/src/rust/src
$ /home/coffee/.cargo/bin/racer complete 2 14 /home/coffee/Documents/code/rust/word-gen/src/generator.rs /tmp/racer14648QqG

This command terminated with exit code 1.

stdout:

racer can't find the directory pointed to by the RUST_SRC_PATH variable ""/usr/local/src/rust/src"". Try using an absolute fully qualified path and make sure it points to the src directory of a rust checkout - e.g. "/home/foouser/src/rust/src".

No output on stderr.

The temporary file will have been deleted. You should be able to reproduce
the same output from racer with the following command:

$ CARGO_HOME=/home/coffee/.cargo RUST_SRC_PATH=/usr/local/src/rust/src /home/coffee/.cargo/bin/racer complete 2 14 /home/coffee/Documents/code/rust/word-gen/src/generator.rs

Please report bugs on GitHub.

I have a feeling that it's emacs that is doing the re-exporting of RUST_SRC_PATH, thus clashing with the existing one.

I'm running Ubuntu 17.10, Emacs 25.2.2, Rust v. 1.21.0, and emacs-racer v. 1.2

ElectricCoffee avatar Nov 06 '17 08:11 ElectricCoffee

How are you setting RUST_SRC_PATH? It sounds like you've set it in a shell and Emacs is ignoring it.

You could set racer-rust-src-path directly if you just want a quick fix.

The default logic is to either use RUST_SRC_PATH (in the shell/environment Emacs is running in), or failing that we try rustc --print sysroot, and failing that we fall back to /usr/local/src/rust/src.

Wilfred avatar Nov 12 '17 21:11 Wilfred

I set it in my .bashrc file

ElectricCoffee avatar Nov 13 '17 10:11 ElectricCoffee

@ElectricCoffee I suspect if you evaluate the lisp function (getenv "RUST_SRC_PATH") it will return nil. This the function you need to get working if you want racer.el to set racer-rust-src-path to your RUST_SRC_PATH for you. getenv, in part, searchs through the process-environment variable for the path. If you look through the content of that variable you'll probably won't see your path variable.

You should look at the section "Why am I getting a message about environment variables on startup?" here. I know you probably don't spacemacs, but the advice to not set environmental variables in your .bashrc might help you here. Short of that you probably just have a configuration issue that's not properly loading environmental variables.

willbush avatar Mar 29 '18 08:03 willbush

~Confirming that if RUST_SRC_PATH is not set anywhere, racer stops behaving erratically (it occurred me sometimes).~ I stand corrected, in my case I did not download the nightly src files: $ rust install nightly $ rustup component add rust-src

However, still curious about the rest of my comment.

So, now I'm a bit confused: is the RUST_SRC_PATH env var needed at all or is it better to not set it? If the latter is true, the documentation should be amended consequently (and I'd gladly submit a tiny pr).

Perhaps related to https://github.com/racer-rust/racer/pull/799

Opinions?

apiraino avatar May 31 '18 11:05 apiraino

@apiraino

is the RUST_SRC_PATH env var needed at all or is it better to not set it?

Now racer can work without RUST_SRC_PATH, but I think you have no problem if you set it manually. But, anyway I think we have to update README, so it's great if you submit a PR for it!

kngwyu avatar Jun 01 '18 03:06 kngwyu