flycheck / flycheck-rust

Better Rust/Cargo support for Flycheck

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flycheck-rust-setup errors

mrcnski opened this issue · comments

I'm getting the following errors when opening a Rust buffer:

Error in flycheck-rust-setup: (invalid-function (packages (let-alist (with-temp-buffer (call-process cargo nil t nil "metadata" "--no-deps" "--manifest-path" manifest) (goto-char (point-min)) (let ((json-array-type (quote list))) (json-read))) \.packages)))
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

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 init.el setup:

(use-package rust-mode
  :defer t
  :mode "\\.rs\\'"
  :config (setq rust-format-on-save t)
  )

;; Run cargo commands in rust buffers, e.g. C-c C-c C-r for cargo-run
(use-package cargo
  :init
  (add-hook 'rust-mode-hook 'cargo-minor-mode)
  (add-hook 'toml-mode-hook 'cargo-minor-mode)
  )

(use-package racer
  :init
  (add-hook 'rust-mode-hook #'racer-mode)
  (add-hook 'racer-mode-hook #'eldoc-mode)
  :config
  (define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)
  (setq racer-rust-src-path "/usr/local/src/rust/src")
  )

;; Doesn't work, json-read-error
(use-package flycheck-rust
  :init
  (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))

Running flycheck-verify-setup:

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

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

  rust
    - may enable: yes
    - predicate:  t
    - executable: Found at /usr/local/bin/rustc

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

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

Flycheck version: 31snapshot (package: 20170324.340)
Emacs version:    26.0.50
System:           x86_64-pc-linux-gnu
Window system:    x

Thanks for the report. Not sure what's going on here. Maybe something in Emacs 26?

Maybe try to change the (when-let in flycheck-rust-get-cargo-targets to (-when-let*.

Can you report your cargo version as well?

Thanks, changing it to (-when-let fixed the first error for me. But I'm still getting this:

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

My cargo version is cargo 0.16.0-nightly (6e0c18c 2017-01-27)

Thanks for the help!

Okay so now that flycheck-rust-setup does run, it fails to correctly identify the targets in your cargo project. Can you share the output of cargo --metadata --no-deps for your project?

$ cargo metadata --no-deps
{"packages":[{"name":"dungeon-dude","version":"0.1.0","id":"dungeon-dude 0.1.0 (path+file:///home/johnny/Dropbox/Code/Rust/dungeon-dude)","license":null,"license_file":null,"source":null,"dependencies":[{"name":"sdl2","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.29","kind":null,"optional":false,"uses_default_features":false,"features":["ttf"],"target":null}],"targets":[{"kind":["bin"],"name":"dungeon-dude","src_path":"/home/johnny/Dropbox/Code/Rust/dungeon-dude/src/main.rs"}],"features":{},"manifest_path":"/home/johnny/Dropbox/Code/Rust/dungeon-dude/Cargo.toml"}],"workspace_members":["dungeon-dude 0.1.0 (path+file:///home/johnny/Dropbox/Code/Rust/dungeon-dude)"],"resolve":null,"version":1

Different project, same error:

$ cargo metadata --no-deps
{"packages":[{"name":"exercises","version":"0.1.0","id":"exercises 0.1.0 (path+file:///home/johnny/Dropbox/Code/Rust/exercises)","license":null,"license_file":null,"source":null,"dependencies":[],"targets":[{"kind":["bin"],"name":"exercises","src_path":"/home/johnny/Dropbox/Code/Rust/exercises/src/main.rs"}],"features":{},"manifest_path":"/home/johnny/Dropbox/Code/Rust/exercises/Cargo.toml"}],"workspace_members":["exercises 0.1.0 (path+file:///home/johnny/Dropbox/Code/Rust/exercises)"],"resolve":null,"version":1}

Hmm, no reason why it shouldn't work: nothing funny in the cargo output.

After you open main.rs and run M-x flycheck-rust-setup, does flycheck-verify-setup still report:

 - Cargo.toml:  Found
 - Crate type:  lib
 - Binary name: Not required

?

Yep, that report looks fine. I also just tried on Emacs 24.5. I even tried deleting my elpa folder to let use-package re-download and compile all of my packages for me. Same exact error.

Thanks, I'll see if I can reproduce on my side.

Hmm, wait. Did you change that line to -when-let* or -when-let?

Here's the change I was suggesting:

-    (when-let ((packages (let-alist
+    (-when-let* ((packages (let-alist

Glory hallelujah it worked! Sorry, I thought that asterisk was a typo. Thanks a lot!

So is this just an issue on my side? I'm curious why I'm the first one who's hit this.

Yeah, the asterisk was important. But I mistyped the backtick so it didn't look as code. Sorry about that.

The plain (when-let works in Emacs 25.1.1, so probably Emacs 26 made some changes to it. I guess not everyone is using the freshest Emacs from the repo.

Still a bug (just pushed the fix), thanks for reporting and for going through with the debugging 👍

This affects me yet. I should open a new Issue?
flycheck-verify-setup

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

  rust
    - may enable: yes
    - predicate:  t
    - executable: Found at /usr/bin/rustc

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

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

Flycheck version: 31snapshot (package: 20170715.1345)
Emacs version:    25.2.1
System:           x86_64-unknown-linux-gnu
Window system:    x

Version flycheck-rust: 20170404.842

I got this only on projects with more than one file, usually using cargo-rust checker via C-c ! C-c rust-cargo RET:

-*- mode: compilation; default-directory: "~/Desktop/project-church/src/" -*-
Compilation started at Sat Jul 15 22:00:17

cargo rustc --lib --message-format\=json -- -Z no-trans --test
error: no library targets found

Compilation exited abnormally with code 101 at Sat Jul 15 22:00:17

I don't have the first issue, but I'm also seeing

Suspicious state from syntax checker rust-cargo: Flycheck checker rust-cargo returned 101, but its output contained no errors: error: no library targets found in package