@@ -60,18 +60,19 @@ function! s:RustfmtWriteMode()
6060 endif
6161endfunction
6262
63- function ! s: RustfmtConfig ()
63+ function ! s: RustfmtConfigOptions ()
6464 let l: rustfmt_toml = findfile (' rustfmt.toml' , expand (' %:p:h' ) . ' ;' )
6565 if l: rustfmt_toml !=# ' '
66- return ' --config-path ' .l: rustfmt_toml
66+ return ' --config-path ' .fnamemodify ( l: rustfmt_toml, " :p " )
6767 endif
6868
6969 let l: _rustfmt_toml = findfile (' .rustfmt.toml' , expand (' %:p:h' ) . ' ;' )
7070 if l: _rustfmt_toml !=# ' '
71- return ' --config-path ' .l: _rustfmt_toml
71+ return ' --config-path ' .fnamemodify ( l: _rustfmt_toml, " :p " )
7272 endif
7373
74- return ' '
74+ " Default to edition 2018 in case no rustfmt.toml was found.
75+ return ' --edition 2018'
7576endfunction
7677
7778function ! s: RustfmtCommandRange (filename, line1, line2)
@@ -82,7 +83,7 @@ function! s:RustfmtCommandRange(filename, line1, line2)
8283
8384 let l: arg = {" file" : shellescape (a: filename ), " range" : [a: line1 , a: line2 ]}
8485 let l: write_mode = s: RustfmtWriteMode ()
85- let l: rustfmt_config = s: RustfmtConfig ()
86+ let l: rustfmt_config = s: RustfmtConfigOptions ()
8687
8788 " FIXME: When --file-lines gets to be stable, add version range checking
8889 " accordingly.
@@ -96,14 +97,9 @@ function! s:RustfmtCommandRange(filename, line1, line2)
9697endfunction
9798
9899function ! s: RustfmtCommand ()
99- if g: rustfmt_emit_files
100- let l: write_mode = " --emit=stdout"
101- else
102- let l: write_mode = " --write-mode=display"
103- endif
104- " rustfmt will pick on the right config on its own due to the
105- " current directory change.
106- return g: rustfmt_command . " " . l: write_mode . " " . g: rustfmt_options
100+ let write_mode = g: rustfmt_emit_files ? ' --emit=stdout' : ' --write-mode=display'
101+ let config = s: RustfmtConfigOptions ()
102+ return join ([g: rustfmt_command , write_mode, config, g: rustfmt_options ])
107103endfunction
108104
109105function ! s: DeleteLines (start , end ) abort
0 commit comments