racer-rust / emacs-racer

Racer support for Emacs
399 stars 48 forks source link

Can't find rust-src #140

Closed kostafey closed 3 years ago

kostafey commented 3 years ago

Fail with the following error: eldoc error: (user-error No such directory: ~/.rustup/toolchains/stable-x86_64-pc-windows-msvc/lib/rustlib/src/rust/src. Please set ‘racer-rust-src-path’ or ‘RUST_SRC_PATH’)

Everything looks installed:

> rustup update
info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
info: syncing channel updates for 'nightly-x86_64-pc-windows-msvc'
info: checking for self-updates

   stable-x86_64-pc-windows-msvc unchanged - rustc 1.47.0 (18bf6b4f0 2020-10-07)
  nightly-x86_64-pc-windows-msvc unchanged - rustc 1.49.0-nightly (3525087ad 2020-10-08)

info: cleaning up downloads & tmp directories

> rustup toolchain add nightly
info: syncing channel updates for 'nightly-x86_64-pc-windows-msvc'

  nightly-x86_64-pc-windows-msvc unchanged - rustc 1.49.0-nightly (3525087ad 2020-10-08)

info: checking for self-updates

> rustup component add rust-src
info: component 'rust-src' is up to date

> cargo +nightly install racer
    Updating crates.io index
     Ignored package `racer v2.1.39` is already installed, use --force to override

But I can't locate the last src directory in this path ~/.rustup/toolchains/stable-x86_64-pc-windows-msvc/lib/rustlib/src/rust/src:

> cd ~\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\
> dir

 Directory of ~\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust

10.10.2020  01:14    <DIR>          .              
10.10.2020  01:14    <DIR>          ..             
10.10.2020  01:14           116 787 Cargo.lock     
10.10.2020  01:14    <DIR>          library        
               1 File(s)        116 787 bytes      
               3 Dir(s)  224 742 670 336 bytes free

> cd library
> dir

 Directory of ~\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library

10.10.2020  01:14    <DIR>          .                                                                                 
10.10.2020  01:14    <DIR>          ..                                                                                
10.10.2020  01:14    <DIR>          alloc                                                                             
10.10.2020  01:14    <DIR>          backtrace                                                                         
10.10.2020  01:14    <DIR>          core                                                                              
10.10.2020  01:14    <DIR>          panic_abort                                                                       
10.10.2020  01:14    <DIR>          panic_unwind                                                                      
10.10.2020  01:14    <DIR>          proc_macro                                                                        
10.10.2020  01:14    <DIR>          profiler_builtins                                                                 
10.10.2020  01:14    <DIR>          rtstartup                                                                         
10.10.2020  01:14    <DIR>          rustc-std-workspace-alloc                                                         
10.10.2020  01:14    <DIR>          rustc-std-workspace-core                                                          
10.10.2020  01:14    <DIR>          rustc-std-workspace-std                                                           
10.10.2020  01:14    <DIR>          std                                                                               
10.10.2020  01:14    <DIR>          stdarch                                                                           
10.10.2020  01:14    <DIR>          term                                                                              
10.10.2020  01:14    <DIR>          test                                                                              
10.10.2020  01:14    <DIR>          unwind                                                                            
               0 File(s)              0 bytes                                                                         
              18 Dir(s)  224 743 960 576 bytes free                                                                   

Did I forget to install something or default rust-src path should be changed to ~/.rustup/toolchains/stable-x86_64-pc-windows-msvc/lib/rustlib/src/rust/library?

ghost commented 3 years ago

For now, just add

(setq racer-rust-src-path
  "/YOUR/REAL/HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library")

to your emacs init file. Its a quick fix fix until the issue is resolved.

PR #141 suggests a fix.

xuyizhe commented 3 years ago

A compatible version here #143.

Or you can add

(setq racer-rust-src-path
      (let* ((sysroot (string-trim
                       (shell-command-to-string "rustc --print sysroot")))
             (lib-path (concat sysroot "/lib/rustlib/src/rust/library"))
              (src-path (concat sysroot "/lib/rustlib/src/rust/src")))
        (or (when (file-exists-p lib-path) lib-path)
            (when (file-exists-p src-path) src-path))))

Related issues #144

rodested commented 3 years ago

Hello,

I've seen that in my installation both directories exist, and in my case it complains because the std library is not in the expected directory.

Trying to have a more robust behaviour I've forked the main racer repository and added a patch so that it automatically detects if the old or new one should be used, by also checking if "std" library directory is there.

Also I have requested a merge applying my changes: https://github.com/racer-rust/emacs-racer/pull/149

Meanwhile, you can download a fixed races.el version which fixes the problem from here: https://github.com/rodested/emacs-racer

Quick fix:

download the races.el file
overwrite the one in (as per my installation): ~/.emacs.d/elpa/26.3/develop/racer-20210119.225 with the downloaded one

Hope this helps

Wilfred commented 3 years ago

Should be fixed in #143.