Skip to content

Commit c42e9de

Browse files
committed
Always use #![nostd] and make std:: explicit
The fake `std` module we had in our root will make things difficult when we switch to 2018, where there's a path difference between `std::` for the crate and `crate::std::` for our module.
1 parent d293267 commit c42e9de

File tree

12 files changed

+57
-74
lines changed

12 files changed

+57
-74
lines changed

src/equivalent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::borrow::Borrow;
1+
use core::borrow::Borrow;
22

33
/// Key equivalence trait.
44
///

src/lib.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// We *mostly* avoid unsafe code, but `map::core::raw` allows it to use `RawTable` buckets.
22
#![deny(unsafe_code)]
33
#![doc(html_root_url = "https://docs.rs/indexmap/1/")]
4-
#![cfg_attr(not(has_std), no_std)]
4+
#![no_std]
55

66
//! [`IndexMap`] is a hash table where the iteration order of the key-value
77
//! pairs is independent of the hash values of the keys.
@@ -82,22 +82,17 @@
8282
#[cfg(not(has_std))]
8383
extern crate alloc;
8484

85+
#[cfg(has_std)]
86+
#[macro_use]
87+
extern crate std;
88+
8589
extern crate hashbrown;
8690

8791
#[cfg(not(has_std))]
88-
pub(crate) mod std {
89-
pub use core::*;
90-
pub mod alloc {
91-
pub use alloc::*;
92-
}
93-
pub mod collections {
94-
pub use alloc::collections::*;
95-
}
96-
pub use alloc::vec;
97-
}
92+
use alloc::vec::{self, Vec};
9893

99-
#[cfg(not(has_std))]
100-
use std::vec::Vec;
94+
#[cfg(has_std)]
95+
use std::vec::{self, Vec};
10196

10297
#[macro_use]
10398
mod macros;

src/map.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@
33
44
mod core;
55

6-
#[cfg(not(has_std))]
7-
use std::vec::Vec;
8-
96
pub use mutable_keys::MutableKeys;
107

118
#[cfg(feature = "rayon")]
129
pub use rayon::map as rayon;
1310

14-
use std::hash::BuildHasher;
15-
use std::hash::Hash;
16-
use std::hash::Hasher;
17-
use std::iter::FromIterator;
18-
use std::ops::RangeFull;
11+
use core::cmp::Ordering;
12+
use core::fmt;
13+
use core::hash::{BuildHasher, Hash, Hasher};
14+
use core::iter::FromIterator;
15+
use core::ops::{Index, IndexMut, RangeFull};
16+
use core::slice::{Iter as SliceIter, IterMut as SliceIterMut};
17+
use vec::{self, Vec};
1918

2019
#[cfg(has_std)]
2120
use std::collections::hash_map::RandomState;
2221

23-
use std::cmp::Ordering;
24-
use std::fmt;
25-
2622
use self::core::IndexMapCore;
2723
use equivalent::Equivalent;
2824
use util::third;
@@ -720,10 +716,6 @@ impl<K, V, S> IndexMap<K, V, S> {
720716
}
721717
}
722718

723-
use std::slice::Iter as SliceIter;
724-
use std::slice::IterMut as SliceIterMut;
725-
use std::vec::IntoIter as VecIntoIter;
726-
727719
/// An iterator over the keys of a `IndexMap`.
728720
///
729721
/// This `struct` is created by the [`keys`] method on [`IndexMap`]. See its
@@ -922,7 +914,7 @@ impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {
922914
/// [`into_iter`]: struct.IndexMap.html#method.into_iter
923915
/// [`IndexMap`]: struct.IndexMap.html
924916
pub struct IntoIter<K, V> {
925-
pub(crate) iter: VecIntoIter<Bucket<K, V>>,
917+
pub(crate) iter: vec::IntoIter<Bucket<K, V>>,
926918
}
927919

928920
impl<K, V> Iterator for IntoIter<K, V> {
@@ -962,7 +954,7 @@ where
962954
K: 'a,
963955
V: 'a,
964956
{
965-
pub(crate) iter: ::std::vec::Drain<'a, Bucket<K, V>>,
957+
pub(crate) iter: vec::Drain<'a, Bucket<K, V>>,
966958
}
967959

968960
impl<'a, K, V> Iterator for Drain<'a, K, V> {
@@ -1013,8 +1005,6 @@ where
10131005
}
10141006
}
10151007

1016-
use std::ops::{Index, IndexMut};
1017-
10181008
impl<'a, K, V, Q: ?Sized, S> Index<&'a Q> for IndexMap<K, V, S>
10191009
where
10201010
Q: Hash + Equivalent<K>,
@@ -1149,6 +1139,7 @@ where
11491139
#[cfg(test)]
11501140
mod tests {
11511141
use super::*;
1142+
use std::string::String;
11521143
use util::enumerate;
11531144

11541145
#[test]
@@ -1405,8 +1396,7 @@ mod tests {
14051396
map_b.swap_remove(&1);
14061397
assert_ne!(map_a, map_b);
14071398

1408-
let map_c: IndexMap<_, String> =
1409-
map_b.into_iter().map(|(k, v)| (k, v.to_owned())).collect();
1399+
let map_c: IndexMap<_, String> = map_b.into_iter().map(|(k, v)| (k, v.into())).collect();
14101400
assert_ne!(map_a, map_c);
14111401
assert_ne!(map_c, map_a);
14121402
}

src/map/core.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99
1010
mod raw;
1111

12-
#[cfg(not(has_std))]
13-
use std::vec::Vec;
14-
1512
use hashbrown::raw::RawTable;
1613

17-
use std::cmp;
18-
use std::fmt;
19-
use std::mem::replace;
20-
use std::ops::RangeFull;
21-
use std::vec::Drain;
14+
use core::cmp;
15+
use core::fmt;
16+
use core::mem::replace;
17+
use core::ops::RangeFull;
18+
use vec::{Drain, Vec};
2219

2320
use equivalent::Equivalent;
2421
use util::enumerate;

src/map/core/raw.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//! mostly in dealing with its bucket "pointers".
44
55
use super::{Entry, Equivalent, HashValue, IndexMapCore, VacantEntry};
6+
use core::fmt;
7+
use core::mem::replace;
68
use hashbrown::raw::RawTable;
7-
use std::fmt;
8-
use std::mem::replace;
99

1010
type RawBucket = hashbrown::raw::Bucket<usize>;
1111

src/mutable_keys.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use std::hash::BuildHasher;
2-
use std::hash::Hash;
1+
use core::hash::{BuildHasher, Hash};
32

43
use super::{Equivalent, IndexMap};
54

src/rayon/map.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use super::collect;
99
use super::rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
1010
use super::rayon::prelude::*;
1111

12-
use std::cmp::Ordering;
13-
use std::fmt;
14-
use std::hash::BuildHasher;
15-
use std::hash::Hash;
12+
use core::cmp::Ordering;
13+
use core::fmt;
14+
use core::hash::{BuildHasher, Hash};
15+
use vec::Vec;
1616

1717
use Bucket;
1818
use Entries;
@@ -398,6 +398,7 @@ where
398398
#[cfg(test)]
399399
mod tests {
400400
use super::*;
401+
use std::string::String;
401402

402403
#[test]
403404
fn insert_order() {
@@ -433,10 +434,8 @@ mod tests {
433434
map_b.insert(3, "3");
434435
assert!(!map_a.par_eq(&map_b));
435436

436-
let map_c: IndexMap<_, String> = map_b
437-
.into_par_iter()
438-
.map(|(k, v)| (k, v.to_owned()))
439-
.collect();
437+
let map_c: IndexMap<_, String> =
438+
map_b.into_par_iter().map(|(k, v)| (k, v.into())).collect();
440439
assert!(!map_a.par_eq(&map_c));
441440
assert!(!map_c.par_eq(&map_a));
442441
}

src/rayon/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ extern crate rayon;
22

33
use self::rayon::prelude::*;
44

5+
#[cfg(not(has_std))]
6+
use alloc::collections::LinkedList;
7+
8+
#[cfg(has_std)]
59
use std::collections::LinkedList;
610

11+
use vec::Vec;
12+
713
// generate `ParallelIterator` methods by just forwarding to the underlying
814
// self.entries and mapping its elements.
915
macro_rules! parallel_iterator_methods {

src/rayon/set.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use super::collect;
99
use super::rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
1010
use super::rayon::prelude::*;
1111

12-
use std::cmp::Ordering;
13-
use std::fmt;
14-
use std::hash::BuildHasher;
15-
use std::hash::Hash;
12+
use core::cmp::Ordering;
13+
use core::fmt;
14+
use core::hash::{BuildHasher, Hash};
15+
use vec::Vec;
1616

1717
use Entries;
1818
use IndexSet;

src/serde.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use self::serde::de::{
66
};
77
use self::serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer};
88

9-
use std::fmt::{self, Formatter};
10-
use std::hash::{BuildHasher, Hash};
11-
use std::marker::PhantomData;
9+
use core::fmt::{self, Formatter};
10+
use core::hash::{BuildHasher, Hash};
11+
use core::marker::PhantomData;
1212

1313
use IndexMap;
1414

0 commit comments

Comments
 (0)