Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variable to fix rust-cargo error for multiple targets #958

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/languages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,13 @@ to view the docstring of the syntax checker. Likewise, you may use
The type of the crate to check, as string for the ``--crate-type``
option.

.. option:: flycheck-rust-binary-name

The name of the binary to pass to ``cargo rustc --bin``, as a string.

Only required when `flycheck-rust-crate-type` is ``bin`` and the crate
has multiple targets.

.. option:: flycheck-rust-library-path

A list of additional library directories. Relative paths are relative
Expand Down
18 changes: 17 additions & 1 deletion flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -8112,6 +8112,19 @@ for the `--crate-type' flag."
:package-version '("flycheck" . "0.20"))
(make-variable-buffer-local 'flycheck-rust-crate-type)

(flycheck-def-option-var flycheck-rust-binary-name nil rust-cargo
"The name of the binary to pass to `cargo rustc --bin'.

The value of this variable is a string denoting the name of the
binary to build: Either the name of the crate, or the name of one
of the files under `src/bin'.

This variable is used only when `flycheck-rust-crate-type' is
`bin', and is only useful for crates with multiple targets."
:type 'string
:safe #'stringp
:package-version '("flycheck" . "0.27"))

(flycheck-def-option-var flycheck-rust-library-path nil (rust-cargo rust)
"A list of library directories for Rust.

Expand All @@ -8127,7 +8140,10 @@ Relative paths are relative to the file being checked."

This syntax checker needs Cargo with rustc subcommand."
:command ("cargo" "rustc"
(eval (if (string= flycheck-rust-crate-type "lib") "--lib" nil))
(eval (cond
((string= flycheck-rust-crate-type "lib") "--lib")
(flycheck-rust-binary-name
(list "--bin" flycheck-rust-binary-name))))
"--" "-Z" "no-trans"
(option-flag "--test" flycheck-rust-check-tests)
(option-list "-L" flycheck-rust-library-path concat)
Expand Down
3 changes: 1 addition & 2 deletions test/flycheck-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -4145,8 +4145,7 @@ Why not:
(flycheck-ert-should-syntax-check
"language/rust/src/multiline-error.rs" 'rust-mode
'(7 9 error "mismatched types:
expected `u8`,\n found `i8`
(expected u8,\n found i8)" :checker rust :id "E0308")
expected `u8`,\n found `i8`" :checker rust :id "E0308")
'(7 9 info "run `rustc --explain E0308` to see a detailed explanation"
:checker rust))))

Expand Down