Remove non-focused memory leaks in core doctests for Miri.

This commit is contained in:
Zachary S 2024-07-06 22:53:31 -05:00
parent e0ed696d2f
commit e4c064d813
2 changed files with 14 additions and 0 deletions

View File

@ -274,6 +274,8 @@ impl<T> MaybeUninit<T> {
/// use std::mem::MaybeUninit; /// use std::mem::MaybeUninit;
/// ///
/// let v: MaybeUninit<Vec<u8>> = MaybeUninit::new(vec![42]); /// let v: MaybeUninit<Vec<u8>> = MaybeUninit::new(vec![42]);
/// # // Prevent leaks for Miri
/// # unsafe { let _ = MaybeUninit::assume_init(v); }
/// ``` /// ```
/// ///
/// [`assume_init`]: MaybeUninit::assume_init /// [`assume_init`]: MaybeUninit::assume_init
@ -506,6 +508,8 @@ impl<T> MaybeUninit<T> {
/// // Create a reference into the `MaybeUninit<T>`. This is okay because we initialized it. /// // Create a reference into the `MaybeUninit<T>`. This is okay because we initialized it.
/// let x_vec = unsafe { &*x.as_ptr() }; /// let x_vec = unsafe { &*x.as_ptr() };
/// assert_eq!(x_vec.len(), 3); /// assert_eq!(x_vec.len(), 3);
/// # // Prevent leaks for Miri
/// # unsafe { MaybeUninit::assume_init_drop(&mut x); }
/// ``` /// ```
/// ///
/// *Incorrect* usage of this method: /// *Incorrect* usage of this method:
@ -545,6 +549,8 @@ impl<T> MaybeUninit<T> {
/// let x_vec = unsafe { &mut *x.as_mut_ptr() }; /// let x_vec = unsafe { &mut *x.as_mut_ptr() };
/// x_vec.push(3); /// x_vec.push(3);
/// assert_eq!(x_vec.len(), 4); /// assert_eq!(x_vec.len(), 4);
/// # // Prevent leaks for Miri
/// # unsafe { MaybeUninit::assume_init_drop(&mut x); }
/// ``` /// ```
/// ///
/// *Incorrect* usage of this method: /// *Incorrect* usage of this method:
@ -746,6 +752,8 @@ impl<T> MaybeUninit<T> {
/// use std::mem::MaybeUninit; /// use std::mem::MaybeUninit;
/// ///
/// let mut x = MaybeUninit::<Vec<u32>>::uninit(); /// let mut x = MaybeUninit::<Vec<u32>>::uninit();
/// # let mut x_mu = x;
/// # let mut x = &mut x_mu;
/// // Initialize `x`: /// // Initialize `x`:
/// x.write(vec![1, 2, 3]); /// x.write(vec![1, 2, 3]);
/// // Now that our `MaybeUninit<_>` is known to be initialized, it is okay to /// // Now that our `MaybeUninit<_>` is known to be initialized, it is okay to
@ -755,6 +763,8 @@ impl<T> MaybeUninit<T> {
/// x.assume_init_ref() /// x.assume_init_ref()
/// }; /// };
/// assert_eq!(x, &vec![1, 2, 3]); /// assert_eq!(x, &vec![1, 2, 3]);
/// # // Prevent leaks for Miri
/// # unsafe { MaybeUninit::assume_init_drop(&mut x_mu); }
/// ``` /// ```
/// ///
/// ### *Incorrect* usages of this method: /// ### *Incorrect* usages of this method:
@ -1088,6 +1098,8 @@ impl<T> MaybeUninit<T> {
/// let init = MaybeUninit::clone_from_slice(&mut dst, &src); /// let init = MaybeUninit::clone_from_slice(&mut dst, &src);
/// ///
/// assert_eq!(init, src); /// assert_eq!(init, src);
/// # // Prevent leaks for Miri
/// # unsafe { std::ptr::drop_in_place(init); }
/// ``` /// ```
/// ///
/// ``` /// ```

View File

@ -1663,6 +1663,8 @@ impl<T> NonNull<[T]> {
/// // Note that calling `memory.as_mut()` is not allowed here as the content may be uninitialized. /// // Note that calling `memory.as_mut()` is not allowed here as the content may be uninitialized.
/// # #[allow(unused_variables)] /// # #[allow(unused_variables)]
/// let slice: &mut [MaybeUninit<u8>] = unsafe { memory.as_uninit_slice_mut() }; /// let slice: &mut [MaybeUninit<u8>] = unsafe { memory.as_uninit_slice_mut() };
/// # // Prevent leaks for Miri.
/// # unsafe { Global.deallocate(memory.cast(), Layout::new::<[u8; 32]>()); }
/// # Ok::<_, std::alloc::AllocError>(()) /// # Ok::<_, std::alloc::AllocError>(())
/// ``` /// ```
#[inline] #[inline]