File tree Expand file tree Collapse file tree 6 files changed +40
-12
lines changed Expand file tree Collapse file tree 6 files changed +40
-12
lines changed Original file line number Diff line number Diff line change 1
- #![ feature( allocator_api) ]
1
+ #![ cfg_attr( feature = "alloc" , feature( allocator_api) ) ]
2
+
2
3
use core:: {
3
4
cell:: Cell ,
4
5
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
+
2
3
use core:: {
3
4
cell:: { Cell , UnsafeCell } ,
4
5
marker:: PhantomPinned ,
@@ -161,8 +162,12 @@ impl WaitEntry {
161
162
}
162
163
}
163
164
165
+ #[ cfg( not( feature = "alloc" ) ) ]
166
+ fn main ( ) { }
167
+
164
168
#[ allow( dead_code) ]
165
169
#[ cfg_attr( test, test) ]
170
+ #[ cfg( feature = "alloc" ) ]
166
171
fn main ( ) {
167
172
let mtx: Pin < Arc < CMutex < usize > > > = Arc :: pin_init ( CMutex :: new ( 0 ) ) . unwrap ( ) ;
168
173
let mut handles = vec ! [ ] ;
Original file line number Diff line number Diff line change 1
1
// 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) ) ]
3
3
#[ cfg( not( windows) ) ]
4
4
mod pthread_mtx {
5
+ #[ cfg( feature = "alloc" ) ]
6
+ use core:: alloc:: AllocError ;
5
7
use core:: {
6
- alloc:: AllocError ,
7
8
cell:: UnsafeCell ,
8
9
marker:: PhantomPinned ,
9
10
mem:: MaybeUninit ,
@@ -45,6 +46,8 @@ mod pthread_mtx {
45
46
match e { }
46
47
}
47
48
}
49
+
50
+ #[ cfg( feature = "alloc" ) ]
48
51
impl From < AllocError > for Error {
49
52
fn from ( _: AllocError ) -> Self {
50
53
Self :: Alloc
@@ -129,7 +132,7 @@ mod pthread_mtx {
129
132
130
133
#[ cfg_attr( test, test) ]
131
134
fn main ( ) {
132
- #[ cfg( not( windows) ) ]
135
+ #[ cfg( all ( feature = "alloc" , not( windows) ) ) ]
133
136
{
134
137
use core:: pin:: Pin ;
135
138
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) ) ]
2
2
3
3
use core:: {
4
4
cell:: { Cell , UnsafeCell } ,
@@ -77,6 +77,10 @@ unsafe impl PinInit<CMutex<usize>> for CountInit {
77
77
78
78
pub static COUNT : StaticInit < CMutex < usize > , CountInit > = StaticInit :: new ( CountInit ) ;
79
79
80
+ #[ cfg( not( feature = "alloc" ) ) ]
81
+ fn main ( ) { }
82
+
83
+ #[ cfg( feature = "alloc" ) ]
80
84
fn main ( ) {
81
85
let mtx: Pin < Arc < CMutex < usize > > > = Arc :: pin_init ( CMutex :: new ( 0 ) ) . unwrap ( ) ;
82
86
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) ) ]
2
2
3
- use core:: { alloc:: AllocError , convert:: Infallible } ;
3
+ #[ cfg( feature = "alloc" ) ]
4
+ use core:: alloc:: AllocError ;
5
+
6
+ use core:: convert:: Infallible ;
4
7
use pinned_init:: * ;
5
8
use std:: sync:: Arc ;
6
9
7
10
#[ path = "./ring_buf.rs" ]
8
11
mod ring_buf;
9
12
use ring_buf:: * ;
10
13
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
+ ) ) ]
12
20
#[ test]
13
21
fn too_big_pinned ( ) {
14
22
// should be too big with current hardware.
@@ -23,7 +31,12 @@ fn too_big_pinned() {
23
31
) ) ;
24
32
}
25
33
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
+ ) ) ]
27
40
#[ test]
28
41
fn too_big_in_place ( ) {
29
42
// should be too big with current hardware.
Original file line number Diff line number Diff line change @@ -192,9 +192,11 @@ fn even_stack() {
192
192
assert_eq ! ( val, Err ( ( ) ) ) ;
193
193
}
194
194
195
+ #[ cfg( feature = "alloc" ) ]
195
196
#[ test]
196
197
fn even_failing ( ) {
197
198
assert ! ( matches!( Box :: try_pin_init( EvenU64 :: new2( 3 ) ) , Err ( Error ) ) ) ;
199
+ assert ! ( matches!( Box :: try_init( EvenU64 :: new2( 3 ) ) , Err ( Error ) ) ) ;
198
200
assert ! ( matches!( Arc :: try_pin_init( EvenU64 :: new2( 5 ) ) , Err ( Error ) ) ) ;
199
201
assert ! ( matches!( Box :: try_init( EvenU64 :: new2( 3 ) ) , Err ( Error ) ) ) ;
200
202
assert ! ( matches!( Arc :: try_init( EvenU64 :: new2( 5 ) ) , Err ( Error ) ) ) ;
@@ -241,7 +243,7 @@ struct BigStruct {
241
243
oth : MaybeUninit < u8 > ,
242
244
}
243
245
244
- #[ cfg( not( miri) ) ]
246
+ #[ cfg( all ( feature = "alloc" , not( miri) ) ) ]
245
247
#[ test]
246
248
fn big_struct ( ) {
247
249
let x = Arc :: init ( init ! ( BigStruct {
@@ -256,7 +258,7 @@ fn big_struct() {
256
258
println ! ( "{x:?}" ) ;
257
259
}
258
260
259
- #[ cfg( not( miri) ) ]
261
+ #[ cfg( all ( feature = "alloc" , not( miri) ) ) ]
260
262
#[ test]
261
263
fn with_big_struct ( ) {
262
264
let buf = Arc :: pin_init ( CMutex :: new ( RingBuffer :: < BigStruct , 64 > :: new ( ) ) ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments