@@ -218,6 +218,21 @@ function or trait. When nil, where will be aligned with fn or trait."
218218 (rust-in-macro))
219219 )))
220220
221+ (defun rust-looking-at-where ()
222+ " Return T when looking at the \" where\" keyword."
223+ (and (looking-at-p " \\ bwhere\\ b" )
224+ (not (rust-in-str-or-cmnt))))
225+
226+ (defun rust-rewind-to-where (&optional limit )
227+ " Rewind the point to the closest occurrence of the \" where\" keyword.
228+ Return T iff a where-clause was found. Does not rewind past
229+ LIMIT when passed, otherwise only stops at the beginning of the
230+ buffer."
231+ (when (re-search-backward " \\ bwhere\\ b" limit t )
232+ (if (rust-in-str-or-cmnt)
233+ (rust-rewind-to-where limit)
234+ t )))
235+
221236(defun rust-align-to-expr-after-brace ()
222237 (save-excursion
223238 (forward-char )
@@ -248,12 +263,12 @@ function or trait. When nil, where will be aligned with fn or trait."
248263 (setq function-start (point )
249264 function-level (rust-paren-level)))
250265 ; ; On a where clause
251- (when (or (looking-at " \\ bwhere \\ b " )
266+ (when (or (rust- looking-at-where )
252267 ; ; or in one of the following lines, e.g.
253268 ; ; where A: Eq
254269 ; ; B: Hash <- on this line
255270 (and (save-excursion
256- (re-search-backward " \\ bwhere \\ b " function-start t ))
271+ (rust-rewind-to-where function-start))
257272 (= current-level function-level)))
258273 (goto-char function-start)))))
259274
@@ -392,7 +407,8 @@ function or trait. When nil, where will be aligned with fn or trait."
392407
393408 ; ; When the user chose not to indent the start of the where
394409 ; ; clause, put it on the baseline.
395- ((and (not rust-indent-where-clause) (looking-at " \\ bwhere\\ b" ))
410+ ((and (not rust-indent-where-clause)
411+ (rust-looking-at-where))
396412 baseline)
397413
398414 ; ; If we're in any other token-tree / sexp, then:
@@ -425,17 +441,16 @@ function or trait. When nil, where will be aligned with fn or trait."
425441 ; ; When we're not on a line starting with "where ", but
426442 ; ; still on a where-clause line, go to "where "
427443 (when (and
428- (not (looking-at " \\ bwhere \\ b " ))
444+ (not (rust- looking-at-where ))
429445 ; ; We're looking at something like "F: ..."
430- (and (looking-at (concat rust-re-ident " :" ))
431- ; ; There is a "where " somewhere after the
432- ; ; start of the function.
433- (re-search-backward " \\ bwhere\\ b"
434- function-start t )
435- ; ; Make sure we're not inside the function
436- ; ; already (e.g. initializing a struct) by
437- ; ; checking we are the same level.
438- (= function-level level)))
446+ (looking-at (concat rust-re-ident " :" ))
447+ ; ; There is a "where " somewhere after the
448+ ; ; start of the function.
449+ (rust-rewind-to-where function-start)
450+ ; ; Make sure we're not inside the function
451+ ; ; already (e.g. initializing a struct) by
452+ ; ; checking we are the same level.
453+ (= function-level level))
439454 ; ; skip over "where"
440455 (forward-char 5 )
441456 ; ; Unless "where" is at the end of the line
0 commit comments