From 5469d9bc3a13c75a8e98a86b6005d3540eb92524 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 18 Mar 2017 21:55:18 +0100 Subject: fix rust indentation bug This patch fixes a bug I found where rust-mode would misindent code like: fn each_split_within<'a, F>(ss: &'a str, lim: usize, mut it: F) -> bool where F: FnMut(&'a str) -> bool { } fn test_split_within() { } In particular the second "fn" would be indented a level. On the "fn" line, rust-mode-indent-line was calling rust-beginning-of-defun, which would go to the previous defun. Fixing this required moving the definition of rust-top-item-beg-re higher in the file, before its first use (recent versions of Emacs insist on this). And, this required removing the "^" from this regexp, which is ok because the sole use is already adding a "^". Additionally, I moved the "\\_>" into the regexp, rather than have it added at the point of use, so that the new use would also benefit. This patch includes two new test cases. --- rust-mode-tests.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'rust-mode-tests.el') diff --git a/rust-mode-tests.el b/rust-mode-tests.el index 98230de..5abd4a7 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -1628,6 +1628,34 @@ fn main() { " ))) +(ert-deftest indent-function-after-where () + (let ((rust-indent-method-chain t)) (test-indent + " +fn each_split_within<'a, F>(ss: &'a str, lim: usize, mut it: F) + -> bool where F: FnMut(&'a str) -> bool { +} + +#[test] +fn test_split_within() { +} +" + ))) + +(ert-deftest indent-function-after-where-nested () + (let ((rust-indent-method-chain t)) (test-indent + " +fn outer() { + fn each_split_within<'a, F>(ss: &'a str, lim: usize, mut it: F) + -> bool where F: FnMut(&'a str) -> bool { + } + #[test] + fn test_split_within() { + } + fn bar() { + } +} +" + ))) (ert-deftest test-for-issue-36-syntax-corrupted-state () "This is a test for a issue #36, which involved emacs's -- cgit v1.2.3