File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -443,12 +443,22 @@ pub trait Deref {
443
443
fn deref ( & self ) -> & Self :: Target ;
444
444
}
445
445
446
+ pub trait Allocator {
447
+ }
448
+
449
+ pub struct Global ;
450
+
451
+ impl Allocator for Global { }
452
+
446
453
#[ 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 ) ;
448
458
449
459
impl < T : ?Sized + Unsize < U > , U : ?Sized > CoerceUnsized < Box < U > > for Box < T > { }
450
460
451
- impl < T : ?Sized > Drop for Box < T > {
461
+ impl < T : ?Sized , A : Allocator > Drop for Box < T , A > {
452
462
fn drop ( & mut self ) {
453
463
// drop is currently performed by compiler.
454
464
}
@@ -468,7 +478,7 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
468
478
}
469
479
470
480
#[ 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 ) {
472
482
libc:: free ( ptr as * mut u8 ) ;
473
483
}
474
484
Original file line number Diff line number Diff line change @@ -251,7 +251,9 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
251
251
ty:: Ref ( ..) | ty:: RawPtr ( _) => {
252
252
return self . field ( cx, index) . gcc_type ( cx, true ) ;
253
253
}
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 ( ) => {
255
257
let ptr_ty = cx. tcx . mk_mut_ptr ( self . ty . boxed_ty ( ) ) ;
256
258
return cx. layout_of ( ptr_ty) . scalar_pair_element_gcc_type ( cx, index, immediate) ;
257
259
}
You can’t perform that action at this time.
0 commit comments