Skip to content

Use clap dynamic parsing to fix toolchain completion - #5033

Open
Cloud0310 wants to merge 1 commit into
rust-lang:mainfrom
Cloud0310:clap-completion
Open

Use clap dynamic parsing to fix toolchain completion #5033
Cloud0310 wants to merge 1 commit into
rust-lang:mainfrom
Cloud0310:clap-completion

Conversation

@Cloud0310

@Cloud0310 Cloud0310 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Closes #2268.

Verified manually (see #5033 (comment)).

Comment thread src/bin/rustup-init.rs Outdated
Comment thread src/cli/rustup_mode.rs Outdated
Comment thread src/cli/rustup_mode.rs Outdated
}
}

pub fn completion_command(process: Process) -> clap::Command {

@rami3l rami3l Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What is the expected ownership model here? I have the feeling that repeatedly cloning Process is definitely not the best solution here. Also, move this below the new caller in https://github.com/rust-lang/rustup/pull/5033/changes#r3844899779.

View changes since the review

Comment thread tests/suite/cli_misc.rs
Comment thread src/cli/rustup_mode.rs Outdated
let Some(toolchains) = process
.current_dir()
.ok()
.and_then(|current_dir| Cfg::from_env(current_dir, true, false, &process).ok())

@rami3l rami3l Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this callback should rely on an existing Cfg and use its .process, instead of creating a new Cfg from an existing process.

View changes since the review

Comment thread src/cli/rustup_mode.rs Outdated
Comment on lines +1970 to +1975
for expected in ["list", "add", "remove"] {
assert!(candidates.iter().any(|candidate| candidate == expected));
}
for root_only in ["install", "toolchain", "show"] {
assert!(!candidates.iter().any(|candidate| candidate == root_only));
}

@rami3l rami3l Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use HashSet<> operations with appropriate error messages for better readability.

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate auto completions; clap unaware of the +toolchain syntax

2 participants