From 7ade8c39303de9d8ecaf089c036a51753609fc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Tue, 9 Feb 2016 23:05:56 +0100 Subject: [PATCH 1/2] Use 'cargo rustc -Zno-trans' for syntastic checker --- syntax_checkers/rust/rustc.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/syntax_checkers/rust/rustc.vim b/syntax_checkers/rust/rustc.vim index 5d196086..f742c59b 100644 --- a/syntax_checkers/rust/rustc.vim +++ b/syntax_checkers/rust/rustc.vim @@ -14,7 +14,9 @@ let s:save_cpo = &cpo set cpo&vim function! SyntaxCheckers_rust_rustc_GetLocList() dict - let makeprg = self.makeprgBuild({ 'args': '-Zparse-only' }) + let makeprg = self.makeprgBuild({ + \ 'args': 'rustc -Zno-trans', + \ 'fname': '' }) let errorformat = \ '%E%f:%l:%c: %\d%#:%\d%# %.%\{-}error:%.%\{-} %m,' . @@ -28,6 +30,7 @@ function! SyntaxCheckers_rust_rustc_GetLocList() dict endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ + \ 'exec': 'cargo', \ 'filetype': 'rust', \ 'name': 'rustc'}) From f20b8b49c74e64b955884d49b4adca18cea29d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Tue, 9 Feb 2016 23:54:51 +0100 Subject: [PATCH 2/2] Detect standalone rs vs a crate --- syntax_checkers/rust/rustc.vim | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/syntax_checkers/rust/rustc.vim b/syntax_checkers/rust/rustc.vim index f742c59b..2a45cea2 100644 --- a/syntax_checkers/rust/rustc.vim +++ b/syntax_checkers/rust/rustc.vim @@ -14,9 +14,20 @@ let s:save_cpo = &cpo set cpo&vim function! SyntaxCheckers_rust_rustc_GetLocList() dict - let makeprg = self.makeprgBuild({ - \ 'args': 'rustc -Zno-trans', - \ 'fname': '' }) + let cwd = '.' " Don't change cwd as default + let cargo_toml_path = findfile('Cargo.toml', '.;') + if empty(cargo_toml_path) " Plain rs file, not a crate + let makeprg = self.makeprgBuild({ + \ 'exe': 'rustc', + \ 'args': '-Zno-trans' }) + else " We are inside a crate + let makeprg = self.makeprgBuild({ + \ 'exe': 'cargo', + \ 'args': 'rustc -Zno-trans', + \ 'fname': '' }) + " Change cwd to the root of the crate + let cwd = fnamemodify( cargo_toml_path, ':p:h') + endif let errorformat = \ '%E%f:%l:%c: %\d%#:%\d%# %.%\{-}error:%.%\{-} %m,' . @@ -26,13 +37,13 @@ function! SyntaxCheckers_rust_rustc_GetLocList() dict return SyntasticMake({ \ 'makeprg': makeprg, - \ 'errorformat': errorformat }) + \ 'errorformat': errorformat, + \ 'cwd': cwd }) endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ - \ 'exec': 'cargo', \ 'filetype': 'rust', - \ 'name': 'rustc'}) + \ 'name': 'rustc' }) let &cpo = s:save_cpo unlet s:save_cpo