Skip to content

Commit b971c6d

Browse files
committed
Fix #151
When looking for a `where` in `rust-rewind-to-beginning-of-current-level-expr`, check that it is not part of a string or comment.
1 parent ed0b390 commit b971c6d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

rust-mode-tests.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,17 @@ impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap<K, V, S>
623623
}
624624
"))
625625

626+
(ert-deftest indent-align-where-in-comment ()
627+
(test-indent
628+
"/// - there must not exist an edge U->V in the graph where:
629+
#[derive(Clone, PartialEq, Eq)]
630+
pub struct Region { // <-- this should be flush with left margin!
631+
entry: BasicBlockIndex,
632+
leaves: BTreeMap<BasicBlockIndex, usize>,
633+
}
634+
"))
635+
636+
626637
(ert-deftest indent-square-bracket-alignment ()
627638
(test-indent
628639
"

rust-mode.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ function or trait. When nil, where will be aligned with fn or trait."
253253
;; where A: Eq
254254
;; B: Hash <- on this line
255255
(and (save-excursion
256-
(re-search-backward "\\bwhere\\b" function-start t))
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)))))
257263
(= current-level function-level)))
258264
(goto-char function-start)))))
259265

0 commit comments

Comments
 (0)