From 236ab1aabf90d50e3e84e009f353a1e71cbb052e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Medina?= Date: Tue, 10 Dec 2024 13:09:44 -0800 Subject: [PATCH] make the named lifetime of serialize more unique otherwise it can't compile if the impl block already had a 'b named lifetime --- scylla-cql/src/types/serialize/row.rs | 54 +++++++++++++++++++++++++++ scylla-macros/src/serialize/row.rs | 8 ++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/scylla-cql/src/types/serialize/row.rs b/scylla-cql/src/types/serialize/row.rs index deb375eecc..4935421139 100644 --- a/scylla-cql/src/types/serialize/row.rs +++ b/scylla-cql/src/types/serialize/row.rs @@ -1790,4 +1790,58 @@ pub(crate) mod tests { assert_eq!(reference, row); } + + #[test] + fn test_name_flatten_with_lifetimes() { + #[derive(SerializeRow)] + #[scylla(crate = crate, flavor = "enforce_order")] + struct Inner<'b> { + b: &'b bool, + } + + #[derive(SerializeRow)] + #[scylla(crate = crate, flavor = "enforce_order")] + struct Outer<'a, 'b> { + #[scylla(flatten)] + inner: &'a Inner<'b>, + } + + let b = true; + let inner = Inner { b: &b }; + + let value = Outer { inner: &inner }; + let spec = [col("b", ColumnType::Boolean)]; + + let reference = do_serialize((&value.inner.b,), &spec); + let row = do_serialize(value, &spec); + + assert_eq!(reference, row); + } + + #[test] + fn test_ordered_flatten_with_lifetimes() { + #[derive(SerializeRow)] + #[scylla(crate = crate, flavor = "enforce_order")] + struct Inner<'b> { + b: &'b bool, + } + + #[derive(SerializeRow)] + #[scylla(crate = crate, flavor = "enforce_order")] + struct Outer<'a, 'b> { + #[scylla(flatten)] + inner: &'a Inner<'b>, + } + + let b = true; + let inner = Inner { b: &b }; + + let value = Outer { inner: &inner }; + let spec = [col("b", ColumnType::Boolean)]; + + let reference = do_serialize((&value.inner.b,), &spec); + let row = do_serialize(value, &spec); + + assert_eq!(reference, row); + } } diff --git a/scylla-macros/src/serialize/row.rs b/scylla-macros/src/serialize/row.rs index 068156ad2f..e0002c2d08 100644 --- a/scylla-macros/src/serialize/row.rs +++ b/scylla-macros/src/serialize/row.rs @@ -341,10 +341,10 @@ impl Generator for ColumnSortingGenerator<'_> { }; parse_quote! { - fn serialize<'b>( + fn serialize<'_scylla_ser_row_writer_buffer>( &self, ctx: &#crate_path::RowSerializationContext, - writer: &mut #crate_path::RowWriter<'b>, + writer: &mut #crate_path::RowWriter<'_scylla_ser_row_writer_buffer>, ) -> ::std::result::Result<(), #crate_path::SerializationError> { #partial_struct #partial_serialize @@ -400,10 +400,10 @@ impl Generator for ColumnOrderedGenerator<'_> { }); parse_quote! { - fn serialize<'b>( + fn serialize<'_scylla_ser_row_writer_buffer>( &self, ctx: &#crate_path::RowSerializationContext, - writer: &mut #crate_path::RowWriter<'b>, + writer: &mut #crate_path::RowWriter<'_scylla_ser_row_writer_buffer>, ) -> ::std::result::Result<(), #crate_path::SerializationError> { #[allow(non_local_definitions)] impl #impl_generics #crate_path::SerializeRowInOrder for #struct_name #ty_generics #where_clause {