branch: elpa/rust-mode
commit b971c6dd1c9356d4ace237c7e173dcbcb454a992
Author: mrBliss <[email protected]>
Commit: mrBliss <[email protected]>
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.
---
rust-mode-tests.el | 11 +++++++++++
rust-mode.el | 8 +++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index de3900c..1e0207d 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -623,6 +623,17 @@ impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap<K,
V, S>
}
"))
+(ert-deftest indent-align-where-in-comment ()
+ (test-indent
+ "/// - there must not exist an edge U->V in the graph where:
+#[derive(Clone, PartialEq, Eq)]
+pub struct Region { // <-- this should be flush with left margin!
+ entry: BasicBlockIndex,
+ leaves: BTreeMap<BasicBlockIndex, usize>,
+}
+"))
+
+
(ert-deftest indent-square-bracket-alignment ()
(test-indent
"
diff --git a/rust-mode.el b/rust-mode.el
index 647e6b1..7a7b78c 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -253,7 +253,13 @@ function or trait. When nil, where will be aligned with
fn or trait."
;; where A: Eq
;; B: Hash <- on this line
(and (save-excursion
- (re-search-backward "\\bwhere\\b" function-start t))
+ (and
+ ;; There is a where clause,
+ (re-search-backward "\\bwhere\\b" function-start t)
+ ;; but not inside a string,
+ (not (nth 3 (syntax-ppss)))
+ ;; nor inside a comment
+ (not (nth 4 (syntax-ppss)))))
(= current-level function-level)))
(goto-char function-start)))))