Skip to content

Commit 7e45c45

Browse files
authored
fix(bevy_ptr): correct Debug impl for MovingPtr (#21040)
# Objective 1. Fix incorrect macro usage in Debug implementation. 2. (unimportant) Enforce consistent formatting for unsafe blocks. ## Solution 1. I'm not sure why `$ptr` appeared in the `Debug` implementation for `MovingPtr`, as this isn't in a macro context. I believe it was a mistake, so I changed `stringify!($ptr)` to `"MovingPtr"`. 2. If a function has no return value (returns `()`), the final statement should end with a semicolon. (At least maintain a consistent style.) Therefore, change `unsafe { ... };` and `unsafe { ... }` to the unified `unsafe { ...; }`. ## Testing - `cargo test -p bevy_ptr` is passed. - Several examples have been running normally. - No more testing is needed.
1 parent 25fd63b commit 7e45c45

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/bevy_ptr/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ impl IsAligned for Aligned {
105105
// - The caller is required to ensure that `ptr` points must be valid for dropping.
106106
// - The caller is required to ensure that the value `ptr` points must not be used after this function
107107
// call.
108-
unsafe { ptr::drop_in_place(ptr) };
108+
unsafe {
109+
ptr::drop_in_place(ptr);
110+
}
109111
}
110112
}
111113

@@ -145,7 +147,9 @@ impl IsAligned for Unaligned {
145147
// - The caller is required to ensure that `ptr` points must be valid for dropping.
146148
// - The caller is required to ensure that the value `ptr` points must not be used after this function
147149
// call.
148-
unsafe { drop(ptr.read_unaligned()) }
150+
unsafe {
151+
drop(ptr.read_unaligned());
152+
}
149153
}
150154
}
151155

@@ -734,14 +738,14 @@ impl<T, A: IsAligned> Pointer for MovingPtr<'_, T, A> {
734738
impl<T> Debug for MovingPtr<'_, T, Aligned> {
735739
#[inline]
736740
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
737-
write!(f, "{}<Aligned>({:?})", stringify!($ptr), self.0)
741+
write!(f, "MovingPtr<Aligned>({:?})", self.0)
738742
}
739743
}
740744

741745
impl<T> Debug for MovingPtr<'_, T, Unaligned> {
742746
#[inline]
743747
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
744-
write!(f, "{}<Unaligned>({:?})", stringify!($ptr), self.0)
748+
write!(f, "MovingPtr<Unaligned>({:?})", self.0)
745749
}
746750
}
747751

0 commit comments

Comments
 (0)