branch: elpa/rust-mode
commit a33b684a027b8f5efb1e197d7f3e294d2f271f26
Author: mrBliss <[email protected]>
Commit: mrBliss <[email protected]>
Fix #103: comment indentation after struct members
Correctly indent comments that come after struct members that do not
have a trailing comma.
Before:
struct A {
x: u8
// TOO FAR
}
After:
struct A {
x: u8
// CORRECT
}
---
rust-mode-tests.el | 18 ++++++++++++++++++
rust-mode.el | 4 +++-
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index e621f82..eb13128 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -600,6 +600,24 @@ fn foo() {
"
))
+;; This is a test for #103: a comment after the last struct member that does
+;; not have a trailing comma. The comment used to be indented one stop too
+;; far.
+(ert-deftest indent-comment-after-last-struct-member ()
+ (test-indent
+ "
+struct A {
+ x: u8
+ // comment
+}
+
+struct A {
+ x: u8
+ /* comment */
+}
+"
+ ))
+
(setq rust-test-motion-string
"
fn fn1(arg: int) -> bool {
diff --git a/rust-mode.el b/rust-mode.el
index 5b50d29..bc03023 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -369,7 +369,9 @@
;; baseline as well (we are continuing an expression,
;; but the "else" or "{" should align with the beginning
;; of the expression it's in.)
- (looking-at "\\<else\\>\\|{")
+ ;; Or, if this line starts a comment, stay on the
+ ;; baseline as well.
+ (looking-at "\\<else\\>\\|{\\|/[/*]")
(save-excursion
(rust-rewind-irrelevant)