@@ -68,7 +68,7 @@ use core::marker::{self, Unsize};
68
68
use core:: mem;
69
69
use core:: ops:: { CoerceUnsized , Deref , DerefMut , Generator , GeneratorState } ;
70
70
use core:: ops:: { BoxPlace , Boxed , InPlace , Place , Placer } ;
71
- use core:: ptr:: { self , Unique } ;
71
+ use core:: ptr:: { self , NonNull , Unique } ;
72
72
use core:: convert:: From ;
73
73
use str:: from_boxed_utf8_unchecked;
74
74
@@ -269,38 +269,38 @@ impl<T: ?Sized> Box<T> {
269
269
#[ stable( feature = "box_raw" , since = "1.4.0" ) ]
270
270
#[ inline]
271
271
pub unsafe fn from_raw ( raw : * mut T ) -> Self {
272
- Box :: from_unique ( Unique :: new_unchecked ( raw) )
272
+ Box ( Unique :: new_unchecked ( raw) )
273
273
}
274
274
275
- /// Constructs a `Box` from a `Unique <T>` pointer.
275
+ /// Constructs a `Box` from a `NonNull <T>` pointer.
276
276
///
277
277
/// After calling this function, the memory is owned by a `Box` and `T` can
278
278
/// then be destroyed and released upon drop.
279
279
///
280
280
/// # Safety
281
281
///
282
- /// A `Unique <T>` can be safely created via [`Unique ::new`] and thus doesn't
282
+ /// A `NonNull <T>` can be safely created via [`NonNull ::new`] and thus doesn't
283
283
/// necessarily own the data pointed to nor is the data guaranteed to live
284
284
/// as long as the pointer.
285
285
///
286
- /// [`Unique ::new`]: ../../core/ptr/struct.Unique .html#method.new
286
+ /// [`NonNull ::new`]: ../../core/ptr/struct.NonNull .html#method.new
287
287
///
288
288
/// # Examples
289
289
///
290
290
/// ```
291
- /// #![feature(unique )]
291
+ /// #![feature(nonnull )]
292
292
///
293
293
/// fn main() {
294
294
/// let x = Box::new(5);
295
- /// let ptr = Box::into_unique (x);
296
- /// let x = unsafe { Box::from_unique (ptr) };
295
+ /// let ptr = Box::into_nonnull_raw (x);
296
+ /// let x = unsafe { Box::from_nonnull_raw (ptr) };
297
297
/// }
298
298
/// ```
299
- #[ unstable( feature = "unique " , reason = "needs an RFC to flesh out design" ,
299
+ #[ unstable( feature = "nonnull " , reason = "needs an RFC to flesh out design" ,
300
300
issue = "27730" ) ]
301
301
#[ inline]
302
- pub unsafe fn from_unique ( u : Unique < T > ) -> Self {
303
- Box ( u)
302
+ pub unsafe fn from_nonnull_raw ( u : NonNull < T > ) -> Self {
303
+ Box ( u. into ( ) )
304
304
}
305
305
306
306
/// Consumes the `Box`, returning the wrapped raw pointer.
@@ -326,41 +326,48 @@ impl<T: ?Sized> Box<T> {
326
326
#[ stable( feature = "box_raw" , since = "1.4.0" ) ]
327
327
#[ inline]
328
328
pub fn into_raw ( b : Box < T > ) -> * mut T {
329
- Box :: into_unique ( b) . as_ptr ( )
329
+ Box :: into_nonnull_raw ( b) . as_ptr ( )
330
330
}
331
331
332
- /// Consumes the `Box`, returning the wrapped pointer as `Unique <T>`.
332
+ /// Consumes the `Box`, returning the wrapped pointer as `NonNull <T>`.
333
333
///
334
334
/// After calling this function, the caller is responsible for the
335
335
/// memory previously managed by the `Box`. In particular, the
336
336
/// caller should properly destroy `T` and release the memory. The
337
- /// proper way to do so is to either convert the `Unique <T>` pointer:
337
+ /// proper way to do so is to either convert the `NonNull <T>` pointer:
338
338
///
339
- /// - Into a `Box` with the [`Box::from_unique `] function.
339
+ /// - Into a `Box` with the [`Box::from_nonnull_raw `] function.
340
340
///
341
341
/// - Into a raw pointer and back into a `Box` with the [`Box::from_raw`]
342
342
/// function.
343
343
///
344
344
/// Note: this is an associated function, which means that you have
345
- /// to call it as `Box::into_unique(b)` instead of `b.into_unique()`. This
345
+ /// to call it as `Box::into_nonnull_raw(b)`
346
+ /// instead of `b.into_nonnull_raw()`. This
346
347
/// is so that there is no conflict with a method on the inner type.
347
348
///
348
- /// [`Box::from_unique `]: struct.Box.html#method.from_unique
349
+ /// [`Box::from_nonnull_raw `]: struct.Box.html#method.from_nonnull_raw
349
350
/// [`Box::from_raw`]: struct.Box.html#method.from_raw
350
351
///
351
352
/// # Examples
352
353
///
353
354
/// ```
354
- /// #![feature(unique )]
355
+ /// #![feature(nonnull )]
355
356
///
356
357
/// fn main() {
357
358
/// let x = Box::new(5);
358
- /// let ptr = Box::into_unique (x);
359
+ /// let ptr = Box::into_nonnull_raw (x);
359
360
/// }
360
361
/// ```
361
- #[ unstable( feature = "unique " , reason = "needs an RFC to flesh out design" ,
362
+ #[ unstable( feature = "nonnull " , reason = "needs an RFC to flesh out design" ,
362
363
issue = "27730" ) ]
363
364
#[ inline]
365
+ pub fn into_nonnull_raw ( b : Box < T > ) -> NonNull < T > {
366
+ Box :: into_unique ( b) . into ( )
367
+ }
368
+
369
+ #[ unstable( feature = "ptr_internals" , issue = "0" , reason = "use into_nonnull_raw instead" ) ]
370
+ #[ inline]
364
371
pub fn into_unique ( b : Box < T > ) -> Unique < T > {
365
372
let unique = b. 0 ;
366
373
mem:: forget ( b) ;
0 commit comments