Skip to content

Commit 5c2b594

Browse files
briancarbonechrisbra
authored andcommitted
runtime(rust): Update indentation after nested array literal
fixes: #18974 closes: #19042 Signed-off-by: Brian Carbone <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent d09be15 commit 5c2b594

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

runtime/indent/rust.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
" Last Change: 2023-09-11
55
" 2024 Jul 04 by Vim Project: use shiftwidth() instead of hard-coding shifted values #15138
66
" 2025 Dec 29 by Vim Project: clean up
7+
" 2025 Dec 31 by Vim Project: correcly indent after nested array literal #19042
78

89
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
910
" Note: upstream seems umaintained: https://github.com/rust-lang/rust.vim/issues/502
@@ -195,6 +196,22 @@ function GetRustIndent(lnum)
195196
endif
196197
endif
197198

199+
" Prevent cindent from becoming confused when pairing square brackets, as
200+
" in
201+
"
202+
" let arr = [[u8; 4]; 2] = [
203+
" [0; 4],
204+
" [1, 3, 5, 9],
205+
" ];
206+
" | ← indentation placed here
207+
"
208+
" for which it calculates too much indentation in the line following the
209+
" close of the array.
210+
if prevline =~# '^\s*\]' && l:last_prevline_character ==# ';'
211+
\ && line !~# '^\s*}'
212+
return indent(prevlinenum)
213+
endif
214+
198215
if l:last_prevline_character ==# ","
199216
\ && s:get_line_trimmed(a:lnum) !~# '^\s*[\[\]{})]'
200217
\ && prevline !~# '^\s*fn\s'

runtime/indent/testdir/rust.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ fn main() {
1515
Ok(file) => file,
1616
};
1717

18+
// Start doing nothing forever
19+
loop {
20+
let arr1 = [[u8; 4]; 2] = [
21+
[0; 4],
22+
[1, 3, 5, 9],
23+
];
24+
}
25+
26+
// Plan for a future that will never come
27+
let arr2 = [[u8; 4]; 2] = [
28+
[1; 4],
29+
[2, 4, 6, 8],
30+
];
31+
let arr2_ref = &arr2;
32+
1833
// Read the file contents into a string, returns `io::Result<usize>`
1934
let mut s = String::new();
2035
match file.read_to_string(&mut s) {

runtime/indent/testdir/rust.ok

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ fn main() {
1515
Ok(file) => file,
1616
};
1717

18+
// Start doing nothing forever
19+
loop {
20+
let arr1 = [[u8; 4]; 2] = [
21+
[0; 4],
22+
[1, 3, 5, 9],
23+
];
24+
}
25+
26+
// Plan for a future that will never come
27+
let arr2 = [[u8; 4]; 2] = [
28+
[1; 4],
29+
[2, 4, 6, 8],
30+
];
31+
let arr2_ref = &arr2;
32+
1833
// Read the file contents into a string, returns `io::Result<usize>`
1934
let mut s = String::new();
2035
match file.read_to_string(&mut s) {

0 commit comments

Comments
 (0)