fix(derive): Improve invalid variant errors

This commit is contained in:
Ed Page
2026-01-14 15:52:40 -06:00
parent bd005654a1
commit 03e3fd51e6
3 changed files with 9 additions and 9 deletions

View File

@@ -527,7 +527,7 @@ pub(crate) fn gen_constructor(fields: &[(&Field, Item)]) -> Result<TokenStream,
Ty::OptionVecVec => {
abort!(
ty.span(),
"{} types are not supported for flatten",
"`{}` is an invalid `#[command(flatten)]` type",
ty.as_str()
);
}

View File

@@ -210,7 +210,7 @@ fn gen_augment(
}
_ => abort!(
variant,
"`flatten` is usable only with single-typed tuple variants"
"invalid variant for `#[command(flatten)]`, expected a newtype variant"
),
},
@@ -218,7 +218,7 @@ fn gen_augment(
let subcommand_var = Ident::new("__clap_subcommand", Span::call_site());
let arg_block = match variant.fields {
Named(_) => {
abort!(variant, "non single-typed tuple enums are not supported")
abort!(variant, "invalid variant for `#[command(subcommand)]`, expected a newtype variant")
}
Unit => quote!( #subcommand_var ),
Unnamed(FieldsUnnamed { ref unnamed, .. }) if unnamed.len() == 1 => {
@@ -238,7 +238,7 @@ fn gen_augment(
}
}
Unnamed(..) => {
abort!(variant, "non single-typed tuple enums are not supported")
abort!(variant, "invalid variant for `#[command(subcommand)]`, expected a newtype variant")
}
};
@@ -315,7 +315,7 @@ fn gen_augment(
}
}
Unnamed(..) => {
abort!(variant, "non single-typed tuple enums are not supported")
abort!(variant, "invalid variant for `#[command(subcommand)]`, expected a newtype variant")
}
};
@@ -398,7 +398,7 @@ fn gen_has_subcommand(variants: &[(&Variant, Item)]) -> Result<TokenStream, syn:
}
_ => abort!(
variant,
"`flatten` is usable only with single-typed tuple variants"
"invalid variant for `#[command(flatten)]`, expected newtype variant"
),
})
.collect::<Result<Vec<_>, syn::Error>>()?;
@@ -520,7 +520,7 @@ fn gen_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStream, sy
}
_ => abort!(
variant,
"`flatten` is usable only with single-typed tuple variants"
"invalid variant for `#[command(flatten)]`, expected newtype variant"
),
}
}).collect::<Result<Vec<_>, syn::Error>>()?;
@@ -638,7 +638,7 @@ fn gen_update_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStr
}
_ => abort!(
variant,
"`flatten` is usable only with single-typed tuple variants"
"invalid variant for `#[command(flatten)]`, expected newtype variant"
),
}
}).collect::<Result<Vec<_>, _>>()?;

View File

@@ -1,4 +1,4 @@
error: `flatten` is usable only with single-typed tuple variants
error: invalid variant for `#[command(flatten)]`, expected newtype variant
--> tests/derive_ui/enum_flatten.rs:14:5
|
14 | / #[command(flatten)]