@@ -847,58 +847,6 @@ fn test_field_validations_take_priority_over_nested_validations() {
847
847
}
848
848
}
849
849
850
- #[ test]
851
- #[ should_panic( expected = "Attempt to replace non-empty ValidationErrors entry" ) ]
852
- #[ allow( unused) ]
853
- fn test_field_validation_errors_replaced_with_nested_validations_fails ( ) {
854
- #[ derive( Debug ) ]
855
- struct ParentWithOverridingStructValidations {
856
- child : Vec < Child > ,
857
- }
858
-
859
- #[ derive( Debug , Validate , Serialize ) ]
860
- struct Child {
861
- #[ validate( length( min = 1 ) ) ]
862
- value : String ,
863
- }
864
-
865
- impl Validate for ParentWithOverridingStructValidations {
866
- // Evaluating structs after fields validations have discovered errors should fail because
867
- // field validations are expected to take priority over nested struct validations
868
- #[ allow( unused_mut) ]
869
- fn validate ( & self ) -> Result < ( ) , ValidationErrors > {
870
- // First validate the length of the vector:
871
- let mut errors = ValidationErrors :: new ( ) ;
872
- if !self . child . validate_length ( Some ( 2u64 ) , None , None ) {
873
- let mut err = ValidationError :: new ( "length" ) ;
874
- err. add_param ( Cow :: from ( "min" ) , & 2u64 ) ;
875
- err. add_param ( Cow :: from ( "value" ) , & & self . child ) ;
876
- errors. add ( "child" , err) ;
877
- }
878
-
879
- // Then validate the nested vector of structs without checking for existing field errors:
880
- let mut result = if errors. is_empty ( ) { Ok ( ( ) ) } else { Err ( errors) } ;
881
- {
882
- let results: Vec < _ > = self
883
- . child
884
- . iter ( )
885
- . map ( |child| {
886
- let mut result = Ok ( ( ) ) ;
887
- result = ValidationErrors :: merge ( result, "child" , child. validate ( ) ) ;
888
- result
889
- } )
890
- . collect ( ) ;
891
- result = ValidationErrors :: merge_all ( result, "child" , results) ;
892
- }
893
- result
894
- }
895
- }
896
-
897
- let instance =
898
- ParentWithOverridingStructValidations { child : vec ! [ Child { value: String :: new( ) } ] } ;
899
- instance. validate ( ) ;
900
- }
901
-
902
850
#[ test]
903
851
#[ should_panic(
904
852
expected = "Attempt to add field validation to a non-Field ValidationErrorsKind instance"
0 commit comments