File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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'
Original file line number Diff line number Diff 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) {
Original file line number Diff line number Diff 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) {
You can’t perform that action at this time.
0 commit comments