Skip to content

Commit f2a6bfb

Browse files
committed
make std feature conflict with hashbrown in compile error and gate free_list_allocator by feature
1 parent 4c45a01 commit f2a6bfb

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

src/allocator/dedicated_block_allocator/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,20 @@ impl SubAllocator for DedicatedBlockAllocator {
101101
) {
102102
let empty = "".to_string();
103103
let name = self.name.as_ref().unwrap_or(&empty);
104-
105-
let backtrace_info = if cfg!(feature = "std") {
106-
format!(
104+
let backtrace_info;
105+
#[cfg(feature = "std")]
106+
{
107+
backtrace_info = format!(
107108
r#"
108-
backtrace: {}
109-
"#,
109+
backtrace: {}
110+
"#,
110111
self.backtrace
111112
)
112-
} else {
113-
"".to_owned()
114-
};
113+
}
114+
#[cfg(not(feature = "std"))]
115+
{
116+
backtrace_info = "".to_owned()
117+
}
115118

116119
log!(
117120
log_level,

src/allocator/free_list_allocator/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ use alloc::{
55
string::{String, ToString},
66
vec::Vec,
77
};
8-
#[cfg(all(feature = "std", not(feature = "hashbrown")))]
9-
use std::collections::{HashMap, HashSet};
8+
109
#[cfg(feature = "std")]
11-
use std::{backtrace::Backtrace, sync::Arc};
10+
use std::{
11+
backtrace::Backtrace,
12+
collections::{HashMap, HashSet},
13+
sync::Arc,
14+
};
1215

13-
#[cfg(all(not(feature = "std"), feature = "hashbrown"))]
16+
#[cfg(feature = "hashbrown")]
1417
use hashbrown::{HashMap, HashSet};
1518
use log::{log, Level};
1619

@@ -377,16 +380,20 @@ impl SubAllocator for FreeListAllocator {
377380
}
378381
let empty = "".to_string();
379382
let name = chunk.name.as_ref().unwrap_or(&empty);
380-
let backtrace_info = if cfg!(feature = "std") {
381-
format!(
383+
let backtrace_info;
384+
#[cfg(feature = "std")]
385+
{
386+
backtrace_info = format!(
382387
r#"
383388
backtrace: {}
384389
"#,
385390
chunk.backtrace
386391
)
387-
} else {
388-
"".to_owned()
389-
};
392+
}
393+
#[cfg(not(feature = "std"))]
394+
{
395+
backtrace_info = "".to_owned()
396+
}
390397
log!(
391398
log_level,
392399
r#"leak detected: {{

src/allocator/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use crate::result::*;
1010
pub(crate) mod dedicated_block_allocator;
1111
pub(crate) use dedicated_block_allocator::DedicatedBlockAllocator;
1212

13+
#[cfg(any(feature = "std", feature = "hashbrown"))]
1314
pub(crate) mod free_list_allocator;
15+
#[cfg(any(feature = "std", feature = "hashbrown"))]
1416
pub(crate) use free_list_allocator::FreeListAllocator;
1517

1618
#[derive(PartialEq, Copy, Clone, Debug)]

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@
222222
#[macro_use]
223223
extern crate alloc;
224224

225-
#[cfg(all(not(feature = "std"), not(feature = "hashbrown")))]
226-
compile_error!("\"hashbrown\" feature should be enabled in \"no_std\" environment.");
225+
#[cfg(all(feature = "std", feature = "hashbrown"))]
226+
compile_error!("\"hashbrown\" feature should not be enabled in \"std\" environment.");
227227

228228
#[cfg(all(not(feature = "std"), feature = "visualizer"))]
229229
compile_error!("Cannot enable \"visualizer\" feature in \"no_std\" environment.");

0 commit comments

Comments
 (0)