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(
216
216
. iter ( )
217
217
. enumerate ( )
218
218
. map ( |( i, variant) | {
219
+ check_variant_attrs ( variant) ?;
219
220
let idx = i as u64 ;
220
221
let variant_name = & variant. ident ;
221
222
construct ( & variant. fields , |_, field| gen_constructor_for_field ( field) )
@@ -401,3 +402,18 @@ fn gen_constructor_for_field(field: &Field) -> Result<TokenStream> {
401
402
} ;
402
403
Ok ( ctor)
403
404
}
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 {
1666
1666
/// x: T,
1667
1667
/// }
1668
1668
/// ```
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
+ /// ```
1669
1678
#[ cfg( all( doctest, feature = "derive" ) ) ]
1670
1679
pub struct CompileFailTests ;
You can’t perform that action at this time.
0 commit comments