Skip to content

Commit 7295c74

Browse files
committed
2 parents e651851 + f20b8b4 commit 7295c74

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

syntax_checkers/rust/rustc.vim

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@ let s:save_cpo = &cpo
1414
set cpo&vim
1515

1616
function! SyntaxCheckers_rust_rustc_GetLocList() dict
17-
let makeprg = self.makeprgBuild({ 'args': '-Zparse-only' })
17+
let cwd = '.' " Don't change cwd as default
18+
let cargo_toml_path = findfile('Cargo.toml', '.;')
19+
if empty(cargo_toml_path) " Plain rs file, not a crate
20+
let makeprg = self.makeprgBuild({
21+
\ 'exe': 'rustc',
22+
\ 'args': '-Zno-trans' })
23+
else " We are inside a crate
24+
let makeprg = self.makeprgBuild({
25+
\ 'exe': 'cargo',
26+
\ 'args': 'rustc -Zno-trans',
27+
\ 'fname': '' })
28+
" Change cwd to the root of the crate
29+
let cwd = fnamemodify( cargo_toml_path, ':p:h')
30+
endif
1831

1932
let errorformat =
2033
\ '%E%f:%l:%c: %\d%#:%\d%# %.%\{-}error:%.%\{-} %m,' .
@@ -24,12 +37,13 @@ function! SyntaxCheckers_rust_rustc_GetLocList() dict
2437

2538
return SyntasticMake({
2639
\ 'makeprg': makeprg,
27-
\ 'errorformat': errorformat })
40+
\ 'errorformat': errorformat,
41+
\ 'cwd': cwd })
2842
endfunction
2943

3044
call g:SyntasticRegistry.CreateAndRegisterChecker({
3145
\ 'filetype': 'rust',
32-
\ 'name': 'rustc'})
46+
\ 'name': 'rustc' })
3347

3448
let &cpo = s:save_cpo
3549
unlet s:save_cpo

0 commit comments

Comments
 (0)