Rust feature gates syntax cause the file to run as shell script
oblitum opened this issue · comments
For example, for this code:
#![feature(slice_patterns)]
#![feature(advanced_slice_patterns)]
fn foldl<A, B>(f: fn(A, &B) -> A, acc: A, xs: &[B]) -> A {
match *xs {
[] => acc,
[ref x, ref xs..] => foldl(f, f(acc, x), xs),
}
}
fn foldr<A, B>(f: fn(&A, B) -> B, acc: B, xs: &[A]) -> B {
match *xs {
[] => acc,
[ref xs.., ref x] => foldr(f, f(x, acc), xs),
}
}
fn main() {
println!("{}",
foldl(|a, b| a + b, String::with_capacity(10), &["1", "2", "3"]));
println!("{}", foldr(|a, b| a + b, 0, &[1, 2, 3]));
}
:QuickRun
gives:
zsh:1: no matches found: [feature(slice_patterns)]
Even though the file type is set to be Rust. It's necessary to add an empty line at the top of the file for it to run through the Rust compiler.
I've applied this minor fix:
diff --git a/autoload/quickrun/hook/shebang.vim b/autoload/quickrun/hook/shebang.vim
index 7acdc58..d360e02 100644
--- a/autoload/quickrun/hook/shebang.vim
+++ b/autoload/quickrun/hook/shebang.vim
@@ -9,7 +9,7 @@ let s:hook = {}
function! s:hook.on_module_loaded(session, context) abort
let line = get(readfile(a:session.config.srcfile, 0, 1), 0, '')
- if line =~# '^#!'
+ if line =~# '^#!/'
let a:session.config.command = line[2 :]
call map(a:session.config.exec, 's:replace_cmd(v:val)')
endif
I think it's OK since shebang syntax requires an absolute interpreter path.
The shebang line is read by many systems, e.g. Apache HTTP Server in Windows.
Absolute path may not start with /
.
You can disable shebang feature for Rust.
let g:quickrun_config = {
\ 'rust': {
\ 'hook/shebang/enable': 0,
\ }
\ }
Should we disable this for Rust by default?
@thinca ah, thanks, that was the first setting I was trying to find but the documentation is really hard to dig, I couldn't figure the enable
flag.
Yes, I do agree it should be disabled by default for Rust.
I updated the default config by 13e6058 .
Please reopen if there is still any problem.
All fine. Thanks!