Skip to content

Commit 610fe1f

Browse files
author
Christian Howe
committed
Address review comments
1 parent 0256f02 commit 610fe1f

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

rust-mode.el

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,24 +1195,26 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
11951195
(with-current-buffer (get-buffer-create "*rustfmt*")
11961196
(erase-buffer)
11971197
(insert-buffer-substring buf)
1198-
(let ((tmpf (make-temp-file "rustfmt")))
1199-
(let ((ret (call-process-region (point-min) (point-max) rust-rustfmt-bin
1200-
t `(t ,tmpf) nil)))
1201-
(cond
1202-
((zerop ret)
1203-
(if (not (string= (buffer-string)
1204-
(with-current-buffer buf (buffer-string))))
1205-
(copy-to-buffer buf (point-min) (point-max)))
1206-
(kill-buffer))
1207-
((= ret 3)
1208-
(if (not (string= (buffer-string)
1209-
(with-current-buffer buf (buffer-string))))
1210-
(copy-to-buffer buf (point-min) (point-max)))
1211-
(erase-buffer)
1212-
(insert-file-contents tmpf)
1213-
(error "Rustfmt could not format some lines, see *rustfmt* buffer for details"))
1214-
(t
1215-
(error "Rustfmt failed, see *rustfmt* buffer for details")))))))
1198+
(let* ((tmpf (make-temp-file "rustfmt"))
1199+
(ret (call-process-region (point-min) (point-max) rust-rustfmt-bin
1200+
t `(t ,tmpf) nil)))
1201+
(unwind-protect
1202+
(cond
1203+
((zerop ret)
1204+
(if (not (string= (buffer-string)
1205+
(with-current-buffer buf (buffer-string))))
1206+
(copy-to-buffer buf (point-min) (point-max)))
1207+
(kill-buffer))
1208+
((= ret 3)
1209+
(if (not (string= (buffer-string)
1210+
(with-current-buffer buf (buffer-string))))
1211+
(copy-to-buffer buf (point-min) (point-max)))
1212+
(erase-buffer)
1213+
(insert-file-contents tmpf)
1214+
(error "Rustfmt could not format some lines, see *rustfmt* buffer for details"))
1215+
(t
1216+
(error "Rustfmt failed, see *rustfmt* buffer for details"))))
1217+
(delete-file tmpf))))
12161218

12171219
(defconst rust--format-word "\\b\\(else\\|enum\\|fn\\|for\\|if\\|let\\|loop\\|match\\|struct\\|unsafe\\|while\\)\\b")
12181220
(defconst rust--format-line "\\([\n]\\)")

0 commit comments

Comments
 (0)