@@ -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,18 +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- (and
257- ; ; There is a where clause,
258- (re-search-backward " \\ bwhere\\ b" function-start t )
259- ; ; but not inside a string,
260- (not (nth 3 (syntax-ppss )))
261- ; ; nor inside a comment
262- (not (nth 4 (syntax-ppss )))))
271+ (rust-rewind-to-where function-start))
263272 (= current-level function-level)))
264273 (goto-char function-start)))))
265274
@@ -398,7 +407,8 @@ function or trait. When nil, where will be aligned with fn or trait."
398407
399408 ; ; When the user chose not to indent the start of the where
400409 ; ; clause, put it on the baseline.
401- ((and (not rust-indent-where-clause) (looking-at " \\ bwhere\\ b" ))
410+ ((and (not rust-indent-where-clause)
411+ (rust-looking-at-where))
402412 baseline)
403413
404414 ; ; If we're in any other token-tree / sexp, then:
@@ -431,17 +441,16 @@ function or trait. When nil, where will be aligned with fn or trait."
431441 ; ; When we're not on a line starting with "where ", but
432442 ; ; still on a where-clause line, go to "where "
433443 (when (and
434- (not (looking-at " \\ bwhere \\ b " ))
444+ (not (rust- looking-at-where ))
435445 ; ; We're looking at something like "F: ..."
436- (and (looking-at (concat rust-re-ident " :" ))
437- ; ; There is a "where " somewhere after the
438- ; ; start of the function.
439- (re-search-backward " \\ bwhere\\ b"
440- function-start t )
441- ; ; Make sure we're not inside the function
442- ; ; already (e.g. initializing a struct) by
443- ; ; checking we are the same level.
444- (= 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))
445454 ; ; skip over "where"
446455 (forward-char 5 )
447456 ; ; Unless "where" is at the end of the line
0 commit comments