@@ -62,17 +62,18 @@ mod tests {
6262 let before = pg_sys:: MemoryContextMemAllocated ( parent, false ) ;
6363
6464 let child = PgMemoryContexts :: new ( "pbox_slice_test_scope" ) ;
65- // Switch CMC and arm the restore guard (drops in LIFO before `child`).
66- let _restore = {
65+ // Switch CMC and arm the restore guard. The guard is held in a
66+ // named binding (NOT `let _ = ...`, which would drop immediately)
67+ // so it lives until the end of the unsafe block, then drops in
68+ // LIFO order before `child` — restoring CMC before the child
69+ // context is deleted. `#[allow(unused_variables)]` silences the
70+ // dead-binding lint since the guard's effect is in its Drop impl.
71+ #[ allow( unused_variables) ]
72+ let restore_guard = {
6773 let previous = pg_sys:: MemoryContextSwitchTo ( child. value ( ) ) ;
6874 CxRestoreGuard { previous }
6975 } ;
7076 memcx:: current_context ( |cx| f ( cx) ) ;
71- drop ( _restore) ;
72-
73- // Drop the owned child explicitly so MemoryContextDelete runs
74- // before we sample `after`.
75- drop ( child) ;
7677
7778 let after = pg_sys:: MemoryContextMemAllocated ( parent, false ) ;
7879 assert_eq ! (
@@ -202,8 +203,7 @@ mod tests {
202203 }
203204 }
204205 memcx:: current_context ( |cx| {
205- let r =
206- PBox :: < [ u32 ] > :: from_iter_in ( OverIter { i : 0 , promised : 3 } , cx) . expect ( "alloc" ) ;
206+ let r = PBox :: < [ u32 ] > :: from_iter_in ( OverIter { i : 0 , promised : 3 } , cx) . expect ( "alloc" ) ;
207207 assert_eq ! ( & * r, & [ 0u32 , 1 , 2 ] ) ;
208208 } ) ;
209209 }
@@ -351,8 +351,7 @@ mod tests {
351351 fn from_huge_iter_in_roundtrip ( ) {
352352 memcx:: current_context ( |cx| {
353353 let v: Vec < i64 > = ( 100 ..110 ) . collect ( ) ;
354- let dst: PBox < [ i64 ] > =
355- PBox :: from_huge_iter_in ( v. iter ( ) . copied ( ) , cx) . expect ( "alloc" ) ;
354+ let dst: PBox < [ i64 ] > = PBox :: from_huge_iter_in ( v. iter ( ) . copied ( ) , cx) . expect ( "alloc" ) ;
356355 assert_eq ! ( & * dst, v. as_slice( ) ) ;
357356 } ) ;
358357 }
0 commit comments