]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(rust): Update indentation after nested array literal
authorBrian Carbone <brian@briancarbone.com>
Wed, 31 Dec 2025 09:24:31 +0000 (09:24 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 31 Dec 2025 09:26:20 +0000 (09:26 +0000)
fixes:  #18974
closes: #19042

Signed-off-by: Brian Carbone <brian@briancarbone.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/indent/rust.vim
runtime/indent/testdir/rust.in
runtime/indent/testdir/rust.ok

index 662c9e7666cf4e20f39e4ab182855ebb08b2026d..30206be435d4b404ba01f787b8f91b2bf5429f63 100644 (file)
@@ -4,6 +4,7 @@
 " Last Change:      2023-09-11
 " 2024 Jul 04 by Vim Project: use shiftwidth() instead of hard-coding shifted values #15138
 " 2025 Dec 29 by Vim Project: clean up
+" 2025 Dec 31 by Vim Project: correcly indent after nested array literal #19042
 
 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim
 " Note: upstream seems umaintained: https://github.com/rust-lang/rust.vim/issues/502
@@ -195,6 +196,22 @@ function GetRustIndent(lnum)
         endif
     endif
 
+    " Prevent cindent from becoming confused when pairing square brackets, as
+    " in
+    "
+    " let arr = [[u8; 4]; 2] = [
+    "     [0; 4],
+    "     [1, 3, 5, 9],
+    " ];
+    "     | ← indentation placed here
+    "
+    " for which it calculates too much indentation in the line following the
+    " close of the array.
+    if prevline =~# '^\s*\]' && l:last_prevline_character ==# ';'
+                \ && line !~# '^\s*}'
+        return indent(prevlinenum)
+    endif
+
     if l:last_prevline_character ==# ","
                 \ && s:get_line_trimmed(a:lnum) !~# '^\s*[\[\]{})]'
                 \ && prevline !~# '^\s*fn\s'
index 848912bfba254aa574f40929a7e050870dfd9828..28a68924f69b030e441a7e837bc85fd1399d5091 100644 (file)
@@ -15,6 +15,21 @@ fn main() {
        Ok(file) => file,
     };
 
+    // Start doing nothing forever
+    loop {
+        let arr1 = [[u8; 4]; 2] = [
+            [0; 4],
+            [1, 3, 5, 9],
+        ];
+        }
+
+    // Plan for a future that will never come
+    let arr2 = [[u8; 4]; 2] = [
+        [1; 4],
+        [2, 4, 6, 8],
+    ];
+        let arr2_ref = &arr2;
+
     // Read the file contents into a string, returns `io::Result<usize>`
     let mut s = String::new();
         match file.read_to_string(&mut s) {
index ea2a071b010c457d3f98d306554512af3759d6ed..04808e224f4d06826fec3742c069c8d0b8b9f641 100644 (file)
@@ -15,6 +15,21 @@ fn main() {
         Ok(file) => file,
     };
 
+    // Start doing nothing forever
+    loop {
+        let arr1 = [[u8; 4]; 2] = [
+            [0; 4],
+            [1, 3, 5, 9],
+        ];
+    }
+
+    // Plan for a future that will never come
+    let arr2 = [[u8; 4]; 2] = [
+        [1; 4],
+        [2, 4, 6, 8],
+    ];
+    let arr2_ref = &arr2;
+
     // Read the file contents into a string, returns `io::Result<usize>`
     let mut s = String::new();
     match file.read_to_string(&mut s) {