@@ -272,7 +272,9 @@ mod neighbors;
272
272
mod size_classes;
273
273
274
274
use const_init:: ConstInit ;
275
- use core:: alloc:: { Alloc , AllocErr , GlobalAlloc , Layout } ;
275
+ #[ cfg( feature = "nightly" ) ]
276
+ use core:: alloc:: Alloc ;
277
+ use core:: alloc:: { AllocErr , GlobalAlloc , Layout } ;
276
278
use core:: cell:: Cell ;
277
279
use core:: cmp;
278
280
use core:: marker:: Sync ;
@@ -1069,13 +1071,8 @@ impl<'a> WeeAlloc<'a> {
1069
1071
result
1070
1072
} )
1071
1073
}
1072
- }
1073
1074
1074
- unsafe impl < ' a , ' b > Alloc for & ' b WeeAlloc < ' a >
1075
- where
1076
- ' a : ' b ,
1077
- {
1078
- unsafe fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
1075
+ unsafe fn alloc_impl ( & self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
1079
1076
let size = Bytes ( layout. size ( ) ) ;
1080
1077
let align = if layout. align ( ) == 0 {
1081
1078
Bytes ( 1 )
@@ -1098,7 +1095,7 @@ where
1098
1095
} )
1099
1096
}
1100
1097
1101
- unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
1098
+ unsafe fn dealloc_impl ( & self , ptr : NonNull < u8 > , layout : Layout ) {
1102
1099
let size = Bytes ( layout. size ( ) ) ;
1103
1100
if size. 0 == 0 {
1104
1101
return ;
@@ -1187,19 +1184,31 @@ where
1187
1184
}
1188
1185
}
1189
1186
1187
+ #[ cfg( feature = "nightly" ) ]
1188
+ unsafe impl < ' a , ' b > Alloc for & ' b WeeAlloc < ' a >
1189
+ where
1190
+ ' a : ' b ,
1191
+ {
1192
+ unsafe fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
1193
+ self . alloc_impl ( layout)
1194
+ }
1195
+
1196
+ unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
1197
+ self . dealloc_impl ( ptr, layout)
1198
+ }
1199
+ }
1200
+
1190
1201
unsafe impl GlobalAlloc for WeeAlloc < ' static > {
1191
1202
unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
1192
- let mut me = self ;
1193
- match Alloc :: alloc ( & mut me, layout) {
1203
+ match self . alloc_impl ( layout) {
1194
1204
Ok ( ptr) => ptr. as_ptr ( ) ,
1195
1205
Err ( AllocErr ) => 0 as * mut u8 ,
1196
1206
}
1197
1207
}
1198
1208
1199
1209
unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
1200
1210
if let Some ( ptr) = NonNull :: new ( ptr) {
1201
- let mut me = self ;
1202
- Alloc :: dealloc ( & mut me, ptr, layout) ;
1211
+ self . dealloc_impl ( ptr, layout) ;
1203
1212
}
1204
1213
}
1205
1214
}
0 commit comments