Skip to content

Commit 878336c

Browse files
Rollup merge of #160323 - RalfJung:no-unleak, r=nia-e
Box::leak: tell people to avoid unleaking r? @nia-e Cc @rust-lang/opsem Note that this goes against the advice given by clippy in rust-lang/rust-clippy#17336. I think clippy should be adjusted to recommend `Box::into_non_null` instead. @ArhanChaudhary wold be great if you could make a clippy PR for that. :)
2 parents 2c109f1 + bb24b38 commit 878336c

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

library/alloc/src/boxed.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,12 +1896,12 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
18961896
/// has only static references, or none at all, then this may be chosen to be
18971897
/// `'static`.
18981898
///
1899-
/// This function is mainly useful for data that lives for the remainder of
1900-
/// the program's life. Dropping the returned reference will cause a memory
1901-
/// leak. If this is not acceptable, the reference should first be wrapped
1902-
/// with the [`Box::from_raw`] function producing a `Box`. This `Box` can
1903-
/// then be dropped which will properly destroy `T` and release the
1904-
/// allocated memory.
1899+
/// This function is mainly useful for data that lives for the remainder of the program's life,
1900+
/// i.e., memory that is meant to leak. Reconstructing ("unleaking") a `Box` from the mutable
1901+
/// reference returned here (e.g. via [`Box::from_raw`]) is a grey area (meaning it is possible
1902+
/// under specific circumstances but many seemingly harmless ways of doing it are undefined
1903+
/// behavior) and should be avoided. If the memory should eventually be freed, prefer to use
1904+
/// [`Box::into_raw`] or [`Box::into_non_null`] instead.
19051905
///
19061906
/// Note: this is an associated function, which means that you have
19071907
/// to call it as `Box::leak(b)` instead of `b.leak()`. This

0 commit comments

Comments
 (0)