From b3be1e3cd5190f2b7ff712c0281bc3f286a266da Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 29 Oct 2024 14:16:15 -0400 Subject: [PATCH] Mark auto derived functions (#495) * Add automatically_derived to all impl functions in deku-derive * Motivation: https://github.com/rust-lang/rust/pull/120185 --- deku-derive/src/macros/deku_read.rs | 7 +++++++ deku-derive/src/macros/deku_write.rs | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/deku-derive/src/macros/deku_read.rs b/deku-derive/src/macros/deku_read.rs index 4331ad49..a5d2ee47 100644 --- a/deku-derive/src/macros/deku_read.rs +++ b/deku-derive/src/macros/deku_read.rs @@ -163,6 +163,7 @@ fn emit_struct(input: &DekuData) -> Result { }; tokens.extend(quote! { + #[automatically_derived] impl #imp ::#crate_::DekuReader<#lifetime, #ctx_types> for #ident #wher { #[inline] fn from_reader_with_ctx(__deku_reader: &mut ::#crate_::reader::Reader, #ctx_arg) -> core::result::Result { @@ -175,6 +176,7 @@ fn emit_struct(input: &DekuData) -> Result { let read_body = wrap_default_ctx(read_body, &input.ctx, &input.ctx_default); tokens.extend(quote! { + #[automatically_derived] impl #imp ::#crate_::DekuReader<#lifetime> for #ident #wher { #[inline] fn from_reader_with_ctx(__deku_reader: &mut ::#crate_::reader::Reader, _: ()) -> core::result::Result { @@ -433,6 +435,7 @@ fn emit_enum(input: &DekuData) -> Result { tokens.extend(quote! { #[allow(non_snake_case)] + #[automatically_derived] impl #imp ::#crate_::DekuReader<#lifetime, #ctx_types> for #ident #wher { #[inline] fn from_reader_with_ctx(__deku_reader: &mut ::#crate_::reader::Reader, #ctx_arg) -> core::result::Result { @@ -446,6 +449,7 @@ fn emit_enum(input: &DekuData) -> Result { tokens.extend(quote! { #[allow(non_snake_case)] + #[automatically_derived] impl #imp ::#crate_::DekuReader<#lifetime> for #ident #wher { #[inline] fn from_reader_with_ctx(__deku_reader: &mut ::#crate_::reader::Reader, _: ()) -> core::result::Result { @@ -470,6 +474,7 @@ fn emit_enum(input: &DekuData) -> Result { // would need to be appended to #imp } else { tokens.extend(quote! { + #[automatically_derived] impl<'__deku> #imp ::#crate_::DekuEnumExt<#lifetime, (#deku_id_type)> for #ident #wher { #[inline] fn deku_id(&self) -> core::result::Result<(#deku_id_type), ::#crate_::DekuError> { @@ -973,6 +978,7 @@ pub fn emit_container_read( ) -> TokenStream { let crate_ = super::get_crate_name(); quote! { + #[automatically_derived] impl #imp ::#crate_::DekuContainerRead<#lifetime> for #ident #wher { #[allow(non_snake_case)] #[inline] @@ -998,6 +1004,7 @@ pub fn emit_try_from( ) -> TokenStream { let crate_ = super::get_crate_name(); quote! { + #[automatically_derived] impl #imp core::convert::TryFrom<&#lifetime [u8]> for #ident #wher { type Error = ::#crate_::DekuError; diff --git a/deku-derive/src/macros/deku_write.rs b/deku-derive/src/macros/deku_write.rs index bc7f0bd6..2d19c214 100644 --- a/deku-derive/src/macros/deku_write.rs +++ b/deku-derive/src/macros/deku_write.rs @@ -93,6 +93,7 @@ fn emit_struct(input: &DekuData) -> Result { if input.ctx.is_none() || (input.ctx.is_some() && input.ctx_default.is_some()) { #[cfg(feature = "bits")] tokens.extend(quote! { + #[automatically_derived] impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec #wher { type Error = ::#crate_::DekuError; @@ -105,6 +106,7 @@ fn emit_struct(input: &DekuData) -> Result { }); tokens.extend(quote! { + #[automatically_derived] impl #imp core::convert::TryFrom<#ident> for Vec #wher { type Error = ::#crate_::DekuError; @@ -114,6 +116,7 @@ fn emit_struct(input: &DekuData) -> Result { } } + #[automatically_derived] impl #imp ::#crate_::DekuContainerWrite for #ident #wher {} }); } @@ -136,6 +139,7 @@ fn emit_struct(input: &DekuData) -> Result { let update_use = check_update_use(&field_updates); tokens.extend(quote! { + #[automatically_derived] impl #imp ::#crate_::DekuUpdate for #ident #wher { #[inline] fn update(&mut self) -> core::result::Result<(), ::#crate_::DekuError> { @@ -146,6 +150,7 @@ fn emit_struct(input: &DekuData) -> Result { } } + #[automatically_derived] impl #imp ::#crate_::DekuWriter<#ctx_types> for #ident #wher { #[allow(unused_variables)] #[inline] @@ -159,6 +164,7 @@ fn emit_struct(input: &DekuData) -> Result { let write_body = wrap_default_ctx(write_body, &input.ctx, &input.ctx_default); tokens.extend(quote! { + #[automatically_derived] impl #imp ::#crate_::DekuWriter for #ident #wher { #[allow(unused_variables)] #[inline] @@ -300,6 +306,7 @@ fn emit_enum(input: &DekuData) -> Result { if input.ctx.is_none() || (input.ctx.is_some() && input.ctx_default.is_some()) { #[cfg(feature = "bits")] tokens.extend(quote! { + #[automatically_derived] impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec #wher { type Error = ::#crate_::DekuError; @@ -312,6 +319,7 @@ fn emit_enum(input: &DekuData) -> Result { }); tokens.extend(quote! { + #[automatically_derived] impl #imp core::convert::TryFrom<#ident> for Vec #wher { type Error = ::#crate_::DekuError; @@ -321,6 +329,7 @@ fn emit_enum(input: &DekuData) -> Result { } } + #[automatically_derived] impl #imp ::#crate_::DekuContainerWrite for #ident #wher {} }); } @@ -341,6 +350,7 @@ fn emit_enum(input: &DekuData) -> Result { let update_use = check_update_use(&variant_updates); tokens.extend(quote! { + #[automatically_derived] impl #imp ::#crate_::DekuUpdate for #ident #wher { #[inline] fn update(&mut self) -> core::result::Result<(), ::#crate_::DekuError> { @@ -354,6 +364,7 @@ fn emit_enum(input: &DekuData) -> Result { } } + #[automatically_derived] impl #imp ::#crate_::DekuWriter<#ctx_types> for #ident #wher { #[allow(unused_variables)] #[inline] @@ -367,6 +378,7 @@ fn emit_enum(input: &DekuData) -> Result { let write_body = wrap_default_ctx(write_body, &input.ctx, &input.ctx_default); tokens.extend(quote! { + #[automatically_derived] impl #imp ::#crate_::DekuWriter for #ident #wher { #[allow(unused_variables)] #[inline]