flycheck / flycheck-rust

Better Rust/Cargo support for Flycheck
GNU General Public License v3.0
121 stars 19 forks source link

emacs 24, I get different kinds of errors even though I am running latest version of all #70

Closed otuk closed 6 years ago

otuk commented 6 years ago

I have used rustup to update my stable as well as my nightly toolchain on commandline which cargo responds as expected (~/.cargo/bin/cargo), so cargo is on my path.

in emacs v24 error messages as soon as I open a rust file I see the following with the STABLE toolchain (rustc version 1.29.2) The editions related issue goes away if I use NIGHTLY toolchain. So that is not a concern.

The real issue is none of the in editor flycheck "checks" are happening. I cannot use the cargo build/run etc shortcuts either

It is very possible there is some stupid mistake in my setup but I could not see it. BTW if I run emacs25-nox with same installation and copy of the rust configuration, things run, but in nox version :(

Error in flycheck-rust-setup: (user-error "flycheck-rust cannot find `cargo'.  Please make sure that cargo is installed and on your PATH.  See http://www.flycheck.org/en/latest/user/troubleshooting.html for more information on setting your PATH with Emacs.")
Suspicious state from syntax checker rust-cargo: Flycheck checker rust-cargo returned non-zero exit code 101, but its output contained no errors: error: failed to parse manifest at `/home/otuk/prj/rustprj/bestruk/Cargo.toml`

Caused by:
  editions are unstable

Caused by:
  feature `edition` is required

this Cargo does not support nightly features, but if you
switch to nightly channel you can add
`cargo-features = ["edition"]` to enable this feature

Try installing a more recent version of rust-cargo, and please open a bug report if the issue persists in the latest release.  Thanks!
Error from syntax checker rust-cargo: Searching for program: no such file or directory, cargo

this is the real error message errors with nightly toolchain, all other config kept same:

Error in flycheck-rust-setup: (user-error "flycheck-rust cannot find `cargo'.  Please make sure that cargo is installed and on your PATH.  See http://www.flycheck.org/en/latest/user/troubleshooting.html for more information on setting your PATH with Emacs.")
Suspicious state from syntax checker rust-cargo: Flycheck checker rust-cargo returned non-zero exit code 101, but its output contained no errors: error: no library targets found in package `bestruk`

Try installing a more recent version of rust-cargo, and please open a bug report if the issue persists in the latest release.  Thanks!

my flycheck verification shows the following while I am in the same rust file:

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

  rust-cargo
    - may enable:  yes
    - predicate:   t
    - executable:  Found at /home/otuk/.cargo/bin/cargo
    - Cargo.toml:  Found
    - Crate type:  lib
    - Binary name: Not required

  rust
    - may enable: Automatically disabled!
    - predicate:  t
    - executable: Not found

  rust-clippy
    - may enable: Automatically disabled!
    - predicate:  t
    - executable: Not found
    - Clippy:     Cannot find the `cargo clippy' command
    - Cargo.toml: Found

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

--------------------

Flycheck version: 32snapshot (package: 20180907.1319)
Emacs version:    24.5.1
System:           x86_64-pc-linux-gnu
Window system:    x
Syntax checkers for buffer main.rs in rust-mode:

  rust-cargo
    - may enable:  yes
    - predicate:   t
    - executable:  Found at /home/otuk/.cargo/bin/cargo
    - Cargo.toml:  Found
    - Crate type:  lib
    - Binary name: Not required

  rust
    - may enable: Automatically disabled!
    - predicate:  t
    - executable: Not found

  rust-clippy
    - may enable: Automatically disabled!
    - predicate:  t
    - executable: Not found
    - Clippy:     Cannot find the `cargo clippy' command
    - Cargo.toml: Found

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

--------------------

Flycheck version: 32snapshot (package: 20180907.1319)
Emacs version:    24.5.1
System:           x86_64-pc-linux-gnu
Window system:    x

my rust coding related config:

#+BEGIN_SRC emacs-lisp
    ;; install major mode
    (use-package rust-mode
       :ensure t
       )

    ;;install cargo minor mode
    ;; C-c C-c C-b to run cargo build
    ;; C-c C-c C-r to run cargo run
    ;; C-c C-c C-t to run cargo test
    (use-package cargo
      :ensure t
      )

  ;;;
  (add-hook 'rust-mode-hook 'cargo-minor-mode)

  (add-hook 'rust-mode-hook
            (lambda ()
              (local-set-key (kbd "C-c <tab>") #'rust-format-buffer)))

  ;;install code completion
  ;; required step - clone rust src with:   
  ;;     git clone https://github.com/rust-lang/rust.git
  ;; required step - install racer with: (oh this step requires rust - nightly)
  ;;     cargo install racer 
  (use-package racer
    :ensure t
    :init
    ;; set rustup binaries PATH
    (setq racer-cmd "~/.cargo/bin/racer")
    ;; Rust source OWN! rust code PATH
    (setq racer-rust-src-path "~/Apps/rust/src/")  ;; I have a separate copy of source here/not needed
    (add-hook 'rust-mode-hook #'racer-mode)
    (add-hook 'racer-mode-hook #'eldoc-mode)
    (add-hook 'racer-mode-hook #'company-mode)
    )

   ;;error check
   (use-package flycheck-rust
     :ensure t
     :config
     (setq flycheck-rust-cargo-executable "~/.cargo/bin/cargo")
     (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)
     )

    ;;activate yasnippets for rust
    (add-hook 'rust-mode-hook
              '(lambda ()
                 (yas-minor-mode-on)))

#+END_SRC
fmdkdd commented 6 years ago

Hmm, it's surprising that you get different behavior in emacs25-nox and in emacs24. But as for flycheck-rust not finding cargo, it's because you are using:

(setq flycheck-rust-cargo-executable "~/.cargo/bin/cargo")

This is a Flycheck variable used to override the checker executable, but flycheck-rust uses flycheck-executable-find to locate cargo by looking in your PATH. It's confusing because cargo is both the checker command and the program we use to configure your project. And also because the prefix flycheck-rust might makes one think it belong to the flycheck-rust package but it's actually a flycheck.el variable.

So I suggest either customizing flycheck-executable-find in your (use-package flycheck-rust config, or better yet add ~/.cargo/bin/cargo to Emacs' PATH.

otuk commented 6 years ago

Thank you @fmdkdd

I made the change for PATH in config.org within the cargo area and kept everything else the same:

      ;;install cargo minor mode
      ;; C-c C-c C-b to run cargo build
      ;; C-c C-c C-r to run cargo run
      ;; C-c C-c C-t to run cargo test
      (use-package cargo
        :ensure t
        :config 
        ;; change emacs PATH o include cargo/bin
        (setenv "PATH" (concat (getenv "PATH") ":~/.cargo/bin"))
        (setq exec-path (append exec-path '("~/.cargo/bin")))
        )

And I get to see the flycheck results :) Yipee.

But I still cannot do C-c C-c C-b to do a build directly, I know this is not fly check related, but maybe I get help?

Any such action generates the following error, I did not find any reference to it for cargo related modules in google searches.

cargo-process--workspace-root: Symbol's function definition is void: alist-get
fmdkdd commented 6 years ago

And I get to see the flycheck results :) Yipee.

Yeah!

cargo-process--workspace-root: Symbol's function definition is void: alist-get

This is a cargo-mode bug: the package claims Emacs 24.3 support, but alist-get is in Emacs 25+. I see you've reported https://github.com/kwrooijen/cargo.el/issues/67, so I will close this one here.

otuk commented 6 years ago

@fmdkdd, thanks again