@@ -131,35 +131,44 @@ Flycheck according to the Cargo project layout."
131
131
(interactive )
132
132
(when (buffer-file-name )
133
133
(-when-let (root (flycheck-rust-project-root))
134
- (pcase-let ((rel-name (file-relative-name (buffer-file-name ) root))
135
- (`(, target-type . , target-name ) (flycheck-rust-find-target
134
+ ; ; We should avoid raising any error in this function, as in combination
135
+ ; ; with `global-flycheck-mode' it will render Emacs unusable (see
136
+ ; ; https://github.com/flycheck/flycheck-rust/issues/40#issuecomment-253760883).
137
+ (if (not (funcall flycheck-executable-find " cargo" ))
138
+ ; ; We can still inform the user though
139
+ (message " flycheck-rust cannot find `cargo' . Please \
140
+ make sure that cargo is installed and on your PATH. See \
141
+ http://www.flycheck.org/en/latest/user/troubleshooting.html for \
142
+ more information on setting your PATH with Emacs. " )
143
+ (pcase-let ((rel-name (file-relative-name (buffer-file-name ) root))
144
+ (`(, target-type . , target-name ) (flycheck-rust-find-target
136
145
(buffer-file-name ))))
137
- ; ; These are valid crate roots as by Cargo's layout
138
- (if (or (flycheck-rust-executable-p rel-name)
139
- (flycheck-rust-test-p rel-name)
140
- (flycheck-rust-bench-p rel-name)
141
- (flycheck-rust-example-p rel-name)
142
- (string= " src/lib.rs" rel-name))
143
- (setq-local flycheck-rust-crate-root rel-name)
144
- ; ; For other files, the library is either the default library or the
145
- ; ; executable
146
- (setq-local flycheck-rust-crate-root (flycheck-rust-find-crate-root)))
147
- ; ; Check tests in libraries and integration tests
148
- (setq-local flycheck-rust-check-tests
149
- (not (flycheck-rust-executable-p rel-name)))
150
- ; ; Set the crate type
151
- (setq-local flycheck-rust-crate-type
152
- (if (string= target-type " bin" )
153
- (progn
154
- ; ; If it's binary target, we need to pass the binary
155
- ; ; name
156
- (setq-local flycheck-rust-binary-name target-name)
157
- " bin" )
158
- " lib" ))
159
- ; ; Find build libraries
160
- (setq-local flycheck-rust-library-path
161
- (list (expand-file-name " target/debug" root)
162
- (expand-file-name " target/debug/deps" root)))))))
146
+ ; ; These are valid crate roots as by Cargo's layout
147
+ (if (or (flycheck-rust-executable-p rel-name)
148
+ (flycheck-rust-test-p rel-name)
149
+ (flycheck-rust-bench-p rel-name)
150
+ (flycheck-rust-example-p rel-name)
151
+ (string= " src/lib.rs" rel-name))
152
+ (setq-local flycheck-rust-crate-root rel-name)
153
+ ; ; For other files, the library is either the default library or the
154
+ ; ; executable
155
+ (setq-local flycheck-rust-crate-root (flycheck-rust-find-crate-root)))
156
+ ; ; Check tests in libraries and integration tests
157
+ (setq-local flycheck-rust-check-tests
158
+ (not (flycheck-rust-executable-p rel-name)))
159
+ ; ; Set the crate type
160
+ (setq-local flycheck-rust-crate-type
161
+ (if (string= target-type " bin" )
162
+ (progn
163
+ ; ; If it's binary target, we need to pass the binary
164
+ ; ; name
165
+ (setq-local flycheck-rust-binary-name target-name)
166
+ " bin" )
167
+ " lib" ))
168
+ ; ; Find build libraries
169
+ (setq-local flycheck-rust-library-path
170
+ (list (expand-file-name " target/debug" root)
171
+ (expand-file-name " target/debug/deps" root) )))))))
163
172
164
173
(provide 'flycheck-rust )
165
174
0 commit comments