From 2a33977a155826904eaecef251f91ac5c566f359 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Sun, 11 Feb 2024 13:35:53 -0800 Subject: [PATCH] Fully mask the `"test_debug"` code from normal builds ... but also add `--all-features` to CI so we're sure it builds. --- .github/workflows/ci.yml | 2 +- src/map.rs | 18 ++++++++++-------- src/map/core.rs | 10 +++++----- src/map/core/raw.rs | 8 +++++--- src/set.rs | 14 ++++++++------ 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a07f9b4f..7631a57b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,7 +93,7 @@ jobs: - uses: dtolnay/rust-toolchain@beta with: components: clippy - - run: cargo clippy + - run: cargo clippy --all-features miri: runs-on: ubuntu-latest diff --git a/src/map.rs b/src/map.rs index 428fac40..5fe0bb18 100644 --- a/src/map.rs +++ b/src/map.rs @@ -141,15 +141,17 @@ where K: fmt::Debug, V: fmt::Debug, { + #[cfg(not(feature = "test_debug"))] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if cfg!(not(feature = "test_debug")) { - f.debug_map().entries(self.iter()).finish() - } else { - // Let the inner `IndexMapCore` print all of its details - f.debug_struct("IndexMap") - .field("core", &self.core) - .finish() - } + f.debug_map().entries(self.iter()).finish() + } + + #[cfg(feature = "test_debug")] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Let the inner `IndexMapCore` print all of its details + f.debug_struct("IndexMap") + .field("core", &self.core) + .finish() } } diff --git a/src/map/core.rs b/src/map/core.rs index 2dca04a5..853c86ed 100644 --- a/src/map/core.rs +++ b/src/map/core.rs @@ -16,7 +16,6 @@ use hashbrown::raw::RawTable; use crate::vec::{self, Vec}; use crate::TryReserveError; -use core::fmt; use core::mem; use core::ops::RangeBounds; @@ -83,12 +82,13 @@ where } } -impl fmt::Debug for IndexMapCore +#[cfg(feature = "test_debug")] +impl core::fmt::Debug for IndexMapCore where - K: fmt::Debug, - V: fmt::Debug, + K: core::fmt::Debug, + V: core::fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("IndexMapCore") .field("indices", &raw::DebugIndices(&self.indices)) .field("entries", &self.entries) diff --git a/src/map/core/raw.rs b/src/map/core/raw.rs index 233e41e7..10bbea53 100644 --- a/src/map/core/raw.rs +++ b/src/map/core/raw.rs @@ -3,7 +3,6 @@ //! mostly in dealing with its bucket "pointers". use super::{equivalent, get_hash, Bucket, HashValue, IndexMapCore}; -use core::fmt; use hashbrown::raw::RawTable; type RawBucket = hashbrown::raw::Bucket; @@ -21,9 +20,12 @@ pub(super) fn insert_bulk_no_grow(indices: &mut RawTable, entries: } } +#[cfg(feature = "test_debug")] pub(super) struct DebugIndices<'a>(pub &'a RawTable); -impl fmt::Debug for DebugIndices<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + +#[cfg(feature = "test_debug")] +impl core::fmt::Debug for DebugIndices<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { // SAFETY: we're not letting any of the buckets escape this function let indices = unsafe { self.0.iter().map(|raw_bucket| *raw_bucket.as_ref()) }; f.debug_list().entries(indices).finish() diff --git a/src/set.rs b/src/set.rs index e2560843..ed6bf35a 100644 --- a/src/set.rs +++ b/src/set.rs @@ -133,13 +133,15 @@ impl fmt::Debug for IndexSet where T: fmt::Debug, { + #[cfg(not(feature = "test_debug"))] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if cfg!(not(feature = "test_debug")) { - f.debug_set().entries(self.iter()).finish() - } else { - // Let the inner `IndexMap` print all of its details - f.debug_struct("IndexSet").field("map", &self.map).finish() - } + f.debug_set().entries(self.iter()).finish() + } + + #[cfg(feature = "test_debug")] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Let the inner `IndexMap` print all of its details + f.debug_struct("IndexSet").field("map", &self.map).finish() } }