File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,8 @@ impl<T> Ptr<T> {
177
177
}
178
178
179
179
pub fn dangling ( ) -> Self {
180
- unsafe { Self :: from_parts ( initial_tag_value ( ) , 1 ) }
180
+ // `anchor()` returns a well-aligned pointer so an offset of 0 will also produce a well-aligned pointer
181
+ unsafe { Self :: from_parts ( initial_tag_value ( ) , 0 ) }
181
182
}
182
183
183
184
pub unsafe fn as_ref ( & self ) -> & T {
Original file line number Diff line number Diff line change @@ -354,6 +354,25 @@ mod tests {
354
354
assert_eq ! ( * A :: alloc( ) . unwrap( ) . init( 1 ) , 1 ) ;
355
355
}
356
356
357
+ #[ test]
358
+ fn boxed_zst_is_well_aligned ( ) {
359
+ #[ repr( align( 2 ) ) ]
360
+ pub struct Zst2 ;
361
+
362
+ pool ! ( A : Zst2 ) ;
363
+
364
+ let x = A :: alloc ( ) . unwrap ( ) . init ( Zst2 ) ;
365
+ assert_eq ! ( 0 , & * x as * const Zst2 as usize % 2 ) ;
366
+
367
+ #[ repr( align( 4096 ) ) ]
368
+ pub struct Zst4096 ;
369
+
370
+ pool ! ( B : Zst4096 ) ;
371
+
372
+ let x = B :: alloc ( ) . unwrap ( ) . init ( Zst4096 ) ;
373
+ assert_eq ! ( 0 , & * x as * const Zst4096 as usize % 4096 ) ;
374
+ }
375
+
357
376
#[ test]
358
377
fn destructors ( ) {
359
378
static COUNT : AtomicUsize = AtomicUsize :: new ( 0 ) ;
You can’t perform that action at this time.
0 commit comments