Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUST_SRC_PATH error on first init #85

Open
sashkachan opened this issue Jul 6, 2017 · 8 comments
Open

RUST_SRC_PATH error on first init #85

sashkachan opened this issue Jul 6, 2017 · 8 comments

Comments

@sashkachan
Copy link

sashkachan commented Jul 6, 2017

The last racer command was:

$ cd /Users/sashka/projects/rust-examples/hello_world/
$ export CARGO_HOME=/Users/sashka/.cargo
$ export RUST_SRC_PATH=/Users/sashka/projects/rust-examples/hello_world/src
$ /Users/sashka/.cargo/bin/racer complete 3 9 /Users/sashka/projects/rust-examples/hello_world/src/main.rs /var/folders/78/h528r3mj0cx0x7dyb_xxlst00000gn/T/racer64638g7w

This command terminated with exit code 1.

stdout:

Unable to find libstd under RUST_SRC_PATH. N.B. RUST_SRC_PATH variable needs to point to the *src* directory inside a rust checkout e.g. "/home/foouser/src/rust/src". Current value ""/Users/sashka/projects/rust-examples/hello_world/src/libstd""

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=/Users/sashka/.cargo RUST_SRC_PATH=/Users/sashka/projects/rust-examples/hello_world/src /Users/sashka/.cargo/bin/racer complete 3 9 /Users/sashka/projects/rust-examples/hello_world/src/main.rs

Please report bugs on GitHub.

Prior to running the project, I checked that src is installed, and I get sources under

$ ls $(rustc --print sysroot)/lib/rustlib/src/rust/src
Cargo.lock                      libbacktrace                    librustc_asan                   librustc_msan                   libsyntax_ext [..]

From the description of Racer Rust Src Path it says:
If $RUST_SRC_PATH is not set, look for rust source in rustup’s install directory.

Which I expected to happen, but on first completion attempt racer-debug claims that var exported is

$ export RUST_SRC_PATH=/Users/sashka/projects/rust-examples/hello_world/src

Is it expected behaviour?

Thanks!

@sashkachan
Copy link
Author

I set the variable to "" (empty string) and RUST_SRC_PATH was implicitly set.
I reset it to original value, which defaulted to

$(rustc --print sysroot)/lib/rustlib/src/rust/src

Does it mean when I change the environment with rustup I will have to update the racer-rust-src-path to?

@Wilfred
Copy link
Member

Wilfred commented Jul 9, 2017

Sorry, I'm slightly confused by which variables you're setting. Had you explicitly set the elisp variable racer-rust-src-path or the environment variable RUST_SRC_PATH? What value did Emacs say racer-rust-src-path was set to?

(You can view this M-x ielm RET racer-rust-src-path RET.)

This is probably obvious, but RUST_SRC_PATH=/Users/sashka/projects/rust-examples/hello_world/src is wrong -- it should be the path to the stdlib source code, not the code for your project.

Does it mean when I change the environment with rustup I will have to update the racer-rust-src-path too?

If you really want to see the exact source code of the stdlib when you jump to a definition, yes. I don't generally bother changing it, I'm happy with it always pointing to nightly's stdlib code.

@sashkachan
Copy link
Author

sashkachan commented Jul 11, 2017

I have not set RUST_SRC_PATH explicitly (and I checked, it wasn't in my ENV), so it wasn't set in emacs either.

I then set the racer-rust-src-path to "" (as I assumed it will be deduced automatically when the mode is engaged) but I get the error and racer-debug produces the output in the original post.

I expected if I reset "racer-rust-src-path" to be empty, it will be reset to the output of $(rustc --print sysroot)/lib/rustlib/src/rust/src, but it doesn't seem to be the case?

I think it fails on this promise (from customise-variable racer-rust-src-path)

 If $RUST_SRC_PATH is not set, look for rust source in rustup’s install directory.

@Wilfred
Copy link
Member

Wilfred commented Jul 14, 2017

Note that an empty string is truthy in elisp, so you should set the variable to nil if you want to reset it.

@JayKickliter
Copy link

@alex-glv I just went through the same exercise. Setting the path to nil in with custom-set-variable did not work. I had to manually delete the line from ~/.emacs.d/custom.el for it to take effect. On next startup, the path was automatically setup.

@iantruslove
Copy link

iantruslove commented Dec 9, 2018

I was just getting racer set up and hit this issue too. In the hopes I may give someone else a workaround, here's what I did:

  1. Install rust sources (rustup component add rust-src)

  2. Use rustc's knowledge of its own environment to configure racer's source path variable:

(setq racer-rust-src-path
      (concat (string-trim
               (shell-command-to-string "rustc --print sysroot"))
              "/lib/rustlib/src/rust/src"))

I use use-package; here's a more complete snippet of my racer configuration:

(use-package racer
  :requires rust-mode

  :init (setq racer-rust-src-path
              (concat (string-trim
                       (shell-command-to-string "rustc --print sysroot"))
                      "/lib/rustlib/src/rust/src"))

  :config
  (add-hook 'rust-mode-hook #'racer-mode)
  (add-hook 'racer-mode-hook #'eldoc-mode)
  (add-hook 'racer-mode-hook #'company-mode))

@b1tg
Copy link

b1tg commented Dec 17, 2018

add (require 'subr-x) to use string-trim for someone occur this error

@n-bes
Copy link

n-bes commented Oct 25, 2020

Helped me: export RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants