Skip to content

Commit cb27821

Browse files
chescocktigregalis
authored andcommitted
Use ptr::is_aligned now that it's stable. (bevyengine#21422)
# Objective Simplify implementation of `debug_ensure_aligned`. The code has a comment asking for the implementation to be replaced when `ptr::is_aligned_to` is stable. While `is_aligned_to` hasn't been stabilized, `ptr::is_aligned` has, and is what we want here anyway. ## Solution Use `ptr::is_aligned`.
1 parent 8f61fcf commit cb27821

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

crates/bevy_ptr/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,17 +1173,11 @@ trait DebugEnsureAligned {
11731173
impl<T: Sized> DebugEnsureAligned for *mut T {
11741174
#[track_caller]
11751175
fn debug_ensure_aligned(self) -> Self {
1176-
let align = align_of::<T>();
1177-
// Implementation shamelessly borrowed from the currently unstable
1178-
// ptr.is_aligned_to.
1179-
//
1180-
// Replace once https://github.com/rust-lang/rust/issues/96284 is stable.
1181-
assert_eq!(
1182-
self as usize & (align - 1),
1183-
0,
1176+
assert!(
1177+
self.is_aligned(),
11841178
"pointer is not aligned. Address {:p} does not have alignment {} for type {}",
11851179
self,
1186-
align,
1180+
align_of::<T>(),
11871181
core::any::type_name::<T>()
11881182
);
11891183
self

0 commit comments

Comments
 (0)