From e03ca7673aa0d304c89aa4632aa979db03de08a6 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Tue, 19 Dec 2023 17:27:53 +1100 Subject: [PATCH 1/2] Remove unneeded unsafe from test --- metrics-exporter-prometheus/src/distribution.rs | 6 +++--- metrics-util/src/bucket.rs | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/metrics-exporter-prometheus/src/distribution.rs b/metrics-exporter-prometheus/src/distribution.rs index a9944305..335d7172 100644 --- a/metrics-exporter-prometheus/src/distribution.rs +++ b/metrics-exporter-prometheus/src/distribution.rs @@ -353,10 +353,10 @@ mod tests { let (clock, mock) = Clock::mock(); mock.increment(Duration::from_secs(4)); - const BUCKET_COUNT: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(2) }; - const BUCKET_WIDTH: Duration = Duration::from_secs(5); + let bucket_count = NonZeroU32::new(2).unwrap(); + let bucket_width = Duration::from_secs(5); - let mut summary = RollingSummary::new(BUCKET_COUNT, BUCKET_WIDTH); + let mut summary = RollingSummary::new(bucket_count, bucket_width); assert_eq!(0, summary.buckets().len()); assert_eq!(0, summary.count()); diff --git a/metrics-util/src/bucket.rs b/metrics-util/src/bucket.rs index 355323ad..22f44baf 100644 --- a/metrics-util/src/bucket.rs +++ b/metrics-util/src/bucket.rs @@ -153,6 +153,8 @@ impl Drop for Block { impl std::fmt::Debug for Block { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // SAFETY: + // This is unsound but there is no way to call this from the public API so its probably fine? let has_next = unsafe { !self.next.load(Ordering::Acquire, unprotected()).is_null() }; f.debug_struct("Block") .field("type", &std::any::type_name::()) From 3da971c157a479993f294458f7e9fa5aa6a29e45 Mon Sep 17 00:00:00 2001 From: Toby Lawrence Date: Thu, 21 Dec 2023 09:44:46 -0500 Subject: [PATCH 2/2] Update bucket.rs --- metrics-util/src/bucket.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/metrics-util/src/bucket.rs b/metrics-util/src/bucket.rs index 22f44baf..355323ad 100644 --- a/metrics-util/src/bucket.rs +++ b/metrics-util/src/bucket.rs @@ -153,8 +153,6 @@ impl Drop for Block { impl std::fmt::Debug for Block { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - // SAFETY: - // This is unsound but there is no way to call this from the public API so its probably fine? let has_next = unsafe { !self.next.load(Ordering::Acquire, unprotected()).is_null() }; f.debug_struct("Block") .field("type", &std::any::type_name::())