Skip to content

Commit 697377a

Browse files
committed
Clarify/add must_use messages for more into_raw* functions of alloc types.
1 parent 4552576 commit 697377a

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

alloc/src/boxed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
10971097
/// ```
10981098
///
10991099
/// [memory layout]: self#memory-layout
1100+
#[must_use = "losing the pointer will leak memory"]
11001101
#[stable(feature = "box_raw", since = "1.4.0")]
11011102
#[inline]
11021103
pub fn into_raw(b: Self) -> *mut T {
@@ -1150,6 +1151,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11501151
/// ```
11511152
///
11521153
/// [memory layout]: self#memory-layout
1154+
#[must_use = "losing the pointer will leak memory"]
11531155
#[unstable(feature = "allocator_api", issue = "32838")]
11541156
#[inline]
11551157
pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) {

alloc/src/rc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
13721372
/// let x = unsafe { Rc::from_raw_in(ptr, alloc) };
13731373
/// assert_eq!(&*x, "hello");
13741374
/// ```
1375+
#[must_use = "losing the pointer will leak memory"]
13751376
#[unstable(feature = "allocator_api", issue = "32838")]
13761377
pub fn into_raw_with_allocator(this: Self) -> (*const T, A) {
13771378
let this = mem::ManuallyDrop::new(this);
@@ -3100,6 +3101,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
31003101
///
31013102
/// [`from_raw_in`]: Weak::from_raw_in
31023103
/// [`as_ptr`]: Weak::as_ptr
3104+
#[must_use = "losing the pointer will leak memory"]
31033105
#[inline]
31043106
#[unstable(feature = "allocator_api", issue = "32838")]
31053107
pub fn into_raw_with_allocator(self) -> (*const T, A) {

alloc/src/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ impl String {
903903
/// let rebuilt = unsafe { String::from_raw_parts(ptr, len, cap) };
904904
/// assert_eq!(rebuilt, "hello");
905905
/// ```
906-
#[must_use = "`self` will be dropped if the result is not used"]
906+
#[must_use = "losing the pointer will leak memory"]
907907
#[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
908908
pub fn into_raw_parts(self) -> (*mut u8, usize, usize) {
909909
self.vec.into_raw_parts()

alloc/src/vec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ impl<T, A: Allocator> Vec<T, A> {
879879
/// };
880880
/// assert_eq!(rebuilt, [4294967295, 0, 1]);
881881
/// ```
882+
#[must_use = "losing the pointer will leak memory"]
882883
#[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
883884
pub fn into_raw_parts(self) -> (*mut T, usize, usize) {
884885
let mut me = ManuallyDrop::new(self);
@@ -922,6 +923,7 @@ impl<T, A: Allocator> Vec<T, A> {
922923
/// };
923924
/// assert_eq!(rebuilt, [4294967295, 0, 1]);
924925
/// ```
926+
#[must_use = "losing the pointer will leak memory"]
925927
#[unstable(feature = "allocator_api", issue = "32838")]
926928
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
927929
pub fn into_raw_parts_with_alloc(self) -> (*mut T, usize, usize, A) {

0 commit comments

Comments
 (0)