racer-rust / emacs-racer

Racer support for Emacs
399 stars 48 forks source link

RUST_SRC_PATH error on first init #85

Open sashkachan opened 7 years ago

sashkachan commented 7 years ago
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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

JayKickliter commented 7 years ago

@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 commented 5 years ago

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 commented 5 years ago

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

n-bes commented 3 years ago

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