--- a/src/map.rs
+++ b/src/map.rs
@@ -10,7 +10,7 @@ mod slice;
 #[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
 pub mod serde_seq;
 
-#[cfg(test)]
+#[cfg(all(test, feature = "std"))]
 mod tests;
 
 pub use self::core::raw_entry_v1::{self, RawEntryApiV1};
--- a/src/borsh.rs
+++ b/src/borsh.rs
@@ -97,7 +97,7 @@ fn check_zst<T>() -> Result<()> {
     Ok(())
 }
 
-#[cfg(test)]
+#[cfg(all(test, feature = "std"))]
 mod borsh_tests {
     use super::*;
 
--- a/src/map/slice.rs
+++ b/src/map/slice.rs
@@ -546,7 +546,7 @@ impl_index!(
     (Bound<usize>, Bound<usize>)
 );
 
-#[cfg(test)]
+#[cfg(all(test, feature = "std"))]
 mod tests {
     use super::*;
 
--- a/src/set.rs
+++ b/src/set.rs
@@ -4,7 +4,7 @@ mod iter;
 mod mutable;
 mod slice;
 
-#[cfg(test)]
+#[cfg(all(test, feature = "std"))]
 mod tests;
 
 pub use self::iter::{
--- a/src/set/slice.rs
+++ b/src/set/slice.rs
@@ -358,7 +358,7 @@ impl_index!(
     (Bound<usize>, Bound<usize>)
 );
 
-#[cfg(test)]
+#[cfg(all(test, feature = "std"))]
 mod tests {
     use super::*;
 
--- a/benches/bench.rs
+++ b/benches/bench.rs
@@ -1,3 +1,4 @@
+#![cfg(feature = "std")]
 #![feature(test)]
 
 extern crate test;
--- a/benches/faststring.rs
+++ b/benches/faststring.rs
@@ -1,3 +1,4 @@
+#![cfg(feature = "std")]
 #![feature(test)]
 
 extern crate test;
--- a/tests/equivalent_trait.rs
+++ b/tests/equivalent_trait.rs
@@ -1,3 +1,4 @@
+#![cfg(feature = "std")]
 use indexmap::indexmap;
 use indexmap::Equivalent;
 
--- a/tests/macros_full_path.rs
+++ b/tests/macros_full_path.rs
@@ -1,3 +1,4 @@
+#![cfg(feature = "std")]
 #[test]
 fn test_create_map() {
     let _m = indexmap::indexmap! {
--- a/tests/quick.rs
+++ b/tests/quick.rs
@@ -1,3 +1,4 @@
+#![cfg(feature = "std")]
 use indexmap::{IndexMap, IndexSet};
 use itertools::Itertools;
 
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1,3 +1,4 @@
+#![cfg(feature = "std")]
 use indexmap::{indexmap, indexset};
 
 #[test]
--- a/src/rayon/map.rs
+++ b/src/rayon/map.rs
@@ -594,7 +594,7 @@ where
     }
 }
 
-#[cfg(test)]
+#[cfg(all(test, feature = "std"))]
 mod tests {
     use super::*;
     use std::string::String;
--- a/src/rayon/set.rs
+++ b/src/rayon/set.rs
@@ -630,7 +630,7 @@ where
     }
 }
 
-#[cfg(test)]
+#[cfg(all(test, feature = "std"))]
 mod tests {
     use super::*;
 
