impl<T: Generator<ResumeTy, Yield = ()>> Future for GenFuture<T> {
type Output = T::Return;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
- // Safety: Safe because we're !Unpin + !Drop, and this is just a field projection.
+ // SAFETY: Safe because we're !Unpin + !Drop, and this is just a field projection.
let gen = unsafe { Pin::map_unchecked_mut(self, |s| &mut s.0) };
// Resume the generator, turning the `&mut Context` into a `NonNull` raw pointer. The
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
match self.iter {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
Some(ref mut iter) => unsafe { SourceIter::as_inner(iter) },
// SAFETY: the specialized iterator never sets `None`
None => unsafe { intrinsics::unreachable() },
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
- // Safety: unsafe function forwarding to unsafe function with the same requirements
+ // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.a) }
}
}
/// Returns `None` if the cell is empty.
#[unstable(feature = "once_cell", issue = "74465")]
pub fn get(&self) -> Option<&T> {
- // Safety: Safe due to `inner`'s invariant
+ // SAFETY: Safe due to `inner`'s invariant
unsafe { &*self.inner.get() }.as_ref()
}
/// Returns `None` if the cell is empty.
#[unstable(feature = "once_cell", issue = "74465")]
pub fn get_mut(&mut self) -> Option<&mut T> {
- // Safety: Safe because we have unique access
+ // SAFETY: Safe because we have unique access
unsafe { &mut *self.inner.get() }.as_mut()
}
/// ```
#[unstable(feature = "once_cell", issue = "74465")]
pub fn set(&self, value: T) -> Result<(), T> {
- // Safety: Safe because we cannot have overlapping mutable borrows
+ // SAFETY: Safe because we cannot have overlapping mutable borrows
let slot = unsafe { &*self.inner.get() };
if slot.is_some() {
return Err(value);
}
- // Safety: This is the only place where we set the slot, no races
+ // SAFETY: This is the only place where we set the slot, no races
// due to reentrancy/concurrency are possible, and we've
// checked that slot is currently `None`, so this write
// maintains the `inner`'s invariant.
/// // Now that our `MaybeUninit<_>` is known to be initialized, it is okay to
/// // create a shared reference to it:
/// let x: &Vec<u32> = unsafe {
- /// // Safety: `x` has been initialized.
+ /// // SAFETY: `x` has been initialized.
/// x.assume_init_ref()
/// };
/// assert_eq!(x, &vec![1, 2, 3]);
/// // To assert our buffer has been initialized without copying it, we upgrade
/// // the `&mut MaybeUninit<[u8; 2048]>` to a `&mut [u8; 2048]`:
/// let buf: &mut [u8; 2048] = unsafe {
- /// // Safety: `buf` has been initialized.
+ /// // SAFETY: `buf` has been initialized.
/// buf.assume_init_mut()
/// };
///
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
- // Safety: since `self` and `rhs` are both nonzero, the
+ // SAFETY: since `self` and `rhs` are both nonzero, the
// result of the bitwise-or will be nonzero.
unsafe { $Ty::new_unchecked(self.get() | rhs.get()) }
}
type Output = Self;
#[inline]
fn bitor(self, rhs: $Int) -> Self::Output {
- // Safety: since `self` is nonzero, the result of the
+ // SAFETY: since `self` is nonzero, the result of the
// bitwise-or will be nonzero regardless of the value of
// `rhs`.
unsafe { $Ty::new_unchecked(self.get() | rhs) }
type Output = $Ty;
#[inline]
fn bitor(self, rhs: $Ty) -> Self::Output {
- // Safety: since `rhs` is nonzero, the result of the
+ // SAFETY: since `rhs` is nonzero, the result of the
// bitwise-or will be nonzero regardless of the value of
// `self`.
unsafe { $Ty::new_unchecked(self | rhs.get()) }
#[stable(feature = "pin", since = "1.33.0")]
#[inline(always)]
pub fn new(pointer: P) -> Pin<P> {
- // Safety: the value pointed to is `Unpin`, and so has no requirements
+ // SAFETY: the value pointed to is `Unpin`, and so has no requirements
// around pinning.
unsafe { Pin::new_unchecked(pointer) }
}
(word_ptr as usize) - (start as usize) == byte_pos
);
- // Safety: We know `word_ptr` is properly aligned (because of
+ // SAFETY: We know `word_ptr` is properly aligned (because of
// `align_offset`), and we know that we have enough bytes between `word_ptr` and the end
let word = unsafe { word_ptr.read() };
if contains_nonascii(word) {
}
}
- // Safety: Same as `AllocRef::grow`
+ // SAFETY: Same as `AllocRef::grow`
#[inline]
unsafe fn grow_impl(
&mut self,
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)
}
#[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.
debug_assert!(self.is_initialized());
- // Safety: The inner value has been initialized
+ // SAFETY: The inner value has been initialized
Ok(unsafe { self.get_unchecked() })
}
/// ```
#[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
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() };
}
}
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
#[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) }
#[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) }