File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,7 @@ fn gen_arbitrary_method(
216216 . iter ( )
217217 . enumerate ( )
218218 . map ( |( i, variant) | {
219+ check_variant_attrs ( variant) ?;
219220 let idx = i as u64 ;
220221 let variant_name = & variant. ident ;
221222 construct ( & variant. fields , |_, field| gen_constructor_for_field ( field) )
@@ -401,3 +402,18 @@ fn gen_constructor_for_field(field: &Field) -> Result<TokenStream> {
401402 } ;
402403 Ok ( ctor)
403404}
405+
406+ fn check_variant_attrs ( variant : & Variant ) -> Result < ( ) > {
407+ for attr in & variant. attrs {
408+ if attr. path ( ) . is_ident ( ARBITRARY_ATTRIBUTE_NAME ) {
409+ return Err ( Error :: new_spanned (
410+ attr,
411+ format ! (
412+ "invalid `{}` attribute. it is unsupported on enum variants. try applying it to a field of the variant instead" ,
413+ ARBITRARY_ATTRIBUTE_NAME
414+ ) ,
415+ ) ) ;
416+ }
417+ }
418+ Ok ( ( ) )
419+ }
Original file line number Diff line number Diff line change @@ -1666,5 +1666,14 @@ mod test {
16661666/// x: T,
16671667/// }
16681668/// ```
1669+ ///
1670+ /// Attempt to use the derive attribute on an enum variant:
1671+ /// ```compile_fail
1672+ /// #[derive(::arbitrary::Arbitrary)]
1673+ /// enum Enum<T: Default> {
1674+ /// #[arbitrary(default)]
1675+ /// Variant(T),
1676+ /// }
1677+ /// ```
16691678#[ cfg( all( doctest, feature = "derive" ) ) ]
16701679pub struct CompileFailTests ;
You can’t perform that action at this time.
0 commit comments