Skip to content

Commit

Permalink
Remove non-focused memory leaks in alloc doctests for Miri.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachs18 committed Jul 7, 2024
1 parent 5569ece commit cac8902
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,8 @@ impl<T: ?Sized> Rc<T> {
///
/// let five = Rc::from_raw(ptr);
/// assert_eq!(2, Rc::strong_count(&five));
/// # // Prevent leaks for Miri.
/// # Rc::decrement_strong_count(ptr);
/// }
/// ```
#[inline]
Expand Down Expand Up @@ -1344,6 +1346,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
/// let x = Rc::new("hello".to_owned());
/// let x_ptr = Rc::into_raw(x);
/// assert_eq!(unsafe { &*x_ptr }, "hello");
/// # // Prevent leaks for Miri.
/// # drop(unsafe { Rc::from_raw(x_ptr) });
/// ```
#[must_use = "losing the pointer will leak memory"]
#[stable(feature = "rc_raw", since = "1.17.0")]
Expand Down Expand Up @@ -1571,6 +1575,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
///
/// let five = Rc::from_raw_in(ptr, System);
/// assert_eq!(2, Rc::strong_count(&five));
/// # // Prevent leaks for Miri.
/// # Rc::decrement_strong_count_in(ptr, System);
/// }
/// ```
#[inline]
Expand Down
6 changes: 6 additions & 0 deletions alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,8 @@ impl<T: ?Sized> Arc<T> {
/// // the `Arc` between threads.
/// let five = Arc::from_raw(ptr);
/// assert_eq!(2, Arc::strong_count(&five));
/// # // Prevent leaks for Miri.
/// # Arc::decrement_strong_count(ptr);
/// }
/// ```
#[inline]
Expand Down Expand Up @@ -1487,6 +1489,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
/// let x = Arc::new("hello".to_owned());
/// let x_ptr = Arc::into_raw(x);
/// assert_eq!(unsafe { &*x_ptr }, "hello");
/// # // Prevent leaks for Miri.
/// # drop(unsafe { Arc::from_raw(x_ptr) });
/// ```
#[must_use = "losing the pointer will leak memory"]
#[stable(feature = "rc_raw", since = "1.17.0")]
Expand Down Expand Up @@ -1769,6 +1773,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
/// // the `Arc` between threads.
/// let five = Arc::from_raw_in(ptr, System);
/// assert_eq!(2, Arc::strong_count(&five));
/// # // Prevent leaks for Miri.
/// # Arc::decrement_strong_count_in(ptr, System);
/// }
/// ```
#[inline]
Expand Down

0 comments on commit cac8902

Please sign in to comment.