From 397a18076a95f2644618a7cb3fb3ba0c9dcecd6e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 18 Sep 2024 09:20:22 -0500 Subject: [PATCH 1/2] fix(complete): Fallback to rustc if rustup fails for --target completions If there is any problem with rustup, we should fallback to rustc. (this also removes some extra allocations) --- src/cargo/util/command_prelude.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 6bb219bcf23..c13105cc620 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -1123,11 +1123,13 @@ fn get_target_triples() -> Vec { if is_rustup() { if let Ok(targets) = get_target_triples_from_rustup() { - candidates.extend(targets); + candidates = targets; } - } else { + } + + if candidates.is_empty() { if let Ok(targets) = get_target_triples_from_rustc() { - candidates.extend(targets); + candidates = targets; } } From a5c25f3dd53b3f2ba952f7c185cf02c4d77f6ee4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 18 Sep 2024 09:28:05 -0500 Subject: [PATCH 2/2] fix(complete): Always check rustup for --target clap-rs/clap#5733 removed the rustup proxy so that `CARGO_COMPLETE=bash cargo +nightly` works (with a side benefit of removing the proxy overhead). As a downside, cargo no longer knows it is running within rustup, so we aren't reading `--target` candidates from rustup. This changes the code to always try rustup. It is likely a good enough source, even if the user isn't currently using it. The candidates should be about the same, just rustup hides some by default. Hiding just means it isn't shown by default but if only hidden candidates match, then we show them. --- src/cargo/util/command_prelude.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index c13105cc620..3069a379971 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -1121,10 +1121,8 @@ fn get_targets_from_metadata() -> CargoResult> { fn get_target_triples() -> Vec { let mut candidates = Vec::new(); - if is_rustup() { - if let Ok(targets) = get_target_triples_from_rustup() { - candidates = targets; - } + if let Ok(targets) = get_target_triples_from_rustup() { + candidates = targets; } if candidates.is_empty() {