Skip to content

Commit a33b684

Browse files
committed
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 }
1 parent 0601540 commit a33b684

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

rust-mode-tests.el

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,24 @@ fn foo() {
600600
"
601601
))
602602

603+
;; This is a test for #103: a comment after the last struct member that does
604+
;; not have a trailing comma. The comment used to be indented one stop too
605+
;; far.
606+
(ert-deftest indent-comment-after-last-struct-member ()
607+
(test-indent
608+
"
609+
struct A {
610+
x: u8
611+
// comment
612+
}
613+
614+
struct A {
615+
x: u8
616+
/* comment */
617+
}
618+
"
619+
))
620+
603621
(setq rust-test-motion-string
604622
"
605623
fn fn1(arg: int) -> bool {

rust-mode.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@
369369
;; baseline as well (we are continuing an expression,
370370
;; but the "else" or "{" should align with the beginning
371371
;; of the expression it's in.)
372-
(looking-at "\\<else\\>\\|{")
372+
;; Or, if this line starts a comment, stay on the
373+
;; baseline as well.
374+
(looking-at "\\<else\\>\\|{\\|/[/*]")
373375

374376
(save-excursion
375377
(rust-rewind-irrelevant)

0 commit comments

Comments
 (0)