fix(derive): Make mismatched behavior more obvious

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 #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.
This commit is contained in:
Ed Page 2022-10-05 16:25:11 -05:00
parent 06d2049931
commit 78676f5043

View file

@ -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)?
)