Skip to content

Commit cc2435b

Browse files
authored
Merge pull request #264 from jjwest/master
Fixed indent when ? operator is used in chained method calls
2 parents 0d408d5 + b861aa9 commit cc2435b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

rust-mode-tests.el

+24
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,18 @@ fn main() {
16681668
"
16691669
)))
16701670

1671+
(ert-deftest indent-method-chains-no-align-with-question-mark-operator ()
1672+
(let ((rust-indent-method-chain nil)) (test-indent
1673+
"
1674+
fn main() {
1675+
let x = thing.do_it()
1676+
.aligned()
1677+
.more_alignment()?
1678+
.more_alignment();
1679+
}
1680+
"
1681+
)))
1682+
16711683
(ert-deftest indent-method-chains-with-align ()
16721684
(let ((rust-indent-method-chain t)) (test-indent
16731685
"
@@ -1679,6 +1691,18 @@ fn main() {
16791691
"
16801692
)))
16811693

1694+
(ert-deftest indent-method-chains-with-align-with-question-mark-operator ()
1695+
(let ((rust-indent-method-chain t)) (test-indent
1696+
"
1697+
fn main() {
1698+
let x = thing.do_it()
1699+
.aligned()
1700+
.more_alignment()?
1701+
.more_alignment();
1702+
}
1703+
"
1704+
)))
1705+
16821706
(ert-deftest indent-method-chains-with-align-and-second-stmt ()
16831707
(let ((rust-indent-method-chain t)) (test-indent
16841708
"

rust-mode.el

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ buffer."
320320
(- (current-column) rust-indent-offset)))))
321321
(cond
322322
;; foo.bar(...)
323-
((rust-looking-back-str ")")
323+
((looking-back "[)?]" (1- (point)))
324324
(backward-list 1)
325325
(funcall skip-dot-identifier))
326326

@@ -501,7 +501,7 @@ buffer."
501501
;; ..or if the previous line ends with any of these:
502502
;; { ? : ( , ; [ }
503503
;; then we are at the beginning of an expression, so stay on the baseline...
504-
(looking-back "[(,:;?[{}]\\|[^|]|" (- (point) 2))
504+
(looking-back "[(,:;[{}]\\|[^|]|" (- (point) 2))
505505
;; or if the previous line is the end of an attribute, stay at the baseline...
506506
(progn (rust-rewind-to-beginning-of-current-level-expr) (looking-at "#")))))
507507
baseline

0 commit comments

Comments
 (0)