This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -443,12 +443,22 @@ pub trait Deref {
443443 fn deref ( & self ) -> & Self :: Target ;
444444}
445445
446+ pub trait Allocator {
447+ }
448+
449+ pub struct Global ;
450+
451+ impl Allocator for Global { }
452+
446453#[ lang = "owned_box" ]
447- pub struct Box < T : ?Sized > ( * mut T ) ;
454+ pub struct Box <
455+ T : ?Sized ,
456+ A : Allocator = Global ,
457+ > ( * mut T , A ) ;
448458
449459impl < T : ?Sized + Unsize < U > , U : ?Sized > CoerceUnsized < Box < U > > for Box < T > { }
450460
451- impl < T : ?Sized > Drop for Box < T > {
461+ impl < T : ?Sized , A : Allocator > Drop for Box < T , A > {
452462 fn drop ( & mut self ) {
453463 // drop is currently performed by compiler.
454464 }
@@ -468,7 +478,7 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
468478}
469479
470480#[ lang = "box_free" ]
471- unsafe fn box_free < T : ?Sized > ( ptr : * mut T ) {
481+ unsafe fn box_free < T : ?Sized , A : Allocator > ( ptr : * mut T , alloc : A ) {
472482 libc:: free ( ptr as * mut u8 ) ;
473483}
474484
Original file line number Diff line number Diff line change @@ -251,7 +251,9 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
251251 ty:: Ref ( ..) | ty:: RawPtr ( _) => {
252252 return self . field ( cx, index) . gcc_type ( cx, true ) ;
253253 }
254- ty:: Adt ( def, _) if def. is_box ( ) => {
254+ // only wide pointer boxes are handled as pointers
255+ // thin pointer boxes with scalar allocators are handled by the general logic below
256+ ty:: Adt ( def, substs) if def. is_box ( ) && cx. layout_of ( substs. type_at ( 1 ) ) . is_zst ( ) => {
255257 let ptr_ty = cx. tcx . mk_mut_ptr ( self . ty . boxed_ty ( ) ) ;
256258 return cx. layout_of ( ptr_ty) . scalar_pair_element_gcc_type ( cx, index, immediate) ;
257259 }
You can’t perform that action at this time.
0 commit comments