Skip to content

fix(builder): Take &self in ArgGroup::is_multiple - #6411

Open
mistaste wants to merge 1 commit into
clap-rs:masterfrom
mistaste:fix-arggroup-is-multiple-shared-ref
Open

fix(builder): Take &self in ArgGroup::is_multiple#6411
mistaste wants to merge 1 commit into
clap-rs:masterfrom
mistaste:fix-arggroup-is-multiple-shared-ref

Conversation

@mistaste

Copy link
Copy Markdown

Fixes #4708.

ArgGroup::is_multiple is a getter that just returns self.multiple, but it
required &mut self. That made it impossible to call on a shared reference,
such as one obtained from Command::groups.

This relaxes the receiver to &self, which is backwards compatible (existing
callers holding a &mut ArgGroup can still call it). The doc example and unit
test are updated accordingly, and the test now also exercises calling the getter
through a &ArgGroup.

cargo test -p clap_builder, --doc, cargo clippy --all-features and
cargo fmt --check all pass.

`ArgGroup::is_multiple` is a getter that doesn't mutate, but required
`&mut self`. That prevented calling it on a shared reference, such as one
obtained from `Command::groups`. Relax the receiver to `&self`.

Fixes clap-rs#4708
@epage

epage commented Jun 16, 2026

Copy link
Copy Markdown
Member

Note that a previous PR existed for #4708 and was deferred due to it being a breaking change.

We might be able to put this behind unstable-v5. Otherwise, we might as well close this until we are ready for breaking changes.

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.

is_multiple shouldn't require &mut self

2 participants