14
14
//! [`Arbitrary`](./trait.Arbitrary.html) trait's documentation for details on
15
15
//! automatically deriving, implementing, and/or using the trait.
16
16
17
- #![ cfg_attr( feature = "const-generics" , feature( min_const_generics) ) ]
18
17
#![ deny( bad_style) ]
19
18
#![ deny( missing_docs) ]
20
19
#![ deny( future_incompatible) ]
@@ -714,13 +713,11 @@ macro_rules! arbitrary_tuple {
714
713
}
715
714
arbitrary_tuple ! ( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ) ;
716
715
717
- #[ cfg( feature = "const-generics" ) ]
718
716
struct ArrayGuard < T , const N : usize > {
719
717
dst : * mut T ,
720
718
initialized : usize ,
721
719
}
722
720
723
- #[ cfg( feature = "const-generics" ) ]
724
721
impl < T , const N : usize > Drop for ArrayGuard < T , N > {
725
722
fn drop ( & mut self ) {
726
723
debug_assert ! ( self . initialized <= N ) ;
@@ -731,7 +728,6 @@ impl<T, const N: usize> Drop for ArrayGuard<T, N> {
731
728
}
732
729
}
733
730
734
- #[ cfg( feature = "const-generics" ) ]
735
731
fn create_array < F , T , const N : usize > ( mut cb : F ) -> [ T ; N ]
736
732
where
737
733
F : FnMut ( usize ) -> T ,
@@ -751,7 +747,6 @@ where
751
747
}
752
748
}
753
749
754
- #[ cfg( feature = "const-generics" ) ]
755
750
fn try_create_array < F , T , const N : usize > ( mut cb : F ) -> Result < [ T ; N ] >
756
751
where
757
752
F : FnMut ( usize ) -> Result < T > ,
@@ -771,7 +766,6 @@ where
771
766
}
772
767
}
773
768
774
- #[ cfg( feature = "const-generics" ) ]
775
769
impl < T , const N : usize > Arbitrary for [ T ; N ]
776
770
where
777
771
T : Arbitrary ,
@@ -803,91 +797,6 @@ where
803
797
}
804
798
}
805
799
806
- #[ cfg( not( feature = "const-generics" ) ) ]
807
- macro_rules! arbitrary_array {
808
- { $n: expr, ( $t: ident, $a: ident) $( ( $ts: ident, $as: ident) ) * } => {
809
- arbitrary_array!{ ( $n - 1 ) , $( ( $ts, $as) ) * }
810
-
811
- impl <T : Arbitrary > Arbitrary for [ T ; $n] {
812
- fn arbitrary( u: & mut Unstructured <' _>) -> Result <[ T ; $n] > {
813
- Ok ( [
814
- Arbitrary :: arbitrary( u) ?,
815
- $( <$ts as Arbitrary >:: arbitrary( u) ?) ,*
816
- ] )
817
- }
818
-
819
- #[ allow( unused_mut) ]
820
- fn arbitrary_take_rest( mut u: Unstructured <' _>) -> Result <[ T ; $n] > {
821
- $( let $as = $ts:: arbitrary( & mut u) ?; ) *
822
- let last = Arbitrary :: arbitrary_take_rest( u) ?;
823
-
824
- Ok ( [
825
- $( $as, ) * last
826
- ] )
827
- }
828
-
829
- #[ inline]
830
- fn size_hint( depth: usize ) -> ( usize , Option <usize >) {
831
- crate :: size_hint:: and_all( & [
832
- <$t as Arbitrary >:: size_hint( depth) ,
833
- $( <$ts as Arbitrary >:: size_hint( depth) ) ,*
834
- ] )
835
- }
836
-
837
- #[ allow( unused_mut) ] // For the `[T; 1]` case.
838
- fn shrink( & self ) -> Box <dyn Iterator <Item = Self >> {
839
- let mut i = 0 ;
840
- let mut shrinkers = [
841
- self [ i] . shrink( ) ,
842
- $( {
843
- i += 1 ;
844
- let t: & $ts = & self [ i] ;
845
- t. shrink( )
846
- } ) ,*
847
- ] ;
848
- Box :: new( iter:: from_fn( move || {
849
- let mut i = 0 ;
850
- Some ( [
851
- shrinkers[ i] . next( ) ?,
852
- $( {
853
- i += 1 ;
854
- let t: $ts = shrinkers[ i] . next( ) ?;
855
- t
856
- } ) ,*
857
- ] )
858
- } ) )
859
- }
860
- }
861
- } ;
862
- ( $n: expr, ) => { } ;
863
- }
864
-
865
- #[ cfg( not( feature = "const-generics" ) ) ]
866
- impl < T : Arbitrary > Arbitrary for [ T ; 0 ] {
867
- fn arbitrary ( _: & mut Unstructured < ' _ > ) -> Result < [ T ; 0 ] > {
868
- Ok ( [ ] )
869
- }
870
-
871
- fn arbitrary_take_rest ( _: Unstructured < ' _ > ) -> Result < [ T ; 0 ] > {
872
- Ok ( [ ] )
873
- }
874
-
875
- #[ inline]
876
- fn size_hint ( _: usize ) -> ( usize , Option < usize > ) {
877
- crate :: size_hint:: and_all ( & [ ] )
878
- }
879
-
880
- fn shrink ( & self ) -> Box < dyn Iterator < Item = Self > > {
881
- Box :: new ( iter:: from_fn ( || None ) )
882
- }
883
- }
884
- #[ cfg( not( feature = "const-generics" ) ) ]
885
- arbitrary_array ! { 32 , ( T , a) ( T , b) ( T , c) ( T , d) ( T , e) ( T , f) ( T , g) ( T , h)
886
- ( T , i) ( T , j) ( T , k) ( T , l) ( T , m) ( T , n) ( T , o) ( T , p)
887
- ( T , q) ( T , r) ( T , s) ( T , u) ( T , v) ( T , w) ( T , x) ( T , y)
888
- ( T , z) ( T , aa) ( T , ab) ( T , ac) ( T , ad) ( T , ae) ( T , af)
889
- ( T , ag) }
890
-
891
800
fn shrink_collection < ' a , T , A : Arbitrary > (
892
801
entries : impl Iterator < Item = T > ,
893
802
f : impl Fn ( & T ) -> Box < dyn Iterator < Item = A > > ,
0 commit comments