@@ -272,7 +272,9 @@ mod neighbors;
272272mod size_classes;
273273
274274use 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 } ;
276278use core:: cell:: Cell ;
277279use core:: cmp;
278280use core:: marker:: Sync ;
@@ -1069,13 +1071,8 @@ impl<'a> WeeAlloc<'a> {
10691071 result
10701072 } )
10711073 }
1072- }
10731074
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 > {
10791076 let size = Bytes ( layout. size ( ) ) ;
10801077 let align = if layout. align ( ) == 0 {
10811078 Bytes ( 1 )
@@ -1098,7 +1095,7 @@ where
10981095 } )
10991096 }
11001097
1101- unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
1098+ unsafe fn dealloc_impl ( & self , ptr : NonNull < u8 > , layout : Layout ) {
11021099 let size = Bytes ( layout. size ( ) ) ;
11031100 if size. 0 == 0 {
11041101 return ;
@@ -1187,19 +1184,31 @@ where
11871184 }
11881185}
11891186
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+
11901201unsafe impl GlobalAlloc for WeeAlloc < ' static > {
11911202 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) {
11941204 Ok ( ptr) => ptr. as_ptr ( ) ,
11951205 Err ( AllocErr ) => 0 as * mut u8 ,
11961206 }
11971207 }
11981208
11991209 unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
12001210 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) ;
12031212 }
12041213 }
12051214}
0 commit comments