]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(rust): Do not use rustfmt as 'formatprg' by default
authorAaron Jacobs <jacobsa@google.com>
Mon, 27 Oct 2025 17:46:11 +0000 (17:46 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 27 Oct 2025 17:46:11 +0000 (17:46 +0000)
This reverts commit 4ac995bf9366c6624a0724d19b2226f4c95694b3.

This was added in #16807, with no explanation for why it was necessary beyond
"it's an example of an idea". It completely breaks `gq` for me—rustfmt doesn't
reflow comments so is not an appropriate tool here! Beyond that, formatting a
selection with rustfmt treats that selection as if it were an entire file,
throwing away any indentation.

For example, the commit causes `gq` to turn this:

```rust
pub fn foo() {
    // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
}
```

into this:

```rust
pub fn foo() {
// blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
}

```

which is totally wrong. In contrast, if I clear `formatprg` then `gq` does the
right thing again:

```rust
pub fn foo() {
    // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    // blah blah blah blah blah blah
}
```

related: #16967
related: #17055
closes: #18640

Signed-off-by: Aaron Jacobs <jacobsa@google.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/rustfmt.vim
runtime/doc/ft_rust.txt
runtime/ftplugin/rust.vim

index 847b698b79b54ed409ea55eb60e30de83bf41ac6..268a1c02ccf6d85aeb075b17e500db28fed4220d 100644 (file)
@@ -1,8 +1,8 @@
 " Author: Stephen Sugden <stephen@stephensugden.com>
 " Last Modified: 2023-09-11
 " Last Change:
-" 2025 Mar 31 by Vim project (rename s:RustfmtConfigOptions())
-" 2025 Jul 14 by Vim project (don't parse rustfmt version automatically #17745)
+" 2025 Oct 27 by Vim project don't use rustfmt as 'formatprg' by default
+"
 "
 " Adapted from https://github.com/fatih/vim-go
 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim
@@ -68,13 +68,7 @@ function! s:RustfmtWriteMode()
     endif
 endfunction
 
-function! rustfmt#RustfmtConfigOptions()
-    let default = '--edition 2018'
-
-    if !get(g:, 'rustfmt_find_toml', 0)
-        return default
-    endif
-
+function! s:RustfmtConfigOptions()
     let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';')
     if l:rustfmt_toml !=# ''
         return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p"))
@@ -97,7 +91,7 @@ function! s:RustfmtCommandRange(filename, line1, line2)
 
     let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]}
     let l:write_mode = s:RustfmtWriteMode()
-    let l:rustfmt_config = rustfmt#RustfmtConfigOptions()
+    let l:rustfmt_config = s:RustfmtConfigOptions()
 
     " FIXME: When --file-lines gets to be stable, add version range checking
     " accordingly.
@@ -112,7 +106,7 @@ endfunction
 
 function! s:RustfmtCommand()
     let write_mode = g:rustfmt_emit_files ? '--emit=stdout' : '--write-mode=display'
-    let config = rustfmt#RustfmtConfigOptions()
+    let config = s:RustfmtConfigOptions()
     return join([g:rustfmt_command, write_mode, config, g:rustfmt_options])
 endfunction
 
index 30b23ced116f8887dd0c3f6a8735b9362ae987b9..4f4e3a85e721ad482b4ea32cb10069465071f9e6 100644 (file)
@@ -166,13 +166,6 @@ g:rustfmt_detect_version~
        Disabled by default for performance reasons
 >
            let g:rustfmt_detect_version = 1
-<
-                                                       *g:rustfmt_find_toml*
-g:rustfmt_emit_files~
-       When set to 1, will try to find "rustfmt.toml" file by searching from
-       current path upwards.  Disabled by default for performance reasons
->
-           let g:rustfmt_find_toml = 1
 <
                                                           *g:rust_playpen_url*
 g:rust_playpen_url~
index 53f7f8336309bfc27f9742cbc11b6bfb190af440..3e2741f919cc5e01bce7d85e9ffe0c79d9a572c4 100644 (file)
@@ -3,7 +3,6 @@
 " Maintainer:  Chris Morgan <me@chrismorgan.info>
 " Last Change: 2024 Mar 17
 "              2024 May 23 by Riley Bruins <ribru17@gmail.com ('commentstring')
-"              2025 Mar 31 by Vim project (set 'formatprg' option)
 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim
 
 if exists("b:did_ftplugin")
@@ -58,19 +57,6 @@ setlocal includeexpr=rust#IncludeExpr(v:fname)
 
 setlocal suffixesadd=.rs
 
-if executable(get(g:, 'rustfmt_command', 'rustfmt'))
-    if get(g:, "rustfmt_fail_silently", 0)
-        augroup rust.vim.FailSilently
-            autocmd! * <buffer>
-            autocmd ShellFilterPost <buffer> if v:shell_error | execute 'echom "shell filter returned error " . v:shell_error . ", undoing changes"' | undo | endif
-        augroup END
-    endif
-
-    let &l:formatprg = get(g:, 'rustfmt_command', 'rustfmt') . ' ' .
-                \ get(g:, 'rustfmt_options', '') . ' ' .
-                \ rustfmt#RustfmtConfigOptions()
-endif
-
 if exists("g:ftplugin_rust_source_path")
     let &l:path=g:ftplugin_rust_source_path . ',' . &l:path
 endif
@@ -163,7 +149,7 @@ endif
 
 let b:undo_ftplugin = "
             \ compiler make |
-            \ setlocal formatoptions< comments< commentstring< include< includeexpr< suffixesadd< formatprg<
+            \ setlocal formatoptions< comments< commentstring< include< includeexpr< suffixesadd<
             \|if exists('b:rust_set_style')
                 \|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<
                 \|endif