diff --git a/crates/bevy_ptr/src/lib.rs b/crates/bevy_ptr/src/lib.rs index e8173f674c47a9..32692218962189 100644 --- a/crates/bevy_ptr/src/lib.rs +++ b/crates/bevy_ptr/src/lib.rs @@ -161,6 +161,7 @@ impl<'a> OwningPtr<'a> { #[inline] pub fn make) -> R, R>(val: T, f: F) -> R { let mut temp = MaybeUninit::new(val); + // SAFETY: `temp.as_mut_ptr()` is a reference to a local value on the stack, so it cannot be null let ptr = unsafe { NonNull::new_unchecked(temp.as_mut_ptr().cast::()) }; f(Self(ptr, PhantomData)) } @@ -233,6 +234,7 @@ impl<'a, T> From<&'a [T]> for ThinSlicePtr<'a, T> { #[inline] fn from(slice: &'a [T]) -> Self { Self { + // SAFETY: a reference can never be null ptr: unsafe { NonNull::new_unchecked(slice.as_ptr() as *mut T) }, #[cfg(debug_assertions)] len: slice.len(), diff --git a/crates/bevy_utils/src/futures.rs b/crates/bevy_utils/src/futures.rs index dc0f68d5d1c68c..1b752a33c70ff3 100644 --- a/crates/bevy_utils/src/futures.rs +++ b/crates/bevy_utils/src/futures.rs @@ -29,5 +29,7 @@ fn noop_raw_waker() -> RawWaker { } fn noop_waker() -> Waker { + // SAFETY: the `RawWakerVTable` is just a big noop and doesn't violate any of the rules in `RawWakerVTable`s documentation + // (which talks about retaining and releasing any "resources", of which there are none in this case) unsafe { Waker::from_raw(noop_raw_waker()) } }