Skip to content

Commit

Permalink
Merge pull request rust-lang#264 from jjwest/master
Browse files Browse the repository at this point in the history
Fixed indent when ? operator is used in chained method calls
  • Loading branch information
nikomatsakis authored Feb 21, 2018
2 parents 0d408d5 + b861aa9 commit cc2435b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions rust-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,18 @@ fn main() {
"
)))

(ert-deftest indent-method-chains-no-align-with-question-mark-operator ()
(let ((rust-indent-method-chain nil)) (test-indent
"
fn main() {
let x = thing.do_it()
.aligned()
.more_alignment()?
.more_alignment();
}
"
)))

(ert-deftest indent-method-chains-with-align ()
(let ((rust-indent-method-chain t)) (test-indent
"
Expand All @@ -1679,6 +1691,18 @@ fn main() {
"
)))

(ert-deftest indent-method-chains-with-align-with-question-mark-operator ()
(let ((rust-indent-method-chain t)) (test-indent
"
fn main() {
let x = thing.do_it()
.aligned()
.more_alignment()?
.more_alignment();
}
"
)))

(ert-deftest indent-method-chains-with-align-and-second-stmt ()
(let ((rust-indent-method-chain t)) (test-indent
"
Expand Down
4 changes: 2 additions & 2 deletions rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ buffer."
(- (current-column) rust-indent-offset)))))
(cond
;; foo.bar(...)
((rust-looking-back-str ")")
((looking-back "[)?]" (1- (point)))
(backward-list 1)
(funcall skip-dot-identifier))

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

0 comments on commit cc2435b

Please sign in to comment.