Skip to content

Commit a789a25

Browse files
committed
Fix #168: use while in rust-rewind-irrelevant
Rewrite the recursive function `rust-rewind-irrelevant`, which causes a stack overflow in #168, using a `while` loop.
1 parent 5cfb919 commit a789a25

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

rust-mode.el

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,20 @@ function or trait. When nil, where will be aligned with fn or trait."
201201
(defun rust-paren-level () (nth 0 (syntax-ppss)))
202202
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
203203
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
204+
204205
(defun rust-rewind-irrelevant ()
205-
(let ((starting (point)))
206-
(skip-chars-backward "[:space:]\n")
207-
(if (rust-looking-back-str "*/") (backward-char))
208-
(if (rust-in-str-or-cmnt)
209-
(rust-rewind-past-str-cmnt))
210-
(if (/= starting (point))
211-
(rust-rewind-irrelevant))))
206+
(let ((continue t))
207+
(while continue
208+
(let ((starting (point)))
209+
(skip-chars-backward "[:space:]\n")
210+
(when (rust-looking-back-str "*/")
211+
(backward-char))
212+
(when (rust-in-str-or-cmnt)
213+
(rust-rewind-past-str-cmnt))
214+
;; Rewind until the point no longer moves
215+
(setq continue (/= starting (point)))))))
216+
217+
212218
(defun rust-in-macro ()
213219
(save-excursion
214220
(when (> (rust-paren-level) 0)

0 commit comments

Comments
 (0)