1
Fork 0

Capitalize safety comments

This commit is contained in:
Flying-Toast 2020-09-08 22:26:44 -04:00
parent 90782cb50b
commit c66789d572
15 changed files with 38 additions and 38 deletions

View file

@ -149,7 +149,7 @@ impl System {
}
}
// Safety: Same as `AllocRef::grow`
// SAFETY: Same as `AllocRef::grow`
#[inline]
unsafe fn grow_impl(
&mut self,

View file

@ -881,13 +881,13 @@ impl From<Vec<NonZeroU8>> for CString {
unsafe {
// Transmute `Vec<NonZeroU8>` to `Vec<u8>`.
let v: Vec<u8> = {
// Safety:
// SAFETY:
// - transmuting between `NonZeroU8` and `u8` is sound;
// - `alloc::Layout<NonZeroU8> == alloc::Layout<u8>`.
let (ptr, len, cap): (*mut NonZeroU8, _, _) = Vec::into_raw_parts(v);
Vec::from_raw_parts(ptr.cast::<u8>(), len, cap)
};
// Safety: `v` cannot contain null bytes, given the type-level
// SAFETY: `v` cannot contain null bytes, given the type-level
// invariant of `NonZeroU8`.
CString::from_vec_unchecked(v)
}

View file

@ -510,14 +510,14 @@ impl OsStr {
#[inline]
fn from_inner(inner: &Slice) -> &OsStr {
// Safety: OsStr is just a wrapper of Slice,
// SAFETY: OsStr is just a wrapper of Slice,
// therefore converting &Slice to &OsStr is safe.
unsafe { &*(inner as *const Slice as *const OsStr) }
}
#[inline]
fn from_inner_mut(inner: &mut Slice) -> &mut OsStr {
// Safety: OsStr is just a wrapper of Slice,
// SAFETY: OsStr is just a wrapper of Slice,
// therefore converting &mut Slice to &mut OsStr is safe.
// Any method that mutates OsStr must be careful not to
// break platform-specific encoding, in particular Wtf8 on Windows.

View file

@ -293,7 +293,7 @@ impl<T> SyncOnceCell<T> {
debug_assert!(self.is_initialized());
// Safety: The inner value has been initialized
// SAFETY: The inner value has been initialized
Ok(unsafe { self.get_unchecked() })
}
@ -316,7 +316,7 @@ impl<T> SyncOnceCell<T> {
/// ```
#[unstable(feature = "once_cell", issue = "74465")]
pub fn into_inner(mut self) -> Option<T> {
// Safety: Safe because we immediately free `self` without dropping
// SAFETY: Safe because we immediately free `self` without dropping
let inner = unsafe { self.take_inner() };
// Don't drop this `SyncOnceCell`. We just moved out one of the fields, but didn't set
@ -416,7 +416,7 @@ impl<T> SyncOnceCell<T> {
unsafe impl<#[may_dangle] T> Drop for SyncOnceCell<T> {
fn drop(&mut self) {
// Safety: The cell is being dropped, so it can't be accessed again.
// SAFETY: The cell is being dropped, so it can't be accessed again.
// We also don't touch the `T`, which validates our usage of #[may_dangle].
unsafe { self.take_inner() };
}

View file

@ -77,14 +77,14 @@ impl Buf {
}
pub fn as_slice(&self) -> &Slice {
// Safety: Slice is just a wrapper for Wtf8,
// SAFETY: Slice is just a wrapper for Wtf8,
// and self.inner.as_slice() returns &Wtf8.
// Therefore, transmuting &Wtf8 to &Slice is safe.
unsafe { mem::transmute(self.inner.as_slice()) }
}
pub fn as_mut_slice(&mut self) -> &mut Slice {
// Safety: Slice is just a wrapper for Wtf8,
// SAFETY: Slice is just a wrapper for Wtf8,
// and self.inner.as_mut_slice() returns &mut Wtf8.
// Therefore, transmuting &mut Wtf8 to &mut Slice is safe.
// Additionally, care should be taken to ensure the slice

View file

@ -106,7 +106,7 @@ impl Buf {
#[inline]
pub fn as_slice(&self) -> &Slice {
// Safety: Slice just wraps [u8],
// SAFETY: Slice just wraps [u8],
// and &*self.inner is &[u8], therefore
// transmuting &[u8] to &Slice is safe.
unsafe { mem::transmute(&*self.inner) }
@ -114,7 +114,7 @@ impl Buf {
#[inline]
pub fn as_mut_slice(&mut self) -> &mut Slice {
// Safety: Slice just wraps [u8],
// SAFETY: Slice just wraps [u8],
// and &mut *self.inner is &mut [u8], therefore
// transmuting &mut [u8] to &mut Slice is safe.
unsafe { mem::transmute(&mut *self.inner) }