From c887c5330d8d2829210afc6e0d8bf34e788440e2 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Fri, 22 May 2026 13:24:50 +0200 Subject: [PATCH 1/3] Debug print --- arcshift/CHANGELOG.md | 4 ++++ arcshift/src/lib.rs | 4 ++-- arcshift/src/tests.rs | 22 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/arcshift/CHANGELOG.md b/arcshift/CHANGELOG.md index b5a810f..3f096d0 100644 --- a/arcshift/CHANGELOG.md +++ b/arcshift/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.3 + +Fix Debug impl of ArcShift, so that it honors "{:#?}" format strings. + ## 0.4.2 Support rust 1.75 (0.4.1 regressed to require newer rust). diff --git a/arcshift/src/lib.rs b/arcshift/src/lib.rs index 755b379..49f1aa5 100644 --- a/arcshift/src/lib.rs +++ b/arcshift/src/lib.rs @@ -413,7 +413,7 @@ where T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - write!(f, "ArcShift({:?})", self.shared_non_reloading_get()) + f.debug_tuple("ArcShift").field(&self.shared_non_reloading_get()).finish() } } @@ -428,7 +428,7 @@ where T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - write!(f, "ArcShiftWeak(..)") + f.debug_tuple("ArcShiftWeak").finish_non_exhaustive() } } diff --git a/arcshift/src/tests.rs b/arcshift/src/tests.rs index 287a85c..0d49919 100644 --- a/arcshift/src/tests.rs +++ b/arcshift/src/tests.rs @@ -17,7 +17,7 @@ use std::hint::black_box; use std::mem::MaybeUninit; use std::string::ToString; use std::sync::atomic::AtomicUsize; -use std::thread; +use std::{format, thread}; use std::time::Duration; use std::vec; @@ -2656,6 +2656,26 @@ fn simple_threading_try_into_inner3() { }); } +#[test] +fn check_debug_impls() { + #[derive(Debug)] + struct Sample { + x: u32, + y: bool + } + + let x = ArcShift::new(Sample { + x: 42, + y: false + }); + let weak = ArcShift::downgrade(&x); + + assert_eq!(format!("{:?}", x), "ArcShift(Sample { x: 42, y: false })"); + assert_eq!(format!("{:?}", weak), "ArcShiftWeak(..)"); + assert_eq!(format!("{:#?}", x), "ArcShift(\n Sample {\n x: 42,\n y: false,\n },\n)"); + assert_eq!(format!("{:#?}", weak), "ArcShiftWeak(..)"); +} + /* This does not compile, nor should it compile. ArcShift must be invariant in 'a. From 86a540b7e1582216b9f37f756c98c65b48e9df36 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Fri, 22 May 2026 13:31:52 +0200 Subject: [PATCH 2/3] Avoid using features from newer rust than MSRV --- arcshift/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcshift/src/lib.rs b/arcshift/src/lib.rs index 49f1aa5..8e8fbac 100644 --- a/arcshift/src/lib.rs +++ b/arcshift/src/lib.rs @@ -428,7 +428,7 @@ where T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - f.debug_tuple("ArcShiftWeak").finish_non_exhaustive() + write!(f, "ArcShiftWeak(..)") } } From ee460670a4dfceab39ce1d7e33e51324e15310af Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Fri, 22 May 2026 13:32:29 +0200 Subject: [PATCH 3/3] cargo fmt --- arcshift/src/lib.rs | 4 +++- arcshift/src/tests.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/arcshift/src/lib.rs b/arcshift/src/lib.rs index 8e8fbac..37605fd 100644 --- a/arcshift/src/lib.rs +++ b/arcshift/src/lib.rs @@ -413,7 +413,9 @@ where T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - f.debug_tuple("ArcShift").field(&self.shared_non_reloading_get()).finish() + f.debug_tuple("ArcShift") + .field(&self.shared_non_reloading_get()) + .finish() } } diff --git a/arcshift/src/tests.rs b/arcshift/src/tests.rs index 0d49919..1362608 100644 --- a/arcshift/src/tests.rs +++ b/arcshift/src/tests.rs @@ -17,9 +17,9 @@ use std::hint::black_box; use std::mem::MaybeUninit; use std::string::ToString; use std::sync::atomic::AtomicUsize; -use std::{format, thread}; use std::time::Duration; use std::vec; +use std::{format, thread}; mod custom_fuzz; pub(crate) mod leak_detection; @@ -2661,18 +2661,18 @@ fn check_debug_impls() { #[derive(Debug)] struct Sample { x: u32, - y: bool + y: bool, } - let x = ArcShift::new(Sample { - x: 42, - y: false - }); + let x = ArcShift::new(Sample { x: 42, y: false }); let weak = ArcShift::downgrade(&x); assert_eq!(format!("{:?}", x), "ArcShift(Sample { x: 42, y: false })"); assert_eq!(format!("{:?}", weak), "ArcShiftWeak(..)"); - assert_eq!(format!("{:#?}", x), "ArcShift(\n Sample {\n x: 42,\n y: false,\n },\n)"); + assert_eq!( + format!("{:#?}", x), + "ArcShift(\n Sample {\n x: 42,\n y: false,\n },\n)" + ); assert_eq!(format!("{:#?}", weak), "ArcShiftWeak(..)"); }