2

I'm currently struggling to set up error checking for rust in emacs. Flycheck seems to work fine with other languages (C, Python, Ruby, eLisp) but doesn't appear to do anything in rust-mode.

I haven't noticed any error messages, but when I run flycheck-verify-setup, I get the following:

Syntax checkers for buffer state.rs in rust-mode:

  rust-cargo
    - predicate:  nil
    - executable: Not found

  rust
    - predicate:  nil
    - executable: Not found

Flycheck Mode is enabled.  Use C-u C-c ! x to enable disabled
checkers.

I tried manually setting the executable but wasn't sure about the predicate, and was concerned that I'd be interfering with flycheck-rust-setup.

The current configuration code I have written concerning this is:

(setq exec-path (append exec-path '("/Users/jac32/.cargo/bin")))
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))

;; Set path to racer binary 
(setq racer-cmd "/usr/local/bin/racer")

;; Set path to rust src directory
(setq racer-rust-src-path "/Users/jac32/.rust/src/")

(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'rust-mode-hook
     (lambda ()
         (setq flycheck-mode-hook #'flycheck-rust-setup)))

And my current setup loads all of the following packages:

(defvar required-packages
  '(
     base16-theme
     company
     company-racer
     evil
     flycheck
     flycheck-rust
     helm
     magit
     rainbow-delimiters
     rust-mode
     racer
     yasnippet
  ) "a list of packages to ensure are installed at launch.")

Thank you for any and all help on this issue.

update Just discovered that the rustc and cargo executables were not located anywhere within the exec-path variable. Under flycheck-verify-setup, both checker executables are found and the predicate for rust-cargo is t. However, resetting flycheck-mode now causes the following message to appear:

Suspicious state from syntax checker rust-cargo: Checker rust-cargo
returned non-zero exit code 101, but no errors from output: Could not             
execute process `rustc -vV` (never executed)

Caused by:
 No such file or directory (os error 2)
Scott Weldon
  • 2,695
  • 1
  • 17
  • 31
  • Hrm -- as you can probably tell, it's mad about something not existing. But, it's hard to guess _what_. If you `M-x toggle-debug-on-error` and try again, do you get a more verbose error? My assumption is that either the file you're trying to lint hasn't been written to disk, or one of the config values is a little off. – Gastove May 02 '16 at 20:40
  • I ran the command you suggested, but it didn't seem to change any behaviour and the error output was the same. – Jack Cargill May 03 '16 at 00:11
  • Dang. I was hoping you'd at least get a more informative stack trace. – Gastove May 03 '16 at 04:21

1 Answers1

3

I had very similar problem. I use OSX and both cargo and rustc weren't in exec-path. Because I see you have /Users path - I assume u run emacs on OSX too.

My solution was exec-path-from-shell plugin. I added to my init.el something like this:

(req-package exec-path-from-shell
    :config
    (if (eq system-type 'darwin)
        (exec-path-from-shell-initialize)))

And remember to run cargo build.

This article was very helpful when I was looking for a solution.

  • This answer led me to a solution. Installing the exec-path-from-shell plugin and adding the following to my init.el file as detailed in the provided link from @Frondeus worked like a charm: (when (memq window-system '(mac ns))(exec-path-from-shell-initialize)) – ramsey_tm Aug 25 '16 at 19:29
  • BTW, `rustup` [has problems with adding rust binaries to `PATH` automatically](https://github.com/rust-lang-nursery/rustup.rs/issues/371) on MacOS. – kolen Jan 29 '18 at 16:31