From 157199aa289c9c843f4f2b119432ea82321aedfa Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 10 Jun 2026 21:19:59 +0000 Subject: [PATCH] durable-sqlx: forward Encode for &[T] slice references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sqlx 0.9's blanket `impl Encode for &T` requires `T: Sized`, so it does not cover `&[T]` (the pointee `[T]` is unsized). As a result, binding a slice reference such as `&[i32]` or `&[&str]` as an array parameter no longer compiled for the element types declared via `generic_slice_decl!`, while the hand-written `uuid` impls still worked — an inconsistent regression in 0.6.0. Add the missing `&[$elem]` forward to `forward_slice_encode_deref!` so the macro-declared element types regain parity with `uuid`, and add a compile-time regression test covering the affected element types. Fixes #114 --- crates/durable-sqlx/src/driver/types/mod.rs | 35 +++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/crates/durable-sqlx/src/driver/types/mod.rs b/crates/durable-sqlx/src/driver/types/mod.rs index 5065ea8..ec9119d 100644 --- a/crates/durable-sqlx/src/driver/types/mod.rs +++ b/crates/durable-sqlx/src/driver/types/mod.rs @@ -57,8 +57,11 @@ macro_rules! forward_encode_deref { } macro_rules! forward_slice_encode_deref { ($elem:ty) => { - // `&T` and `Cow<'_, T>` are covered by blanket `Encode` impls in sqlx 0.9, - // so we only forward for the wrappers without such blanket impls. + // sqlx 0.9's blanket `impl Encode for &T` requires `T: Sized`, so it does + // *not* cover `&[$elem]` (the pointee `[$elem]` is unsized). Forward it here + // explicitly so slice references stay bindable. `Cow<'_, [$elem]>` is covered + // by a blanket `Encode` impl in sqlx 0.9. + forward_encode_deref!(&'_ [$elem] => [$elem]); forward_encode_deref!(Vec<$elem> => [$elem]); forward_encode_deref!(Box<[$elem]> => [$elem]); } @@ -118,3 +121,31 @@ where { value.encode_by_ref(buf) } + +#[cfg(test)] +mod tests { + use super::Durable; + + /// Regression test for #114: binding a `&[T]` slice reference as an array + /// parameter must compile for every element type declared via the slice + /// macros, matching the hand-written `uuid` impls. sqlx 0.9's blanket + /// `impl Encode for &T` requires `T: Sized`, so it does not cover `&[T]` + /// (the pointee `[T]` is unsized) — the forwarding impls are what make + /// these bindable. + fn assert_encode<'q, T: sqlx::Encode<'q, Durable>>() {} + + #[test] + fn slice_refs_implement_encode() { + assert_encode::<&[i8]>(); + assert_encode::<&[i16]>(); + assert_encode::<&[i32]>(); + assert_encode::<&[i64]>(); + assert_encode::<&[f32]>(); + assert_encode::<&[f64]>(); + assert_encode::<&[bool]>(); + assert_encode::<&[&str]>(); + assert_encode::<&[String]>(); + #[cfg(feature = "uuid")] + assert_encode::<&[::uuid::Uuid]>(); + } +}