Skip to content

Commit d286b7e

Browse files
bonziniBennoLossin
authored andcommitted
allow feature = "std" when checking for presence of memory allocation
Memory allocation (i.e. the Box and Arc) can be present even without the allocator_api. Allow feature = "std" when the code is simply checking for the existence of Box and Arc, and the allocator API is not used. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f794151 commit d286b7e

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

examples/mutex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ impl WaitEntry {
162162
}
163163
}
164164

165-
#[cfg(not(feature = "alloc"))]
165+
#[cfg(not(any(feature = "std", feature = "alloc")))]
166166
fn main() {}
167167

168168
#[allow(dead_code)]
169169
#[cfg_attr(test, test)]
170-
#[cfg(feature = "alloc")]
170+
#[cfg(any(feature = "std", feature = "alloc"))]
171171
fn main() {
172172
let mtx: Pin<Arc<CMutex<usize>>> = Arc::pin_init(CMutex::new(0)).unwrap();
173173
let mut handles = vec![];

examples/pthread_mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ mod pthread_mtx {
132132

133133
#[cfg_attr(test, test)]
134134
fn main() {
135-
#[cfg(all(feature = "alloc", not(windows)))]
135+
#[cfg(all(any(feature = "std", feature = "alloc"), not(windows)))]
136136
{
137137
use core::pin::Pin;
138138
use pinned_init::*;

examples/static_init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ unsafe impl PinInit<CMutex<usize>> for CountInit {
7777

7878
pub static COUNT: StaticInit<CMutex<usize>, CountInit> = StaticInit::new(CountInit);
7979

80-
#[cfg(not(feature = "alloc"))]
80+
#[cfg(not(any(feature = "std", feature = "alloc")))]
8181
fn main() {}
8282

83-
#[cfg(feature = "alloc")]
83+
#[cfg(any(feature = "std", feature = "alloc"))]
8484
fn main() {
8585
let mtx: Pin<Arc<CMutex<usize>>> = Arc::pin_init(CMutex::new(0)).unwrap();
8686
let mut handles = vec![];

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ pub trait InPlaceWrite<T> {
12741274
fn write_pin_init<E>(self, init: impl PinInit<T, E>) -> Result<Pin<Self::Initialized>, E>;
12751275
}
12761276

1277-
#[cfg(feature = "alloc")]
1277+
#[cfg(any(feature = "std", feature = "alloc"))]
12781278
impl<T> InPlaceWrite<T> for Box<MaybeUninit<T>> {
12791279
type Initialized = Box<T>;
12801280

@@ -1405,7 +1405,7 @@ impl_zeroable! {
14051405
//
14061406
// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
14071407
{<T: ?Sized>} Option<NonNull<T>>,
1408-
#[cfg(feature = "alloc")]
1408+
#[cfg(any(feature = "std", feature = "alloc"))]
14091409
{<T: ?Sized>} Option<Box<T>>,
14101410

14111411
// SAFETY: `null` pointer is valid.

tests/ring_buf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn even_stack() {
192192
assert_eq!(val, Err(()));
193193
}
194194

195-
#[cfg(feature = "alloc")]
195+
#[cfg(any(feature = "std", feature = "alloc"))]
196196
#[test]
197197
fn even_failing() {
198198
assert!(matches!(Box::try_pin_init(EvenU64::new2(3)), Err(Error)));
@@ -243,7 +243,7 @@ struct BigStruct {
243243
oth: MaybeUninit<u8>,
244244
}
245245

246-
#[cfg(all(feature = "alloc", not(miri)))]
246+
#[cfg(all(any(feature = "std", feature = "alloc"), not(miri)))]
247247
#[test]
248248
fn big_struct() {
249249
let x = Arc::init(init!(BigStruct {
@@ -258,7 +258,7 @@ fn big_struct() {
258258
println!("{x:?}");
259259
}
260260

261-
#[cfg(all(feature = "alloc", not(miri)))]
261+
#[cfg(all(any(feature = "std", feature = "alloc"), not(miri)))]
262262
#[test]
263263
fn with_big_struct() {
264264
let buf = Arc::pin_init(CMutex::new(RingBuffer::<BigStruct, 64>::new())).unwrap();

0 commit comments

Comments
 (0)