@@ -19,7 +19,7 @@ use core::cmp;
19
19
use core:: fmt;
20
20
use core:: mem;
21
21
use core:: usize;
22
- use core:: ptr:: { self , Unique } ;
22
+ use core:: ptr:: { self , NonNull } ;
23
23
24
24
/// Represents the combination of a starting address and
25
25
/// a total capacity of the returned block.
@@ -895,12 +895,12 @@ pub unsafe trait Alloc {
895
895
/// Clients wishing to abort computation in response to an
896
896
/// allocation error are encouraged to call the allocator's `oom`
897
897
/// method, rather than directly invoking `panic!` or similar.
898
- fn alloc_one < T > ( & mut self ) -> Result < Unique < T > , AllocErr >
898
+ fn alloc_one < T > ( & mut self ) -> Result < NonNull < T > , AllocErr >
899
899
where Self : Sized
900
900
{
901
901
let k = Layout :: new :: < T > ( ) ;
902
902
if k. size ( ) > 0 {
903
- unsafe { self . alloc ( k) . map ( |p| Unique :: new_unchecked ( p as * mut T ) ) }
903
+ unsafe { self . alloc ( k) . map ( |p| NonNull :: new_unchecked ( p as * mut T ) ) }
904
904
} else {
905
905
Err ( AllocErr :: invalid_input ( "zero-sized type invalid for alloc_one" ) )
906
906
}
@@ -923,7 +923,7 @@ pub unsafe trait Alloc {
923
923
/// * `ptr` must denote a block of memory currently allocated via this allocator
924
924
///
925
925
/// * the layout of `T` must *fit* that block of memory.
926
- unsafe fn dealloc_one < T > ( & mut self , ptr : Unique < T > )
926
+ unsafe fn dealloc_one < T > ( & mut self , ptr : NonNull < T > )
927
927
where Self : Sized
928
928
{
929
929
let raw_ptr = ptr. as_ptr ( ) as * mut u8 ;
@@ -963,15 +963,15 @@ pub unsafe trait Alloc {
963
963
/// Clients wishing to abort computation in response to an
964
964
/// allocation error are encouraged to call the allocator's `oom`
965
965
/// method, rather than directly invoking `panic!` or similar.
966
- fn alloc_array < T > ( & mut self , n : usize ) -> Result < Unique < T > , AllocErr >
966
+ fn alloc_array < T > ( & mut self , n : usize ) -> Result < NonNull < T > , AllocErr >
967
967
where Self : Sized
968
968
{
969
969
match Layout :: array :: < T > ( n) {
970
970
Some ( ref layout) if layout. size ( ) > 0 => {
971
971
unsafe {
972
972
self . alloc ( layout. clone ( ) )
973
973
. map ( |p| {
974
- Unique :: new_unchecked ( p as * mut T )
974
+ NonNull :: new_unchecked ( p as * mut T )
975
975
} )
976
976
}
977
977
}
@@ -1012,15 +1012,15 @@ pub unsafe trait Alloc {
1012
1012
/// reallocation error are encouraged to call the allocator's `oom`
1013
1013
/// method, rather than directly invoking `panic!` or similar.
1014
1014
unsafe fn realloc_array < T > ( & mut self ,
1015
- ptr : Unique < T > ,
1015
+ ptr : NonNull < T > ,
1016
1016
n_old : usize ,
1017
- n_new : usize ) -> Result < Unique < T > , AllocErr >
1017
+ n_new : usize ) -> Result < NonNull < T > , AllocErr >
1018
1018
where Self : Sized
1019
1019
{
1020
1020
match ( Layout :: array :: < T > ( n_old) , Layout :: array :: < T > ( n_new) , ptr. as_ptr ( ) ) {
1021
1021
( Some ( ref k_old) , Some ( ref k_new) , ptr) if k_old. size ( ) > 0 && k_new. size ( ) > 0 => {
1022
1022
self . realloc ( ptr as * mut u8 , k_old. clone ( ) , k_new. clone ( ) )
1023
- . map ( |p|Unique :: new_unchecked ( p as * mut T ) )
1023
+ . map ( |p| NonNull :: new_unchecked ( p as * mut T ) )
1024
1024
}
1025
1025
_ => {
1026
1026
Err ( AllocErr :: invalid_input ( "invalid layout for realloc_array" ) )
@@ -1048,7 +1048,7 @@ pub unsafe trait Alloc {
1048
1048
/// constraints.
1049
1049
///
1050
1050
/// Always returns `Err` on arithmetic overflow.
1051
- unsafe fn dealloc_array < T > ( & mut self , ptr : Unique < T > , n : usize ) -> Result < ( ) , AllocErr >
1051
+ unsafe fn dealloc_array < T > ( & mut self , ptr : NonNull < T > , n : usize ) -> Result < ( ) , AllocErr >
1052
1052
where Self : Sized
1053
1053
{
1054
1054
let raw_ptr = ptr. as_ptr ( ) as * mut u8 ;
0 commit comments