Skip to content

Commit

Permalink
fix(derive): Make mismatched behavior more obvious
Browse files Browse the repository at this point in the history
If the inner type never implemented `group_id()`, then it won't work and
people will be confused.  This at least gives people an idea of whats
going wrong.

This is most likely to be a problem until clap-rs#3165 is fully implemented but
hand-implementations can still run into this.  Probably should have made
the groups another trait to catch this in type system but too late.
  • Loading branch information
epage committed Oct 5, 2022
1 parent 06d2049 commit 78676f5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clap_derive/src/derives/args.rs
Expand Up @@ -447,7 +447,9 @@ pub fn gen_constructor(fields: &[(&Field, Item)]) -> TokenStream {
Ty::Option => {
quote_spanned! { kind.span()=>
#field_name: {
if <#inner_type as clap::Args>::group_id().map(|group_id| #arg_matches.contains_id(group_id.as_str())).unwrap_or(false) {
let group_id = <#inner_type as clap::Args>::group_id()
.expect("`#[arg(flatten)]`ed field type implements `Args::group_id`");
if #arg_matches.contains_id(group_id.as_str()) {
Some(
<#inner_type as clap::FromArgMatches>::from_arg_matches_mut(#arg_matches)?
)
Expand Down

0 comments on commit 78676f5

Please sign in to comment.