File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- #![ feature( allocator_api) ]
1+ #![ cfg_attr( feature = "alloc" , feature( allocator_api) ) ]
2+
23use core:: {
34 cell:: Cell ,
45 convert:: Infallible ,
Original file line number Diff line number Diff line change 1- #![ feature( allocator_api) ]
1+ #![ cfg_attr( feature = "alloc" , feature( allocator_api) ) ]
2+
23use core:: {
34 cell:: { Cell , UnsafeCell } ,
45 marker:: PhantomPinned ,
@@ -161,8 +162,12 @@ impl WaitEntry {
161162 }
162163}
163164
165+ #[ cfg( not( feature = "alloc" ) ) ]
166+ fn main ( ) { }
167+
164168#[ allow( dead_code) ]
165169#[ cfg_attr( test, test) ]
170+ #[ cfg( feature = "alloc" ) ]
166171fn main ( ) {
167172 let mtx: Pin < Arc < CMutex < usize > > > = Arc :: pin_init ( CMutex :: new ( 0 ) ) . unwrap ( ) ;
168173 let mut handles = vec ! [ ] ;
Original file line number Diff line number Diff line change 11// inspired by https://github.com/nbdd0121/pin-init/blob/trunk/examples/pthread_mutex.rs
2- #![ feature( allocator_api) ]
2+ #![ cfg_attr ( feature = "alloc" , feature ( allocator_api) ) ]
33#[ cfg( not( windows) ) ]
44mod pthread_mtx {
5+ #[ cfg( feature = "alloc" ) ]
6+ use core:: alloc:: AllocError ;
57 use core:: {
6- alloc:: AllocError ,
78 cell:: UnsafeCell ,
89 marker:: PhantomPinned ,
910 mem:: MaybeUninit ,
@@ -45,6 +46,8 @@ mod pthread_mtx {
4546 match e { }
4647 }
4748 }
49+
50+ #[ cfg( feature = "alloc" ) ]
4851 impl From < AllocError > for Error {
4952 fn from ( _: AllocError ) -> Self {
5053 Self :: Alloc
@@ -129,7 +132,7 @@ mod pthread_mtx {
129132
130133#[ cfg_attr( test, test) ]
131134fn main ( ) {
132- #[ cfg( not( windows) ) ]
135+ #[ cfg( all ( feature = "alloc" , not( windows) ) ) ]
133136 {
134137 use core:: pin:: Pin ;
135138 use pinned_init:: * ;
Original file line number Diff line number Diff line change 1- #![ feature( allocator_api) ]
1+ #![ cfg_attr ( feature = "alloc" , feature ( allocator_api) ) ]
22
33use core:: {
44 cell:: { Cell , UnsafeCell } ,
@@ -77,6 +77,10 @@ unsafe impl PinInit<CMutex<usize>> for CountInit {
7777
7878pub static COUNT : StaticInit < CMutex < usize > , CountInit > = StaticInit :: new ( CountInit ) ;
7979
80+ #[ cfg( not( feature = "alloc" ) ) ]
81+ fn main ( ) { }
82+
83+ #[ cfg( feature = "alloc" ) ]
8084fn main ( ) {
8185 let mtx: Pin < Arc < CMutex < usize > > > = Arc :: pin_init ( CMutex :: new ( 0 ) ) . unwrap ( ) ;
8286 let mut handles = vec ! [ ] ;
Original file line number Diff line number Diff line change 1- #![ feature( allocator_api) ]
1+ #![ cfg_attr ( feature = "alloc" , feature ( allocator_api) ) ]
22
3- use core:: { alloc:: AllocError , convert:: Infallible } ;
3+ #[ cfg( feature = "alloc" ) ]
4+ use core:: alloc:: AllocError ;
5+
6+ use core:: convert:: Infallible ;
47use pinned_init:: * ;
58use std:: sync:: Arc ;
69
710#[ path = "./ring_buf.rs" ]
811mod ring_buf;
912use ring_buf:: * ;
1013
11- #[ cfg( all( not( miri) , not( NO_ALLOC_FAIL_TESTS ) , not( target_os = "macos" ) ) ) ]
14+ #[ cfg( all(
15+ feature = "alloc" ,
16+ not( miri) ,
17+ not( NO_ALLOC_FAIL_TESTS ) ,
18+ not( target_os = "macos" )
19+ ) ) ]
1220#[ test]
1321fn too_big_pinned ( ) {
1422 // should be too big with current hardware.
@@ -23,7 +31,12 @@ fn too_big_pinned() {
2331 ) ) ;
2432}
2533
26- #[ cfg( all( not( miri) , not( NO_ALLOC_FAIL_TESTS ) , not( target_os = "macos" ) ) ) ]
34+ #[ cfg( all(
35+ feature = "alloc" ,
36+ not( miri) ,
37+ not( NO_ALLOC_FAIL_TESTS ) ,
38+ not( target_os = "macos" )
39+ ) ) ]
2740#[ test]
2841fn too_big_in_place ( ) {
2942 // should be too big with current hardware.
Original file line number Diff line number Diff line change @@ -192,9 +192,11 @@ fn even_stack() {
192192 assert_eq ! ( val, Err ( ( ) ) ) ;
193193}
194194
195+ #[ cfg( feature = "alloc" ) ]
195196#[ test]
196197fn even_failing ( ) {
197198 assert ! ( matches!( Box :: try_pin_init( EvenU64 :: new2( 3 ) ) , Err ( Error ) ) ) ;
199+ assert ! ( matches!( Box :: try_init( EvenU64 :: new2( 3 ) ) , Err ( Error ) ) ) ;
198200 assert ! ( matches!( Arc :: try_pin_init( EvenU64 :: new2( 5 ) ) , Err ( Error ) ) ) ;
199201 assert ! ( matches!( Box :: try_init( EvenU64 :: new2( 3 ) ) , Err ( Error ) ) ) ;
200202 assert ! ( matches!( Arc :: try_init( EvenU64 :: new2( 5 ) ) , Err ( Error ) ) ) ;
@@ -241,7 +243,7 @@ struct BigStruct {
241243 oth : MaybeUninit < u8 > ,
242244}
243245
244- #[ cfg( not( miri) ) ]
246+ #[ cfg( all ( feature = "alloc" , not( miri) ) ) ]
245247#[ test]
246248fn big_struct ( ) {
247249 let x = Arc :: init ( init ! ( BigStruct {
@@ -256,7 +258,7 @@ fn big_struct() {
256258 println ! ( "{x:?}" ) ;
257259}
258260
259- #[ cfg( not( miri) ) ]
261+ #[ cfg( all ( feature = "alloc" , not( miri) ) ) ]
260262#[ test]
261263fn with_big_struct ( ) {
262264 let buf = Arc :: pin_init ( CMutex :: new ( RingBuffer :: < BigStruct , 64 > :: new ( ) ) ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments