Skip to content

Commit

Permalink
Fully mask the "test_debug" code from normal builds
Browse files Browse the repository at this point in the history
... but also add `--all-features` to CI so we're sure it builds.
  • Loading branch information
cuviper committed Feb 11, 2024
1 parent 3ac86a4 commit 2a33977
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/map/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -83,12 +82,13 @@ where
}
}

impl<K, V> fmt::Debug for IndexMapCore<K, V>
#[cfg(feature = "test_debug")]
impl<K, V> core::fmt::Debug for IndexMapCore<K, V>
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)
Expand Down
8 changes: 5 additions & 3 deletions src/map/core/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>;
Expand All @@ -21,9 +20,12 @@ pub(super) fn insert_bulk_no_grow<K, V>(indices: &mut RawTable<usize>, entries:
}
}

#[cfg(feature = "test_debug")]
pub(super) struct DebugIndices<'a>(pub &'a RawTable<usize>);
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()
Expand Down
14 changes: 8 additions & 6 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ impl<T, S> fmt::Debug for IndexSet<T, S>
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()
}
}

Expand Down

0 comments on commit 2a33977

Please sign in to comment.