From 4184a6441cb1cd63450f567867a9bcbd0cbcaffa Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Thu, 22 Jan 2026 13:31:52 -0700 Subject: [PATCH] Add `Debug` bound to `ArraySize` This came up with `elliptic-curve` and `sec1` as I was working on `dhkem`: error[E0277]: `::FieldBytesSize` doesn't implement `Debug` --> dhkem/src/ecdh_kem.rs:80:5 | 80 | / fn encapsulate_with_rng( 81 | | &self, 82 | | rng: &mut R, 83 | | ) -> Result<(PublicKey, SharedSecret), Self::Error> { | |_____________________________________________________________^ the trait `Debug` is not implemented for `::FieldBytesSize` `sec1::point::ModulusSize` bounds on `Debug`, but `elliptic_curve::Curve::FieldBytesSize` does not. Yet for whatever reason in `elliptic-curve` it's able to get away with: FieldBytesSize: ModulusSize Instead of adding a `Debug` bound to `Curve::FieldBytesSize` I thought I would add it here instead to solve this problem for good. This shouldn't be breaking, because `ArraySize` bounds on `typenum::Unsigned`, which means it's impossible for 3rd party crates to impl as they would need to add impls to a foreign type which isn't allowed by the orphan rules. --- src/traits.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/traits.rs b/src/traits.rs index 1988277..d22a30e 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -3,6 +3,7 @@ use crate::Array; use core::{ borrow::{Borrow, BorrowMut}, + fmt::Debug, ops::{Index, IndexMut, Range}, }; use typenum::Unsigned; @@ -17,7 +18,7 @@ use typenum::Unsigned; /// /// NOTE: This trait is effectively sealed and can not be implemented by third-party crates. /// It is implemented only for a number of types defined in [`typenum::consts`]. -pub unsafe trait ArraySize: Unsigned { +pub unsafe trait ArraySize: Unsigned + Debug { /// Array type which corresponds to this size. /// /// This is always defined to be `[T; N]` where `N` is the same as