Skip to content

Commit 34ac70d

Browse files
committed
cargo fmt
1 parent 74a60a6 commit 34ac70d

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

pgrx-unit-tests/src/tests/pbox_slice_tests.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

pgrx/src/palloc/pbox.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ impl<'mcx, T> PBox<'mcx, [MaybeUninit<T>]> {
166166
}
167167

168168
/// Zeroed counterpart of [`new_huge_uninit_slice_in`].
169+
///
170+
/// [`new_huge_uninit_slice_in`]: PBox::new_huge_uninit_slice_in
169171
pub fn new_huge_zeroed_slice_in(len: usize, cx: &MemCx<'mcx>) -> Result<Self, OutOfMemory> {
170172
const { assert!(align_of::<T>() <= size_of::<pg_sys::Datum>()) };
171173
let layout = core::alloc::Layout::array::<T>(len).map_err(|_| OutOfMemory::new())?;

0 commit comments

Comments
 (0)