File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ use core:: alloc:: { Allocator , Layout } ;
2+ use core:: ptr:: NonNull ;
3+ use std:: alloc:: System ;
14use std:: assert_matches:: assert_matches;
25use std:: borrow:: Cow ;
36use std:: cell:: Cell ;
@@ -991,6 +994,27 @@ fn test_into_iter_advance_by() {
991994 assert_eq ! ( i. len( ) , 0 ) ;
992995}
993996
997+ #[ test]
998+ fn test_into_iter_drop_allocator ( ) {
999+ struct ReferenceCountedAllocator < ' a > ( DropCounter < ' a > ) ;
1000+
1001+ unsafe impl Allocator for ReferenceCountedAllocator < ' _ > {
1002+ fn allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , core:: alloc:: AllocError > {
1003+ System . allocate ( layout)
1004+ }
1005+
1006+ unsafe fn deallocate ( & self , ptr : NonNull < u8 > , layout : Layout ) {
1007+ System . deallocate ( ptr, layout)
1008+ }
1009+ }
1010+
1011+ let mut drop_count = 0 ;
1012+ let allocator = ReferenceCountedAllocator ( DropCounter { count : & mut drop_count } ) ;
1013+ let _ = Vec :: < u32 , _ > :: new_in ( allocator) . into_iter ( ) ;
1014+
1015+ assert_eq ! ( drop_count, 1 ) ;
1016+ }
1017+
9941018#[ test]
9951019fn test_from_iter_specialization ( ) {
9961020 let src: Vec < usize > = vec ! [ 0usize ; 1 ] ;
You can’t perform that action at this time.
0 commit comments