rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.09k stars 176 forks source link

Rust-cargo failed, error: no override and no default toolchain set #451

Closed RArbore closed 2 years ago

RArbore commented 2 years ago

Hello - I recently reinstalled emacs and rustup on my machine, and I'm getting the above error whenever I open a .rs file.

I installed rust via rustup in the Arch repositories. I've also tried using the rustup script from the rustup.rs website, but I get the above error with both.

When running rustup default, I get... stable-x86_64-unknown-linux-gnu (default)

This is the full error from emacs:

Debugger entered--Lisp error: (error "Process rust-cargo failed with 1 (error: no override and no default toolchain set\n)")
  signal(error ("Process rust-cargo failed with 1 (error: no override and no default toolchain set\n)"))
  error("Process %s failed with %S (%s)" rust-cargo 1 "error: no override and no default toolchain set\n")
  flycheck-call-checker-process-for-output(rust-cargo nil t "metadata" "--no-deps" "--format-version" "1")
  flycheck-rust-cargo-metadata()
  flycheck-rust-cargo-workspace-root()
  #f(compiled-function (errors) #<bytecode -0x13b4b8c1b6a1c6ee>)(nil)
  flycheck-filter-errors(nil rust-cargo)
  flycheck-finish-current-syntax-check(nil "~/Work/vtrace-rs/")
  flycheck-report-buffer-checker-status(#s(flycheck-syntax-check :buffer #<buffer render.rs> :checker rust-cargo :context #<process flycheck-rust-cargo> :working-directory "~/Work/vtrace-rs/") finished nil)
  apply(flycheck-report-buffer-checker-status #s(flycheck-syntax-check :buffer #<buffer render.rs> :checker rust-cargo :context #<process flycheck-rust-cargo> :working-directory "~/Work/vtrace-rs/") (finished nil))
  #f(compiled-function (&rest args) #<bytecode -0x70df25aef77d770>)(finished nil)
  flycheck-finish-checker-process(rust-cargo 1 nil "error: no override and no default toolchain set\n" #f(compiled-function (&rest args) #<bytecode -0x70df25aef77d770>) "~/Work/vtrace-rs/")
  flycheck-handle-signal(#<process flycheck-rust-cargo> "exited abnormally with code 1\n")

Tried searching around, but couldn't find anything about this. Any help would be appreciated.

brotzeit commented 2 years ago

I've never seens this but seems to be a flycheck issue. You don't want to use lsp with flycheck ?

RArbore commented 2 years ago

I'm not quite sure I know what you mean - are you saying I shouldn't use lsp w/ flycheck?

My rust emacs config worked last time I used it on an old OS installation. Recently, I reinstalled and now I'm getting the above errors. Here is the relevant portion of my emacs config:

;; Rust mode
(use-package rust-mode
  :ensure t
  :mode "\\.rs\\'"
  :config (setq rust-format-on-save t)
  )
(use-package cargo
  :ensure t
  :init
  (add-hook 'rust-mode-hook 'cargo-minor-mode)
  (add-hook 'toml-mode-hook 'cargo-minor-mode)
  )
(use-package flycheck-rust
  :ensure t)
(add-hook 'rust-mode-hook
          (lambda () (setq indent-tabs-mode nil)))
(setq rust-format-on-save t)
(with-eval-after-load 'rust-mode
  (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))

Also, if I run cargo run in my terminal in my project, it works fine. However, if I use projectile to run cargo run, it complains that error: no override and no default toolchain set. Could this be some emacs issue regarding not getting environment variables from .bashrc?

RArbore commented 2 years ago

Turned out that was the issue - for those wondering, I used exec-path-from-shell in order to fix this, as I set my RUSTUP_HOME and CARGO_HOME environment variables to non-default values.

brotzeit commented 2 years ago

It looked like it was related to flycheck. But good to know that you fixed it by using exec-path-from-shell.