Skip to content

Commit 99848ff

Browse files
committed
Always use an explicit feature for std
1 parent ed9bf13 commit 99848ff

File tree

7 files changed

+24
-35
lines changed

7 files changed

+24
-35
lines changed

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ rust-version = "1.56"
1414
[lib]
1515
bench = false
1616

17-
[build-dependencies]
18-
autocfg = "1"
19-
2017
[dependencies]
2118
serde = { version = "1.0", optional = true, default-features = false }
2219
rayon = { version = "1.4.1", optional = true }
@@ -40,7 +37,7 @@ fxhash = "0.2.1"
4037
serde_derive = "1.0"
4138

4239
[features]
43-
# Force the use of `std`, bypassing target detection.
40+
default = ["std"]
4441
std = []
4542

4643
# for testing only, of course

build.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@
6161
//!
6262
//! ## No Standard Library Targets
6363
//!
64-
//! This crate supports being built without `std`, requiring
65-
//! `alloc` instead. This is enabled automatically when it is detected that
66-
//! `std` is not available. There is no crate feature to enable/disable to
67-
//! trigger this. It can be tested by building for a std-less target.
64+
//! This crate supports being built without `std`, requiring `alloc` instead.
65+
//! This is chosen by disabling the default "std" cargo feature, by adding
66+
//! `default-features = false` to your dependency specification.
6867
//!
6968
//! - Creating maps and sets using [`new`][IndexMap::new] and
70-
//! [`with_capacity`][IndexMap::with_capacity] is unavailable without `std`.
69+
//! [`with_capacity`][IndexMap::with_capacity] is unavailable without `std`.
7170
//! Use methods [`IndexMap::default`][def],
7271
//! [`with_hasher`][IndexMap::with_hasher],
7372
//! [`with_capacity_and_hasher`][IndexMap::with_capacity_and_hasher] instead.
@@ -79,7 +78,7 @@
7978
8079
extern crate alloc;
8180

82-
#[cfg(has_std)]
81+
#[cfg(feature = "std")]
8382
#[macro_use]
8483
extern crate std;
8584

src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(has_std)]
1+
#[cfg(feature = "std")]
22
#[macro_export]
33
/// Create an `IndexMap` from a list of key-value pairs
44
///
@@ -35,7 +35,7 @@ macro_rules! indexmap {
3535
};
3636
}
3737

38-
#[cfg(has_std)]
38+
#[cfg(feature = "std")]
3939
#[macro_export]
4040
/// Create an `IndexSet` from a list of values
4141
///

src/map.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use ::core::iter::{FromIterator, FusedIterator};
1616
use ::core::ops::{Index, IndexMut, RangeBounds};
1717
use ::core::slice::{Iter as SliceIter, IterMut as SliceIterMut};
1818

19-
#[cfg(has_std)]
19+
#[cfg(feature = "std")]
2020
use std::collections::hash_map::RandomState;
2121

2222
use self::core::IndexMapCore;
@@ -67,12 +67,12 @@ pub use self::core::{Entry, OccupiedEntry, VacantEntry};
6767
/// assert_eq!(letters[&'u'], 1);
6868
/// assert_eq!(letters.get(&'y'), None);
6969
/// ```
70-
#[cfg(has_std)]
70+
#[cfg(feature = "std")]
7171
pub struct IndexMap<K, V, S = RandomState> {
7272
pub(crate) core: IndexMapCore<K, V>,
7373
hash_builder: S,
7474
}
75-
#[cfg(not(has_std))]
75+
#[cfg(not(feature = "std"))]
7676
pub struct IndexMap<K, V, S> {
7777
pub(crate) core: IndexMapCore<K, V>,
7878
hash_builder: S,
@@ -140,7 +140,7 @@ where
140140
}
141141
}
142142

143-
#[cfg(has_std)]
143+
#[cfg(feature = "std")]
144144
impl<K, V> IndexMap<K, V> {
145145
/// Create a new map. (Does not allocate.)
146146
#[inline]
@@ -1391,7 +1391,7 @@ where
13911391
}
13921392
}
13931393

1394-
#[cfg(all(has_std, rustc_1_51))]
1394+
#[cfg(feature = "std")]
13951395
impl<K, V, const N: usize> From<[(K, V); N]> for IndexMap<K, V, RandomState>
13961396
where
13971397
K: Hash + Eq,
@@ -1906,7 +1906,7 @@ mod tests {
19061906
}
19071907

19081908
#[test]
1909-
#[cfg(all(has_std, rustc_1_51))]
1909+
#[cfg(feature = "std")]
19101910
fn from_array() {
19111911
let map = IndexMap::from([(1, 2), (3, 4)]);
19121912
let mut expected = IndexMap::new();

src/set.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[cfg(feature = "rayon")]
44
pub use crate::rayon::set as rayon;
55

6-
#[cfg(has_std)]
6+
#[cfg(feature = "std")]
77
use std::collections::hash_map::RandomState;
88

99
use crate::vec::{self, Vec};
@@ -59,11 +59,11 @@ type Bucket<T> = super::Bucket<T, ()>;
5959
/// assert!(letters.contains(&'u'));
6060
/// assert!(!letters.contains(&'y'));
6161
/// ```
62-
#[cfg(has_std)]
62+
#[cfg(feature = "std")]
6363
pub struct IndexSet<T, S = RandomState> {
6464
pub(crate) map: IndexMap<T, (), S>,
6565
}
66-
#[cfg(not(has_std))]
66+
#[cfg(not(feature = "std"))]
6767
pub struct IndexSet<T, S> {
6868
pub(crate) map: IndexMap<T, (), S>,
6969
}
@@ -124,7 +124,7 @@ where
124124
}
125125
}
126126

127-
#[cfg(has_std)]
127+
#[cfg(feature = "std")]
128128
impl<T> IndexSet<T> {
129129
/// Create a new set. (Does not allocate.)
130130
pub fn new() -> Self {
@@ -888,7 +888,7 @@ where
888888
}
889889
}
890890

891-
#[cfg(all(has_std, rustc_1_51))]
891+
#[cfg(feature = "std")]
892892
impl<T, const N: usize> From<[T; N]> for IndexSet<T, RandomState>
893893
where
894894
T: Eq + Hash,
@@ -1882,7 +1882,7 @@ mod tests {
18821882
}
18831883

18841884
#[test]
1885-
#[cfg(all(has_std, rustc_1_51))]
1885+
#[cfg(feature = "std")]
18861886
fn from_array() {
18871887
let set1 = IndexSet::from([1, 2, 3, 4]);
18881888
let set2: IndexSet<_> = [1, 2, 3, 4].into();

test-nostd/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ version = "0.1.0"
44
publish = false
55
edition = "2021"
66

7-
[dependencies]
8-
indexmap = { path = "..", features = ["serde"] }
7+
[dependencies.indexmap]
8+
path = ".."
9+
default-features = false
10+
features = ["serde"]
911

1012
[dev-dependencies]

0 commit comments

Comments
 (0)