Skip to content

Commit e802d78

Browse files
mkpankovswsnr
authored andcommitted
Treat crates as binary if main.rs exists
Fixes syntax checking in binary crates, by going on the safe side of considering the whole crate binary if a binary root exists. Closes GH-18 and fixes GH-16
1 parent 4da768e commit e802d78

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

flycheck-rust.el

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ relative to the current file."
8585
(-when-let (exe-crate-dir (locate-dominating-file (buffer-file-name) "main.rs"))
8686
(expand-file-name "main.rs" exe-crate-dir))))
8787

88+
(defun flycheck-rust-binary-crate-p (crate-root)
89+
"Determine whether CRATE-ROOT is a binary crate.
90+
91+
CRATE-ROOT is the path to the root module of a crate.
92+
93+
Return non-nil if CRATE-ROOT is a binary crate, nil otherwise."
94+
(let ((root-dir (file-name-directory crate-root)))
95+
(file-exists-p (expand-file-name "src/main.rs" root-dir))))
96+
8897
;;;###autoload
8998
(defun flycheck-rust-setup ()
9099
"Setup Rust in Flycheck.
@@ -109,7 +118,8 @@ Flycheck according to the Cargo project layout."
109118
(not (flycheck-rust-executable-p rel-name)))
110119
;; Set the crate type
111120
(setq-local flycheck-rust-crate-type
112-
(if (flycheck-rust-executable-p rel-name) "bin" "lib"))
121+
(if (flycheck-rust-binary-crate-p flycheck-rust-crate-root)
122+
"bin" "lib"))
113123
;; Find build libraries
114124
(setq-local flycheck-rust-library-path
115125
(list (expand-file-name "target/debug" root)

0 commit comments

Comments
 (0)