runtime(rust): Update indentation after nested array literal

Commit: 
https://github.com/vim/vim/commit/5c2b594d0e86e4484cc92bd415aedbef5749bd9e
Author: Brian Carbone <[email protected]>
Date:   Wed Dec 31 09:24:31 2025 +0000

    runtime(rust): Update indentation after nested array literal
    
    fixes:  https://github.com/vim/vim/issues/18974
    closes: https://github.com/vim/vim/issues/19042
    
    Signed-off-by: Brian Carbone <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/indent/rust.vim b/runtime/indent/rust.vim
index 662c9e766..30206be43 100644
--- a/runtime/indent/rust.vim
+++ b/runtime/indent/rust.vim
@@ -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'
diff --git a/runtime/indent/testdir/rust.in b/runtime/indent/testdir/rust.in
index 848912bfb..28a68924f 100644
--- a/runtime/indent/testdir/rust.in
+++ b/runtime/indent/testdir/rust.in
@@ -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) {
diff --git a/runtime/indent/testdir/rust.ok b/runtime/indent/testdir/rust.ok
index ea2a071b0..04808e224 100644
--- a/runtime/indent/testdir/rust.ok
+++ b/runtime/indent/testdir/rust.ok
@@ -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) {

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1vasWq-006uDp-JP%40256bit.org.

Raspunde prin e-mail lui