Skip to content

Commit b9f5a79

Browse files
committed
Fix infinite recursion in bash completions when rustc is not in PATH
Previously, running `source /etc/bash_completion.d/cargo` would loop forever: ``` Command 'rustc' not found, but can be installed with: sudo snap install rustup # version 1.24.3, or sudo apt install rustc # version 1.47.0+dfsg1+llvm-1ubuntu1~20.04.1 See 'snap info rustup' for additional versions. Command 'rustc' not found, but can be installed with: sudo snap install rustup # version 1.24.3, or sudo apt install rustc # version 1.47.0+dfsg1+llvm-1ubuntu1~20.04.1 See 'snap info rustup' for additional versions. Command 'rustc' not found, but can be installed with: ``` The issue was that `$(rustc --print sysroot)/etc/bash_completion.d/cargo` will expand to `/etc/bash_completion.d/cargo` is rustc doesn't print anything, which sources the same file over and over. This fixes it by first checking that rustc exists. This also adds quotes around the sysroot, to support spaces with filenames.
1 parent 457d643 commit b9f5a79

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/cli/rustup_mode.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,9 @@ fn output_completion_script(shell: Shell, command: CompletionCommand) -> Result<
16861686

16871687
writeln!(
16881688
&mut term2::stdout(),
1689-
"source $(rustc --print sysroot){}",
1689+
"if command -v rustc >/dev/null 2>&1; then\n\
1690+
\tsource \"$(rustc --print sysroot)\"{}\n\
1691+
fi",
16901692
script,
16911693
)?;
16921694
}

0 commit comments

Comments
 (0)