From e1c90cac8872f68867e175ec4b4f5379dbfa27b1 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Wed, 18 Oct 2017 11:47:21 -0500 Subject: [PATCH] Prevent error output on invocation of rustc completions fish was indiscriminately calling `rustc -Z help` in the autocompletion script for `rustc`, but `-Z` (and its `-Z help` output completions) is only available when using the nightly compiler. Note that this isn't a perfect fix since if you try to use those command line options now added to the autocompletions list without using the nightly toolchain, `rustc` will still throw an error. But at least this way we don't cause random errors about `-Z` not being available to appear any time someone tries to use `rustc` from the fish command prompt. --- share/completions/rustc.fish | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/share/completions/rustc.fish b/share/completions/rustc.fish index 090be9db8..27cb6498e 100644 --- a/share/completions/rustc.fish +++ b/share/completions/rustc.fish @@ -36,16 +36,19 @@ for line in $rust_docs complete -c rustc -x -s C -l codegen -a "$flag" -d "$docs[2]" end -set -l rust_docs (rustc -Z help \ - | string replace -r -i '(\s+)-Z(.+)--(\s+)([^\n]+)' '$2 $4' \ - | string trim \ - | string match -r '^.*[^:]$') +# rustc -Z is only available with the nightly toolchain, which may not be installed +if rustc +nightly >/dev/null 2>&1 + set -l rust_docs (rustc +nightly -Z help \ + | string replace -r -i '(\s+)-Z(.+)--(\s+)([^\n]+)' '$2 $4' \ + | string trim \ + | string match -r '^.*[^:]$') -for line in $rust_docs - set docs (string split -m 1 ' ' $line) - set flag (string replace -r '^([a-z\-]+\=|[a-z\-]+)(.*)' '$1' \ - $docs[1]) - complete -c rustc -x -s Z -a "$flag" -d "$docs[2]" + for line in $rust_docs + set docs (string split -m 1 ' ' $line) + set flag (string replace -r '^([a-z\-]+\=|[a-z\-]+)(.*)' '$1' \ + $docs[1]) + complete -c rustc -x -s Z -a "$flag" -d "$docs[2]" + end end set -l rust_docs (rustc -W help \