flycheck / flycheck-rust

Better Rust/Cargo support for Flycheck

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rust-cargo detects the wrong crate type

romatthe opened this issue · comments

Hi,

The issue I'm opening here has been discussed in other issues, so I apologize if this is a duplicate, but I haven't been able to find a solution.

I'm trying to set up Emacs to work with Rust and Flycheck, but the rust-cargo checker keeps on crashing on me with the following error when running it against a simple but popular Rust repo, bat:

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 bat

I did the usual stuff:

flycheck-verify-setup:

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

First checker to run:

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

Checkers that could run if selected:

  rust  select
    - may enable: yes
    - predicate:  t
    - executable: Found at /home/romatthe/.cargo/bin/rustc

  rust-clippy  select
    - may enable: yes
    - predicate:  t
    - executable: Found at /home/romatthe/.cargo/bin/cargo
    - Clippy:     Found
    - Cargo.toml: Found

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

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

Flycheck version: 32snapshot
Emacs version:    26.2
System:           x86_64-pc-linux-gnu
Window system:    x

The report of rust-cargo is a little strange, because bat is a cat clone, so it's a --bin crate, not a --lib crate.

C-c ! C-c rust-cargo <RET>:

-*- mode: compilation; default-directory: "~/Source/bat/" -*-
Compilation started at Wed May 29 00:27:20

cargo test --no-run --lib --message-format\=json
error: no library targets found in package `bat`

Compilation exited abnormally with code 101 at Wed May 29 00:27:20

So it makes sense that the compilation commands fails, as there is no --lib target.

I tried to find out how flycheck.el or flycheck-rust.el determines the Crate type, but my elisp is terrible and I not very good at debugging Emacs.

Is this a problem with the setup of the bat Cargo.toml or with flycheck-rust?

Emacs version:

$ emacs --version
GNU Emacs 26.2

Cargo version:

$ cargo --version
cargo 1.35.0 (6f3e9c367 2019-04-04)

Flycheck version: git 47174a1

(Again, apologies if this a duplicate issue, I'm both a Rust and Emacs newbie)

Cannot reproduce. Diagnostics in the bat crate work fine here. Maybe something wrong in your flycheck-rust setup? This is the part that detects binary/library targets. What does M-: (flycheck-rust-find-cargo-target buffer-file-name) returns in a bat file? I get:

((kind . "bin") (name . "bat"))

Sorry for the delay, haven't been able to get back to the system where I'm having the issue. I will get back to you as soon as possible.

I can confirm that this happens on a newly created cargo project.

$ cargo new --bin rlisp
     Created binary (application) `rlisp` package

After editing src/main.rs and saving the file I get the original error message about suspicious state.

M-: (flycheck-rust-find-cargo-target buffer-file-name) results in ((kind . "bin") (name . "rlisp"))

Running flycheck-verify-setup originally showed similar output to what @romatthe observed. After running flycheck-rust-setup, the output of flycheck-verify-setup was correct and the error about a suspicious state went away.

After running flycheck-rust-setup,

@peschkaj Ah, yes, flycheck-rust-setup needs to be run on each Rust buffer, otherwise flycheck alone does not know which crate type it should check for. That's why we recommend putting flycheck-rust-setup in a hook in the README.