File tree 1 file changed +24
-0
lines changed
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 ;
1
4
use std:: assert_matches:: assert_matches;
2
5
use std:: borrow:: Cow ;
3
6
use std:: cell:: Cell ;
@@ -991,6 +994,27 @@ fn test_into_iter_advance_by() {
991
994
assert_eq ! ( i. len( ) , 0 ) ;
992
995
}
993
996
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
+
994
1018
#[ test]
995
1019
fn test_from_iter_specialization ( ) {
996
1020
let src: Vec < usize > = vec ! [ 0usize ; 1 ] ;
You can’t perform that action at this time.
0 commit comments