flycheck / flycheck-rust

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

rust-cargo checker doesn't recognize crate type #64

Closed PatchesPrime closed 6 years ago

PatchesPrime commented 6 years ago

Hello,

I have combed through your issues page (and extensively looked via google) and could not find a solution to the problem. I have followed the installing instructions to the letter.

A few issues similar (if not the same, but still not working) to mine are: #16 #52 #23 I would have inquired there, but those issues are now closed.

Here is the information requested in those:

M-x flycheck-compile


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!


> M-x flycheck-verify-setup

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

rust-cargo

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


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



> M-x flycheck-rust-setup
`Error in flycheck-rust-setup: (wrong-type-argument listp packages)`

> $ cargo --version
`cargo 0.26.0 (41480f5cc 2018-02-26)`

> $ rustc --version
`rustc 1.25.0 (84203cac6 2018-03-25)`

> $ cargo metadata --no-deps --format-version=1
`{"packages":[{"name":"guessing_game","version":"0.1.0","id":"guessing_game 0.1.0 (path+file:///home/patches/projects/rust/guessing_game)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["bin"],"crate_types":["bin"],"name":"guessing_game","src_path":"/home/patches/projects/rust/guessing_game/src/main.rs"}],"features":{},"manifest_path":"/home/patches/projects/rust/guessing_game/Cargo.toml"}],"workspace_members":["guessing_game 0.1.0 (path+file:///home/patches/projects/rust/guessing_game)"],"resolve":null,"target_directory":"/home/patches/projects/rust/guessing_game/target","version":1,"workspace_root":"/home/patches/projects/rust/guessing_game"}`

As far as I can tell the issue seems to be not properly parsing the metadata to find the correct crate type. 
fmdkdd commented 6 years ago

Error in flycheck-rust-setup: (wrong-type-argument listp packages)

Here is the culprit. Can you enable stacktraces with M-x toggle-debug-on-error and retry M-x flycheck-rust-setup? Please copy the stracktrace so we can better see what's going on.

PatchesPrime commented 6 years ago

Sure thing.

Debugger entered--Lisp error: (wrong-type-argument listp packages)
  #[257 "\300@A@\"\207" [dash--match] 4 "\n\n(fn IT)"](packages)
  mapcar(#[257 "\300@A@\"\207" [dash--match] 4 "\n\n(fn IT)"] (packages (let-alist (with-temp-buffer (call-process cargo nil (quote (t nil)) nil "metadata" "--no-deps" "--manifest-path" manifest "--format-version" "1") (goto-char (point-min)) (let ((json-array-type (quote list))) (json-read))) \.packages)))
  #[642 "\300\301\302\303\304\305!\306\"\307\310%\311\312\313\314   \"\"#\207" [-reduce-r-from make-byte-code 512 "@A@\301DC\302\300BBBE\207" vconcat vector [let if] 10 "\n\n(fn &optional IT ACC)" apply append mapcar #[257 "\300@A@\"\207" [dash--match] 4 "\n\n(fn IT)"]] 11 ("/home/patches/.emacs.d/elpa/dash-20180310.1317/dash.elc" . 68209)]((packages (let-alist (with-temp-buffer (call-process cargo nil (quote (t nil)) nil "metadata" "--no-deps" "--manifest-path" manifest "--format-version" "1") (goto-char (point-min)) (let ((json-array-type (quote list))) (json-read))) \.packages)) (progn (seq-map (lambda (pkg) (let-alist pkg \.targets)) packages)))
  (-if-let* (packages (let-alist (with-temp-buffer (call-process cargo nil (quote (t nil)) nil "metadata" "--no-deps" "--manifest-path" manifest "--format-version" "1") (goto-char (point-min)) (let ((json-array-type (quote list))) (json-read))) \.packages)) (progn (seq-map (lambda (pkg) (let-alist pkg \.targets)) packages)))
  (-when-let* (packages (let-alist (with-temp-buffer (call-process cargo nil (quote (t nil)) nil "metadata" "--no-deps" "--manifest-path" manifest "--format-version" "1") (goto-char (point-min)) (let ((json-array-type (quote list))) (json-read))) \.packages)) (seq-map (lambda (pkg) (let-alist pkg \.targets)) packages))
  (let ((cargo (funcall flycheck-executable-find "cargo"))) (unless cargo (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.")) (-when-let* (packages (let-alist (with-temp-buffer (call-process cargo nil (quote (t nil)) nil "metadata" "--no-deps" "--manifest-path" manifest "--format-version" "1") (goto-char (point-min)) (let ((json-array-type ...)) (json-read))) \.packages)) (seq-map (lambda (pkg) (let-alist pkg \.targets)) packages)))
  flycheck-rust-get-cargo-targets("/home/patches/projects/rust/guessing_game/Cargo.toml")
  (let ((packages (flycheck-rust-get-cargo-targets manifest))) (if packages (let ((targets (-flatten-n 1 packages))) (if targets (progn (let ((target ...)) (if (string= "custom-build" ...) (progn ...)) (if target (progn ...))))))))
  (if manifest (let ((packages (flycheck-rust-get-cargo-targets manifest))) (if packages (let ((targets (-flatten-n 1 packages))) (if targets (progn (let (...) (if ... ...) (if target ...))))))))
  (let ((manifest (flycheck-rust-find-manifest file-name))) (if manifest (let ((packages (flycheck-rust-get-cargo-targets manifest))) (if packages (let ((targets (-flatten-n 1 packages))) (if targets (progn (let ... ... ...))))))))
  flycheck-rust-find-cargo-target("/home/patches/projects/rust/guessing_game/src/main.rs")
  (let ((--dash-source-2-- (flycheck-rust-find-cargo-target file-name))) (if --dash-source-2-- (let ((kind (car-safe (prog1 --dash-source-2-- (setq --dash-source-2-- ...))))) (if kind (let ((name --dash-source-2--)) (if name (progn (set ... kind) (set ... name))))))))
  (if file-name (let ((--dash-source-2-- (flycheck-rust-find-cargo-target file-name))) (if --dash-source-2-- (let ((kind (car-safe (prog1 --dash-source-2-- ...)))) (if kind (let ((name --dash-source-2--)) (if name (progn ... ...))))))))
  (let ((file-name (buffer-file-name))) (if file-name (let ((--dash-source-2-- (flycheck-rust-find-cargo-target file-name))) (if --dash-source-2-- (let ((kind (car-safe ...))) (if kind (let (...) (if name ...))))))))
  (condition-case err (let ((file-name (buffer-file-name))) (if file-name (let ((--dash-source-2-- (flycheck-rust-find-cargo-target file-name))) (if --dash-source-2-- (let ((kind ...)) (if kind (let ... ...))))))) ((debug error) (message "Error in flycheck-rust-setup: %S" err) nil))
  flycheck-rust-setup()
  funcall-interactively(flycheck-rust-setup)
  call-interactively(flycheck-rust-setup record nil)
  command-execute(flycheck-rust-setup record)
  execute-extended-command(nil "flycheck-rust-setup" "flycheck-rust-setup")
  funcall-interactively(execute-extended-command nil "flycheck-rust-setup" "flycheck-rust-setup")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
fmdkdd commented 6 years ago

Can you try M-: (flycheck-rust-get-cargo-targets "/home/patches/projects/rust/guessing_game/Cargo.toml") and report its results (which you can see in the *Messages* buffer)?

PatchesPrime commented 6 years ago
Debugger entered--Lisp error: (void-function flycheck-rust-get-cargo-targets)
  (flycheck-rust-get-cargo-targets "/home/patches/projects/rust/guessing_game/Cargo.toml")
  eval((flycheck-rust-get-cargo-targets "/home/patches/projects/rust/guessing_game/Cargo.toml") nil)
  eval-expression((flycheck-rust-get-cargo-targets "/home/patches/projects/rust/guessing_game/Cargo.toml") nil)
  funcall-interactively(eval-expression (flycheck-rust-get-cargo-targets "/home/patches/projects/rust/guessing_game/Cargo.toml") nil)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

Sayin' the function doesn't exist, looks like. If I run the flycheck-rust-setup first (which still errors) it will give mapcar: Wrong type argument: listp, packages instead.

fmdkdd commented 6 years ago

Okay, another snippet to try:

(let* ((cargo (funcall flycheck-executable-find "cargo"))
       (raw-output)
       (json-output
        (with-temp-buffer
          (call-process cargo nil '(t nil) nil
                        "metadata" "--no-deps"
                        "--manifest-path" "/home/patches/projects/rust/guessing_game/Cargo.toml"
                        "--format-version" "1")
          (setq raw-output (buffer-substring (point-min) (point-max)))
          (goto-char (point-min))
          (let ((json-array-type 'list))
            (json-read))))
       (packages (let-alist json-output .packages)))
  (message "\n-- BEGIN --\n")
  (message "dash: %s" (pkg-info-version-info 'dash))
  (message "seq: %s" (pkg-info-version-info 'seq))
  (message "let-alist: %s" (pkg-info-version-info 'let-alist))
  (message "cargo: %S\n" cargo)
  (message "raw-output: %s" raw-output)
  (message "json-output: %S\n" json-output)
  (message "packages: %S\n" packages)
  (message "\n-- END --\n"))

Please execute that using M-: <paste> RET and report the output in *Messages*. Hopefully this is the last!

PatchesPrime commented 6 years ago

From the Backtrace buffer on first run:

Debugger entered--Lisp error: (void-variable flycheck-executable-find)
  (funcall flycheck-executable-find "cargo")
  (let* ((cargo (funcall flycheck-executable-find "cargo")) (raw-output) (json-output (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (call-process cargo nil ... nil "metadata" "--no-deps" "--manifest-path" "/home/patches/projects/rust/guessing_game/Cargo.toml" "--format-version" "1") (setq raw-output ...) (goto-char ...) (let ... ...)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))) (packages (let ((alist json-output)) (let ((\.packages (cdr ...))) \.packages)))) (message "\n-- BEGIN --\n") (message "dash: %s" (pkg-info-version-info (quote dash))) (message "seq: %s" (pkg-info-version-info (quote seq))) (message "let-alist: %s" (pkg-info-version-info (quote let-alist))) (message "cargo: %S\n" cargo) (message "raw-output: %s" raw-output) (message "json-output: %S\n" json-output) (message "packages: %S\n" packages) (message "\n-- END --\n"))
  eval((let* ((cargo (funcall flycheck-executable-find "cargo")) (raw-output) (json-output (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (call-process cargo nil ... nil "metadata" "--no-deps" "--manifest-path" "/home/patches/projects/rust/guessing_game/Cargo.toml" "--format-version" "1") (setq raw-output ...) (goto-char ...) (let ... ...)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))) (packages (let ((alist json-output)) (let ((\.packages (cdr ...))) \.packages)))) (message "\n-- BEGIN --\n") (message "dash: %s" (pkg-info-version-info (quote dash))) (message "seq: %s" (pkg-info-version-info (quote seq))) (message "let-alist: %s" (pkg-info-version-info (quote let-alist))) (message "cargo: %S\n" cargo) (message "raw-output: %s" raw-output) (message "json-output: %S\n" json-output) (message "packages: %S\n" packages) (message "\n-- END --\n")) nil)
  eval-expression((let* ((cargo (funcall flycheck-executable-find "cargo")) (raw-output) (json-output (with-temp-buffer (call-process cargo nil (quote (t nil)) nil "metadata" "--no-deps" "--manifest-path" "/home/patches/projects/rust/guessing_game/Cargo.toml" "--format-version" "1") (setq raw-output (buffer-substring (point-min) (point-max))) (goto-char (point-min)) (let ((json-array-type (quote list))) (json-read)))) (packages (let-alist json-output \.packages))) (message "\n-- BEGIN --\n") (message "dash: %s" (pkg-info-version-info (quote dash))) (message "seq: %s" (pkg-info-version-info (quote seq))) (message "let-alist: %s" (pkg-info-version-info (quote let-alist))) (message "cargo: %S\n" cargo) (message "raw-output: %s" raw-output) (message "json-output: %S\n" json-output) (message "packages: %S\n" packages) (message "\n-- END --\n")) nil)
  funcall-interactively(eval-expression (let* ((cargo (funcall flycheck-executable-find "cargo")) (raw-output) (json-output (with-temp-buffer (call-process cargo nil (quote (t nil)) nil "metadata" "--no-deps" "--manifest-path" "/home/patches/projects/rust/guessing_game/Cargo.toml" "--format-version" "1") (setq raw-output (buffer-substring (point-min) (point-max))) (goto-char (point-min)) (let ((json-array-type (quote list))) (json-read)))) (packages (let-alist json-output \.packages))) (message "\n-- BEGIN --\n") (message "dash: %s" (pkg-info-version-info (quote dash))) (message "seq: %s" (pkg-info-version-info (quote seq))) (message "let-alist: %s" (pkg-info-version-info (quote let-alist))) (message "cargo: %S\n" cargo) (message "raw-output: %s" raw-output) (message "json-output: %S\n" json-output) (message "packages: %S\n" packages) (message "\n-- END --\n")) nil)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

However, after doing M-x flycheck-rust-setup as before (before I execute the elisp) I get this in messages:

-- BEGIN --

dash: 20180310.1317
uncompressing seq.el.gz...done
uncompressing seq.el.gz...done
seq: 2.3
let-alist: 1.0.5
cargo: "/home/patches/.cargo/bin/cargo"

raw-output: {"packages":[{"name":"guessing_game","version":"0.1.0","id":"guessing_game 0.1.0 (path+file:///home/patches/projects/rust/guessing_game)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[{"name":"rand","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.4.0","kind":null,"optional":false,"uses_default_features":true,"features":[],"target":null}],"targets":[{"kind":["bin"],"crate_types":["bin"],"name":"guessing_game","src_path":"/home/patches/projects/rust/guessing_game/src/main.rs"}],"features":{},"manifest_path":"/home/patches/projects/rust/guessing_game/Cargo.toml"}],"workspace_members":["guessing_game 0.1.0 (path+file:///home/patches/projects/rust/guessing_game)"],"resolve":null,"target_directory":"/home/patches/projects/rust/guessing_game/target","version":1,"workspace_root":"/home/patches/projects/rust/guessing_game"}

json-output: ((packages ((name . "guessing_game") (version . "0.1.0") (id . "guessing_game 0.1.0 (path+file:///home/patches/projects/rust/guessing_game)") (license) (license_file) (description) (source) (dependencies ((name . "rand") (source . "registry+https://github.com/rust-lang/crates.io-index") (req . "^0.4.0") (kind) (optional . :json-false) (uses_default_features . t) (features) (target))) (targets ((kind "bin") (crate_types "bin") (name . "guessing_game") (src_path . "/home/patches/projects/rust/guessing_game/src/main.rs"))) (features) (manifest_path . "/home/patches/projects/rust/guessing_game/Cargo.toml"))) (workspace_members "guessing_game 0.1.0 (path+file:///home/patches/projects/rust/guessing_game)") (resolve) (target_directory . "/home/patches/projects/rust/guessing_game/target") (version . 1) (workspace_root . "/home/patches/projects/rust/guessing_game"))

packages: (((name . "guessing_game") (version . "0.1.0") (id . "guessing_game 0.1.0 (path+file:///home/patches/projects/rust/guessing_game)") (license) (license_file) (description) (source) (dependencies ((name . "rand") (source . "registry+https://github.com/rust-lang/crates.io-index") (req . "^0.4.0") (kind) (optional . :json-false) (uses_default_features . t) (features) (target))) (targets ((kind "bin") (crate_types "bin") (name . "guessing_game") (src_path . "/home/patches/projects/rust/guessing_game/src/main.rs"))) (features) (manifest_path . "/home/patches/projects/rust/guessing_game/Cargo.toml")))

-- END --

"
-- END --
"

If it's not the last one that's fine, I just want it to work. :)

fmdkdd commented 6 years ago

That's strange. It seems to parse fine here, but somehow packages ends up invalid when calling flycheck-rust-setup. I can't reproduce on my end. Do you have the issue on every Rust project, or just this one?

If you create a new binary project with cargo --new foo and open the src/main.rs file, does it work?

I would suggest reinstalling dash using package-reinstall dash and see if that makes a difference.

PatchesPrime commented 6 years ago

As far as the command cargo --new foo, --new is an unknown flag. It's just 'new'. Anyway, here is the output.

$ cargo new foo
     Created binary (application) `foo` project

When doing flycheck-rust-setup, same result. It does not in fact work for other projects. Same across all of them. Error in flycheck-rust-setup: (wrong-type-argument listp packages)

I reinstalled dash but that provided no benefit as far as I can tell. Exact same everything across the board.

I have however made SOME progress. It may be some package conflict (looking into it when I have more time to do so) as when I start from a fresh emacs install (no packages but rust-mode and flycheck-rust added on) it works.

I will report what I find if you leave the issue open, or you can close it as a package conflict isn't your problem and I totally understand that.

PatchesPrime commented 6 years ago

Okay, so I suppose something even more bizarre was at play. I decided I'd just go ahead and install all my packages again from a fresh install (I'm a simple man, only like 80 of them..) one by one and open the project then run M-x flycheck-rust-setup.

Now I can no longer reproduce it with the fresh package installs.

Something strange is happening, but it's not flycheck-rust.

You can close the issue if you like, thanks kindly for the attentive help.

fmdkdd commented 6 years ago

Ah! Too bad we didn't catch the bug. Glad it works for you :)