diff --git a/borsh-derive/src/internals/attributes/field/mod.rs b/borsh-derive/src/internals/attributes/field/mod.rs index 3bc61b395..70c43c974 100644 --- a/borsh-derive/src/internals/attributes/field/mod.rs +++ b/borsh-derive/src/internals/attributes/field/mod.rs @@ -165,8 +165,7 @@ impl Attributes { Ok(result) } pub(crate) fn needs_bounds_derive(&self, ty: BoundType) -> bool { - let predicates = self.get_bounds(ty); - predicates.is_none() + self.get_bounds(ty).is_none() } fn get_bounds(&self, ty: BoundType) -> Option> { @@ -243,8 +242,7 @@ impl Attributes { #[cfg(test)] mod tests { - use quote::quote; - use syn::{Attribute, ItemStruct}; + use syn::{parse_quote, Attribute, ItemStruct}; fn parse_bounds(attrs: &[Attribute]) -> Result, syn::Error> { // #[borsh(bound(serialize = "...", deserialize = "..."))] @@ -261,7 +259,7 @@ mod tests { #[test] fn test_reject_multiple_borsh_attrs() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(skip)] #[borsh(bound(deserialize = "K: Hash + Ord, @@ -272,8 +270,7 @@ mod tests { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let err = match Attributes::parse(&first_field.attrs) { @@ -285,7 +282,7 @@ mod tests { #[test] fn test_bounds_parsing1() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(bound(deserialize = "K: Hash + Ord, V: Eq + Ord", @@ -295,8 +292,7 @@ mod tests { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let attrs = parse_bounds(&first_field.attrs).unwrap().unwrap(); @@ -306,7 +302,7 @@ mod tests { #[test] fn test_bounds_parsing2() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(bound(deserialize = "K: Hash + Eq + borsh::de::BorshDeserialize, V: borsh::de::BorshDeserialize", @@ -316,8 +312,7 @@ mod tests { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let attrs = parse_bounds(&first_field.attrs).unwrap().unwrap(); @@ -327,7 +322,7 @@ mod tests { #[test] fn test_bounds_parsing3() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(bound(deserialize = "K: Hash + Eq + borsh::de::BorshDeserialize, V: borsh::de::BorshDeserialize", @@ -336,8 +331,7 @@ mod tests { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let attrs = parse_bounds(&first_field.attrs).unwrap().unwrap(); @@ -347,14 +341,13 @@ mod tests { #[test] fn test_bounds_parsing4() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(bound(deserialize = "K: Hash"))] x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let attrs = parse_bounds(&first_field.attrs).unwrap().unwrap(); @@ -364,14 +357,13 @@ mod tests { #[test] fn test_bounds_parsing_error() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(bound(deser = "K: Hash"))] x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let err = match parse_bounds(&first_field.attrs) { @@ -383,14 +375,13 @@ mod tests { #[test] fn test_bounds_parsing_error2() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(bound(deserialize = "K Hash"))] x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let err = match parse_bounds(&first_field.attrs) { @@ -402,14 +393,13 @@ mod tests { #[test] fn test_bounds_parsing_error3() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(bound(deserialize = 42))] x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let err = match parse_bounds(&first_field.attrs) { @@ -421,7 +411,7 @@ mod tests { #[test] fn test_ser_de_with_parsing1() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh( serialize_with = "third_party_impl::serialize_third_party", @@ -430,8 +420,7 @@ mod tests { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let attrs = Attributes::parse(&first_field.attrs).unwrap(); @@ -440,14 +429,13 @@ mod tests { } #[test] fn test_borsh_skip() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(skip)] x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; @@ -456,13 +444,12 @@ mod tests { } #[test] fn test_borsh_no_skip() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; @@ -483,7 +470,7 @@ mod tests_schema { }; use quote::quote; - use syn::{Attribute, ItemStruct}; + use syn::{parse_quote, Attribute, ItemStruct}; use super::schema; fn parse_schema_attrs(attrs: &[Attribute]) -> Result, syn::Error> { @@ -494,7 +481,7 @@ mod tests_schema { #[test] fn test_root_bounds_and_params_combined() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh( serialize_with = "third_party_impl::serialize_third_party", @@ -504,8 +491,7 @@ mod tests_schema { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; @@ -521,7 +507,7 @@ mod tests_schema { #[test] fn test_schema_params_parsing1() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -532,8 +518,7 @@ mod tests_schema { field: ::Associated, another: V, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let schema_attrs = parse_schema_attrs(&first_field.attrs).unwrap(); @@ -541,7 +526,7 @@ mod tests_schema { } #[test] fn test_schema_params_parsing_error() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -552,8 +537,7 @@ mod tests_schema { field: ::Associated, another: V, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let err = match parse_schema_attrs(&first_field.attrs) { @@ -565,7 +549,7 @@ mod tests_schema { #[test] fn test_schema_params_parsing_error2() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -576,8 +560,7 @@ mod tests_schema { field: ::Associated, another: V, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let err = match parse_schema_attrs(&first_field.attrs) { @@ -589,7 +572,7 @@ mod tests_schema { #[test] fn test_schema_params_parsing2() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -600,8 +583,7 @@ mod tests_schema { field: ::Associated, another: V, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let schema_attrs = parse_schema_attrs(&first_field.attrs).unwrap(); @@ -609,7 +591,7 @@ mod tests_schema { } #[test] fn test_schema_params_parsing3() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -618,8 +600,7 @@ mod tests_schema { field: ::Associated, another: V, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let schema_attrs = parse_schema_attrs(&first_field.attrs).unwrap(); @@ -628,7 +609,7 @@ mod tests_schema { #[test] fn test_schema_params_parsing4() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -636,8 +617,7 @@ mod tests_schema { field: ::Associated, another: V, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let schema_attrs = parse_schema_attrs(&first_field.attrs).unwrap(); @@ -646,7 +626,7 @@ mod tests_schema { #[test] fn test_schema_with_funcs_parsing() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(schema(with_funcs( declaration = "third_party_impl::declaration::", @@ -655,8 +635,7 @@ mod tests_schema { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let attrs = Attributes::parse(&first_field.attrs).unwrap(); @@ -670,7 +649,7 @@ mod tests_schema { // both `declaration` and `definitions` have to be specified #[test] fn test_schema_with_funcs_parsing_error() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(schema(with_funcs( declaration = "third_party_impl::declaration::" @@ -678,8 +657,7 @@ mod tests_schema { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let attrs = Attributes::parse(&first_field.attrs); @@ -693,14 +671,13 @@ mod tests_schema { #[test] fn test_root_error() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(boons)] x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; let err = match Attributes::parse(&first_field.attrs) { @@ -712,7 +689,7 @@ mod tests_schema { #[test] fn test_root_bounds_and_wrong_key_combined() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(bound(deserialize = "K: Hash"), schhema(params = "T => ::Associated, V => Vec") @@ -720,8 +697,7 @@ mod tests_schema { x: u64, y: String, } - }) - .unwrap(); + }; let first_field = &item_struct.fields.into_iter().collect::>()[0]; diff --git a/borsh-derive/src/internals/attributes/item/mod.rs b/borsh-derive/src/internals/attributes/item/mod.rs index ff3551486..98cdf601a 100644 --- a/borsh-derive/src/internals/attributes/item/mod.rs +++ b/borsh-derive/src/internals/attributes/item/mod.rs @@ -121,51 +121,49 @@ pub(crate) fn get_crate(attrs: &[Attribute]) -> Result, Error> { #[cfg(test)] mod tests { use crate::internals::test_helpers::local_insta_assert_debug_snapshot; - use quote::{quote, ToTokens}; - use syn::ItemEnum; + use quote::ToTokens; + use syn::{parse_quote, ItemEnum}; use super::*; + #[test] fn test_use_discriminant() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[derive(BorshDeserialize, Debug)] #[borsh(use_discriminant = false)] enum AWithUseDiscriminantFalse { X, Y, } - }) - .unwrap(); + }; let actual = contains_use_discriminant(&item_enum); assert!(!actual.unwrap()); } #[test] fn test_use_discriminant_true() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[derive(BorshDeserialize, Debug)] #[borsh(use_discriminant = true)] enum AWithUseDiscriminantTrue { X, Y, } - }) - .unwrap(); + }; let actual = contains_use_discriminant(&item_enum); assert!(actual.unwrap()); } #[test] fn test_use_discriminant_wrong_value() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[derive(BorshDeserialize, Debug)] #[borsh(use_discriminant = 111)] enum AWithUseDiscriminantFalse { X, Y, } - }) - .unwrap(); + }; let actual = contains_use_discriminant(&item_enum); let err = match actual { Ok(..) => unreachable!("expecting error here"), @@ -173,66 +171,66 @@ mod tests { }; local_insta_assert_debug_snapshot!(err); } + #[test] fn test_check_attrs_use_discriminant_on_struct() { - let item_enum: DeriveInput = syn::parse2(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshDeserialize, Debug)] #[borsh(use_discriminant = false)] struct AWithUseDiscriminantFalse { x: X, y: Y, } - }) - .unwrap(); - let actual = check_attributes(&item_enum); + }; + let actual = check_attributes(&derive_input); local_insta_assert_debug_snapshot!(actual.unwrap_err()); } + #[test] fn test_check_attrs_borsh_skip_on_whole_item() { - let item_enum: DeriveInput = syn::parse2(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshDeserialize, Debug)] #[borsh(skip)] struct AWithUseDiscriminantFalse { x: X, y: Y, } - }) - .unwrap(); - let actual = check_attributes(&item_enum); + }; + let actual = check_attributes(&derive_input); local_insta_assert_debug_snapshot!(actual.unwrap_err()); } + #[test] fn test_check_attrs_borsh_invalid_on_whole_item() { - let item_enum: DeriveInput = syn::parse2(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshDeserialize, Debug)] #[borsh(invalid)] enum AWithUseDiscriminantFalse { X, Y, } - }) - .unwrap(); - let actual = check_attributes(&item_enum); + }; + let actual = check_attributes(&derive_input); local_insta_assert_debug_snapshot!(actual.unwrap_err()); } + #[test] fn test_check_attrs_init_function() { - let item_struct = syn::parse2::(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(init = initialization_method)] struct A<'a> { x: u64, } - }) - .unwrap(); + }; - let actual = check_attributes(&item_struct); + let actual = check_attributes(&derive_input); assert!(actual.is_ok()); } #[test] fn test_check_attrs_init_function_with_use_discriminant_reversed() { - let item_struct = syn::parse2::(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(use_discriminant=true, init = initialization_method)] enum A { @@ -240,16 +238,15 @@ mod tests { C, D= 10, } - }) - .unwrap(); + }; - let actual = check_attributes(&item_struct); + let actual = check_attributes(&derive_input); assert!(actual.is_ok()); } #[test] fn test_reject_multiple_borsh_attrs() { - let item_struct = syn::parse2::(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(use_discriminant=true)] #[borsh(init = initialization_method)] @@ -258,16 +255,15 @@ mod tests { C, D= 10, } - }) - .unwrap(); + }; - let actual = check_attributes(&item_struct); + let actual = check_attributes(&derive_input); local_insta_assert_debug_snapshot!(actual.unwrap_err()); } #[test] fn test_check_attrs_init_function_with_use_discriminant() { - let item_struct = syn::parse2::(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(init = initialization_method, use_discriminant=true)] enum A { @@ -275,16 +271,15 @@ mod tests { C, D= 10, } - }) - .unwrap(); + }; - let actual = check_attributes(&item_struct); + let actual = check_attributes(&derive_input); assert!(actual.is_ok()); } #[test] fn test_check_attrs_init_function_wrong_format() { - let item_struct: DeriveInput = syn::parse2(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshDeserialize, Debug)] #[borsh(init_func = initialization_method)] struct A<'a> { @@ -295,23 +290,22 @@ mod tests { v: Vec, } - }) - .unwrap(); - let actual = check_attributes(&item_struct); + }; + let actual = check_attributes(&derive_input); local_insta_assert_debug_snapshot!(actual.unwrap_err()); } + #[test] fn test_init_function() { - let item_struct = syn::parse2::(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(init = initialization_method)] struct A<'a> { x: u64, } - }) - .unwrap(); + }; - let actual = contains_initialize_with(&item_struct.attrs); + let actual = contains_initialize_with(&derive_input.attrs); assert_eq!( actual.unwrap().to_token_stream().to_string(), "initialization_method" @@ -320,16 +314,15 @@ mod tests { #[test] fn test_init_function_parsing_error() { - let item_struct = syn::parse2::(quote! { + let derive_input: DeriveInput = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(init={strange; blocky})] struct A { lazy: Option, } - }) - .unwrap(); + }; - let actual = contains_initialize_with(&item_struct.attrs); + let actual = contains_initialize_with(&derive_input.attrs); let err = match actual { Ok(..) => unreachable!("expecting error here"), Err(err) => err, @@ -339,7 +332,7 @@ mod tests { #[test] fn test_init_function_with_use_discriminant() { - let item_struct = syn::parse2::(quote! { + let item_enum: ItemEnum = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(init = initialization_method, use_discriminant=true)] enum A { @@ -347,21 +340,20 @@ mod tests { C, D, } - }) - .unwrap(); + }; - let actual = contains_initialize_with(&item_struct.attrs); + let actual = contains_initialize_with(&item_enum.attrs); assert_eq!( actual.unwrap().to_token_stream().to_string(), "initialization_method" ); - let actual = contains_use_discriminant(&item_struct); + let actual = contains_use_discriminant(&item_enum); assert!(actual.unwrap()); } #[test] fn test_init_function_with_use_discriminant_reversed() { - let item_struct = syn::parse2::(quote! { + let item_enum: ItemEnum = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(use_discriminant=true, init = initialization_method)] enum A { @@ -369,21 +361,20 @@ mod tests { C, D, } - }) - .unwrap(); + }; - let actual = contains_initialize_with(&item_struct.attrs); + let actual = contains_initialize_with(&item_enum.attrs); assert_eq!( actual.unwrap().to_token_stream().to_string(), "initialization_method" ); - let actual = contains_use_discriminant(&item_struct); + let actual = contains_use_discriminant(&item_enum); assert!(actual.unwrap()); } #[test] fn test_init_function_with_use_discriminant_with_crate() { - let item_struct = syn::parse2::(quote! { + let item_enum: ItemEnum = parse_quote! { #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(init = initialization_method, crate = "reexporter::borsh", use_discriminant=true)] enum A { @@ -391,18 +382,17 @@ mod tests { C, D, } - }) - .unwrap(); + }; - let actual = contains_initialize_with(&item_struct.attrs); + let actual = contains_initialize_with(&item_enum.attrs); assert_eq!( actual.unwrap().to_token_stream().to_string(), "initialization_method" ); - let actual = contains_use_discriminant(&item_struct); + let actual = contains_use_discriminant(&item_enum); assert!(actual.unwrap()); - let crate_ = get_crate(&item_struct.attrs); + let crate_ = get_crate(&item_enum.attrs); assert_eq!( crate_.unwrap().to_token_stream().to_string(), "reexporter :: borsh" diff --git a/borsh-derive/src/internals/deserialize/enums/mod.rs b/borsh-derive/src/internals/deserialize/enums/mod.rs index fb405e90d..77e5adff5 100644 --- a/borsh-derive/src/internals/deserialize/enums/mod.rs +++ b/borsh-derive/src/internals/deserialize/enums/mod.rs @@ -1,6 +1,6 @@ -use proc_macro2::TokenStream as TokenStream2; +use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; -use syn::{Fields, ItemEnum, Path, Variant}; +use syn::{Fields, ItemEnum, Path, Token, Variant}; use crate::internals::{attributes::item, deserialize, enum_discriminant::Discriminants, generics}; @@ -23,13 +23,9 @@ pub fn process(input: &ItemEnum, cratename: Path) -> syn::Result { if variant_tag == #discriminant_value { #name::#variant_ident #variant_body } else }); } - let init = if let Some(method_ident) = item::contains_initialize_with(&input.attrs)? { - quote! { - return_value.#method_ident(); - } - } else { - quote! {} - }; + let init = item::contains_initialize_with(&input.attrs)? + .map(|method_ident| quote! { return_value.#method_ident(); }); + let r#mut = init.is_some().then(|| Token![mut](Span::call_site())); generics_output.extend(&mut where_clause, &cratename); Ok(quote! { @@ -45,15 +41,15 @@ pub fn process(input: &ItemEnum, cratename: Path) -> syn::Result { reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = + let #r#mut return_value = #variant_arms { - return Err(#cratename::io::Error::new( + return ::core::result::Result::Err(#cratename::io::Error::new( #cratename::io::ErrorKind::InvalidData, #cratename::__private::maybestd::format!("Unexpected variant tag: {:?}", variant_tag), )) }; #init - Ok(return_value) + ::core::result::Result::Ok(return_value) } } }) @@ -70,13 +66,13 @@ fn process_variant( for field in &fields.named { deserialize::process_field(field, cratename, &mut body, generics)?; } - body = quote! { { #body }}; + body = quote! {{ #body }}; } Fields::Unnamed(fields) => { - for field in fields.unnamed.iter() { + for field in &fields.unnamed { deserialize::process_field(field, cratename, &mut body, generics)?; } - body = quote! { ( #body )}; + body = quote! {( #body )}; } Fields::Unit => {} } @@ -88,12 +84,13 @@ mod tests { use crate::internals::test_helpers::{ default_cratename, local_insta_assert_snapshot, pretty_print_syn_str, }; + use syn::parse_quote; use super::*; #[test] fn borsh_skip_struct_variant_field() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum AA { B { #[borsh(skip)] @@ -104,8 +101,7 @@ mod tests { beta: u8, } } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -113,7 +109,7 @@ mod tests { #[test] fn borsh_skip_tuple_variant_field() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum AAT { B(#[borsh(skip)] i32, u32), @@ -121,8 +117,7 @@ mod tests { beta: u8, } } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -130,7 +125,7 @@ mod tests { #[test] fn simple_enum_with_custom_crate() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { B { x: HashMap, @@ -138,17 +133,16 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let crate_: Path = syn::parse2(quote! { reexporter::borsh }).unwrap(); - let actual = process(&item_struct, crate_).unwrap(); + let crate_: Path = parse_quote! { reexporter::borsh }; + let actual = process(&item_enum, crate_).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn simple_generics() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { B { x: HashMap, @@ -156,16 +150,15 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn bound_generics() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { x: HashMap, @@ -173,16 +166,15 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn recursive_enum() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { x: HashMap, @@ -190,16 +182,15 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn generic_borsh_skip_struct_field() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { #[borsh(skip)] @@ -208,17 +199,16 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn generic_borsh_skip_tuple_field() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { x: HashMap, @@ -226,17 +216,16 @@ mod tests { }, C(K, #[borsh(skip)] Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn generic_deserialize_bound() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { C { a: String, @@ -248,17 +237,16 @@ mod tests { }, D(u32, u32), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn check_deserialize_with_attr() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum C { C3(u64, u64), C4 { @@ -267,17 +255,16 @@ mod tests { y: ThirdParty }, } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn borsh_discriminant_false() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[borsh(use_discriminant = false)] enum X { A, @@ -287,15 +274,15 @@ mod tests { E = 10, F, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } + #[test] fn borsh_discriminant_true() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[borsh(use_discriminant = true)] enum X { A, @@ -305,15 +292,14 @@ mod tests { E = 10, F, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn borsh_init_func() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[borsh(init = initialization_method)] enum A { A, @@ -323,8 +309,7 @@ mod tests { E, F, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_discriminant_false.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_discriminant_false.snap index 1e0446681..cc76362a3 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_discriminant_false.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_discriminant_false.snap @@ -15,7 +15,7 @@ impl borsh::de::EnumExt for X { reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { X::A } else if variant_tag == 1u8 { X::B @@ -28,7 +28,7 @@ impl borsh::de::EnumExt for X { } else if variant_tag == 5u8 { X::F } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -37,6 +37,6 @@ impl borsh::de::EnumExt for X { ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_discriminant_true.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_discriminant_true.snap index add0f62ed..4b4f60e9c 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_discriminant_true.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_discriminant_true.snap @@ -15,7 +15,7 @@ impl borsh::de::EnumExt for X { reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0 { + let return_value = if variant_tag == 0 { X::A } else if variant_tag == 20 { X::B @@ -28,7 +28,7 @@ impl borsh::de::EnumExt for X { } else if variant_tag == 10 + 1 { X::F } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -37,6 +37,6 @@ impl borsh::de::EnumExt for X { ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_init_func.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_init_func.snap index 28dd7dbce..7332b0025 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_init_func.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_init_func.snap @@ -28,7 +28,7 @@ impl borsh::de::EnumExt for A { } else if variant_tag == 5u8 { A::F } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -38,6 +38,6 @@ impl borsh::de::EnumExt for A { ) }; return_value.initialization_method(); - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_skip_struct_variant_field.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_skip_struct_variant_field.snap index a8a2d9e1a..63b6d2ba8 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_skip_struct_variant_field.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_skip_struct_variant_field.snap @@ -2,7 +2,10 @@ source: borsh-derive/src/internals/deserialize/enums/mod.rs expression: pretty_print_syn_str(&actual).unwrap() --- -impl borsh::de::BorshDeserialize for AA { +impl borsh::de::BorshDeserialize for AA +where + i32: ::core::default::Default, +{ fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { @@ -10,22 +13,25 @@ impl borsh::de::BorshDeserialize for AA { ::deserialize_variant(reader, tag) } } -impl borsh::de::EnumExt for AA { +impl borsh::de::EnumExt for AA +where + i32: ::core::default::Default, +{ fn deserialize_variant<__R: borsh::io::Read>( reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { AA::B { - c: core::default::Default::default(), - d: borsh::BorshDeserialize::deserialize_reader(reader)?, + c: ::core::default::Default::default(), + d: ::deserialize_reader(reader)?, } } else if variant_tag == 1u8 { AA::NegatedVariant { - beta: borsh::BorshDeserialize::deserialize_reader(reader)?, + beta: ::deserialize_reader(reader)?, } } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -34,6 +40,6 @@ impl borsh::de::EnumExt for AA { ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_skip_tuple_variant_field.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_skip_tuple_variant_field.snap index 60149fc60..57f8b11cd 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_skip_tuple_variant_field.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/borsh_skip_tuple_variant_field.snap @@ -2,7 +2,10 @@ source: borsh-derive/src/internals/deserialize/enums/mod.rs expression: pretty_print_syn_str(&actual).unwrap() --- -impl borsh::de::BorshDeserialize for AAT { +impl borsh::de::BorshDeserialize for AAT +where + i32: ::core::default::Default, +{ fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { @@ -10,22 +13,25 @@ impl borsh::de::BorshDeserialize for AAT { ::deserialize_variant(reader, tag) } } -impl borsh::de::EnumExt for AAT { +impl borsh::de::EnumExt for AAT +where + i32: ::core::default::Default, +{ fn deserialize_variant<__R: borsh::io::Read>( reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { AAT::B( - core::default::Default::default(), - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::default::Default::default(), + ::deserialize_reader(reader)?, ) } else if variant_tag == 1u8 { AAT::NegatedVariant { - beta: borsh::BorshDeserialize::deserialize_reader(reader)?, + beta: ::deserialize_reader(reader)?, } } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -34,6 +40,6 @@ impl borsh::de::EnumExt for AAT { ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/bound_generics.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/bound_generics.snap index 6b31f4bc6..38e6caa60 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/bound_generics.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/bound_generics.snap @@ -27,18 +27,21 @@ where reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { A::B { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + x: as borsh::BorshDeserialize>::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, } } else if variant_tag == 1u8 { A::C( - borsh::BorshDeserialize::deserialize_reader(reader)?, - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, + as borsh::BorshDeserialize>::deserialize_reader(reader)?, ) } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -47,6 +50,6 @@ where ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/check_deserialize_with_attr.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/check_deserialize_with_attr.snap index 968e0c3b5..8d92322bd 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/check_deserialize_with_attr.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/check_deserialize_with_attr.snap @@ -23,18 +23,18 @@ where reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { C::C3( - borsh::BorshDeserialize::deserialize_reader(reader)?, - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, ) } else if variant_tag == 1u8 { C::C4 { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, + x: ::deserialize_reader(reader)?, y: third_party_impl::deserialize_third_party(reader)?, } } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -43,6 +43,6 @@ where ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/generic_borsh_skip_struct_field.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/generic_borsh_skip_struct_field.snap index cde62e488..8540e0d2a 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/generic_borsh_skip_struct_field.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/generic_borsh_skip_struct_field.snap @@ -7,8 +7,7 @@ where V: Value, K: borsh::de::BorshDeserialize, U: borsh::de::BorshDeserialize, - K: core::default::Default, - V: core::default::Default, + HashMap: ::core::default::Default, { fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, @@ -22,25 +21,24 @@ where V: Value, K: borsh::de::BorshDeserialize, U: borsh::de::BorshDeserialize, - K: core::default::Default, - V: core::default::Default, + HashMap: ::core::default::Default, { fn deserialize_variant<__R: borsh::io::Read>( reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { A::B { - x: core::default::Default::default(), - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + x: ::core::default::Default::default(), + y: ::deserialize_reader(reader)?, } } else if variant_tag == 1u8 { A::C( - borsh::BorshDeserialize::deserialize_reader(reader)?, - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, + as borsh::BorshDeserialize>::deserialize_reader(reader)?, ) } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -49,6 +47,6 @@ where ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/generic_borsh_skip_tuple_field.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/generic_borsh_skip_tuple_field.snap index 0cc108681..2cd494d42 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/generic_borsh_skip_tuple_field.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/generic_borsh_skip_tuple_field.snap @@ -7,7 +7,7 @@ where V: Value, K: borsh::de::BorshDeserialize, V: borsh::de::BorshDeserialize, - U: core::default::Default, + Vec: ::core::default::Default, { fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, @@ -21,24 +21,27 @@ where V: Value, K: borsh::de::BorshDeserialize, V: borsh::de::BorshDeserialize, - U: core::default::Default, + Vec: ::core::default::Default, { fn deserialize_variant<__R: borsh::io::Read>( reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { A::B { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + x: as borsh::BorshDeserialize>::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, } } else if variant_tag == 1u8 { A::C( - borsh::BorshDeserialize::deserialize_reader(reader)?, - core::default::Default::default(), + ::deserialize_reader(reader)?, + ::core::default::Default::default(), ) } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -47,6 +50,6 @@ where ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/generic_deserialize_bound.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/generic_deserialize_bound.snap index adf641118..fb1f01553 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/generic_deserialize_bound.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/generic_deserialize_bound.snap @@ -23,18 +23,21 @@ where reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { A::C { - a: borsh::BorshDeserialize::deserialize_reader(reader)?, - b: borsh::BorshDeserialize::deserialize_reader(reader)?, + a: ::deserialize_reader(reader)?, + b: as borsh::BorshDeserialize>::deserialize_reader(reader)?, } } else if variant_tag == 1u8 { A::D( - borsh::BorshDeserialize::deserialize_reader(reader)?, - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, ) } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -43,6 +46,6 @@ where ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/recursive_enum.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/recursive_enum.snap index b3c8f7790..f2d247805 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/recursive_enum.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/recursive_enum.snap @@ -25,18 +25,21 @@ where reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { A::B { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + x: as borsh::BorshDeserialize>::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, } } else if variant_tag == 1u8 { A::C( - borsh::BorshDeserialize::deserialize_reader(reader)?, - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, + as borsh::BorshDeserialize>::deserialize_reader(reader)?, ) } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -45,6 +48,6 @@ where ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/simple_enum_with_custom_crate.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/simple_enum_with_custom_crate.snap index 88457ee99..38c7627ab 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/simple_enum_with_custom_crate.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/simple_enum_with_custom_crate.snap @@ -17,18 +17,25 @@ impl reexporter::borsh::de::EnumExt for A { reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { A::B { - x: reexporter::borsh::BorshDeserialize::deserialize_reader(reader)?, - y: reexporter::borsh::BorshDeserialize::deserialize_reader(reader)?, + x: as reexporter::borsh::BorshDeserialize>::deserialize_reader(reader)?, + y: ::deserialize_reader( + reader, + )?, } } else if variant_tag == 1u8 { A::C( - reexporter::borsh::BorshDeserialize::deserialize_reader(reader)?, - reexporter::borsh::BorshDeserialize::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, + as reexporter::borsh::BorshDeserialize>::deserialize_reader(reader)?, ) } else { - return Err( + return ::core::result::Result::Err( reexporter::borsh::io::Error::new( reexporter::borsh::io::ErrorKind::InvalidData, reexporter::borsh::__private::maybestd::format!( @@ -37,6 +44,6 @@ impl reexporter::borsh::de::EnumExt for A { ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/enums/snapshots/simple_generics.snap b/borsh-derive/src/internals/deserialize/enums/snapshots/simple_generics.snap index d8b85259c..eaa228428 100644 --- a/borsh-derive/src/internals/deserialize/enums/snapshots/simple_generics.snap +++ b/borsh-derive/src/internals/deserialize/enums/snapshots/simple_generics.snap @@ -25,18 +25,21 @@ where reader: &mut __R, variant_tag: u8, ) -> ::core::result::Result { - let mut return_value = if variant_tag == 0u8 { + let return_value = if variant_tag == 0u8 { A::B { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + x: as borsh::BorshDeserialize>::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, } } else if variant_tag == 1u8 { A::C( - borsh::BorshDeserialize::deserialize_reader(reader)?, - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, + as borsh::BorshDeserialize>::deserialize_reader(reader)?, ) } else { - return Err( + return ::core::result::Result::Err( borsh::io::Error::new( borsh::io::ErrorKind::InvalidData, borsh::__private::maybestd::format!( @@ -45,6 +48,6 @@ where ), ) }; - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/mod.rs b/borsh-derive/src/internals/deserialize/mod.rs index 9133b26d6..0de55ddee 100644 --- a/borsh-derive/src/internals/deserialize/mod.rs +++ b/borsh-derive/src/internals/deserialize/mod.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use syn::{parse_quote, ExprPath, Generics, Ident, Path, Type}; +use syn::{parse_quote, ExprPath, Generics, Ident, Path, Type, TypeGroup}; use super::{ attributes::{field, BoundType}, @@ -13,7 +13,7 @@ pub mod unions; struct GenericsOutput { overrides: Vec, - default_visitor: generics::FindTyParams, + skipped_fields_types: Vec, deserialize_visitor: generics::FindTyParams, } @@ -21,8 +21,8 @@ impl GenericsOutput { fn new(generics: &Generics) -> Self { Self { overrides: vec![], + skipped_fields_types: vec![], deserialize_visitor: generics::FindTyParams::new(generics), - default_visitor: generics::FindTyParams::new(generics), } } @@ -32,7 +32,7 @@ impl GenericsOutput { let de_predicates = generics::compute_predicates(self.deserialize_visitor.process_for_bounds(), &de_trait); let default_predicates = - generics::compute_predicates(self.default_visitor.process_for_bounds(), &default_trait); // FIXME: this is not correct, the `Default` trait should be requested for field types, rather than their type parameters + generics::compute_predicates(self.skipped_fields_types, &default_trait); where_clause.predicates.extend(de_predicates); where_clause.predicates.extend(default_predicates); where_clause.predicates.extend(self.overrides); @@ -55,7 +55,11 @@ fn process_field( let field_name = field.ident.as_ref(); let delta = if parsed.skip { if needs_bounds_derive { - generics.default_visitor.visit_field(field); + let mut ty = &field.ty; + while let Type::Group(TypeGroup { elem, .. }) = ty { + ty = elem; + } + generics.skipped_fields_types.push(ty.clone()); } field_default_output(field_name) } else { diff --git a/borsh-derive/src/internals/deserialize/structs/mod.rs b/borsh-derive/src/internals/deserialize/structs/mod.rs index 0faaec309..60a256444 100644 --- a/borsh-derive/src/internals/deserialize/structs/mod.rs +++ b/borsh-derive/src/internals/deserialize/structs/mod.rs @@ -17,45 +17,35 @@ pub fn process(input: &ItemStruct, cratename: Path) -> syn::Result for field in &fields.named { deserialize::process_field(field, &cratename, &mut body, &mut generics_output)?; } - quote! { - Self { #body } - } + quote! { Self { #body } } } Fields::Unnamed(fields) => { for field in fields.unnamed.iter() { deserialize::process_field(field, &cratename, &mut body, &mut generics_output)?; } - quote! { - Self( #body ) - } - } - Fields::Unit => { - quote! { - Self {} - } + quote! { Self( #body ) } } + Fields::Unit => quote! { Self {} }, }; generics_output.extend(&mut where_clause, &cratename); - if let Some(method_ident) = item::contains_initialize_with(&input.attrs)? { - Ok(quote! { - impl #impl_generics #cratename::de::BorshDeserialize for #name #ty_generics #where_clause { - fn deserialize_reader<__R: #cratename::io::Read>(reader: &mut __R) -> ::core::result::Result { - let mut return_value = #return_value; - return_value.#method_ident(); - Ok(return_value) - } - } - }) + let body = if let Some(method_ident) = item::contains_initialize_with(&input.attrs)? { + quote! { + let mut return_value = #return_value; + return_value.#method_ident(); + ::core::result::Result::Ok(return_value) + } } else { - Ok(quote! { - impl #impl_generics #cratename::de::BorshDeserialize for #name #ty_generics #where_clause { - fn deserialize_reader<__R: #cratename::io::Read>(reader: &mut __R) -> ::core::result::Result { - Ok(#return_value) - } + quote! { ::core::result::Result::Ok(#return_value) } + }; + + Ok(quote! { + impl #impl_generics #cratename::de::BorshDeserialize for #name #ty_generics #where_clause { + fn deserialize_reader<__R: #cratename::io::Read>(reader: &mut __R) -> ::core::result::Result { + #body } - }) - } + } + }) } #[cfg(test)] @@ -63,18 +53,18 @@ mod tests { use crate::internals::test_helpers::{ default_cratename, local_insta_assert_snapshot, pretty_print_syn_str, }; + use syn::parse_quote; use super::*; #[test] fn simple_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: u64, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -83,15 +73,14 @@ mod tests { #[test] fn simple_struct_with_custom_crate() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: u64, y: String, } - }) - .unwrap(); + }; - let crate_: Path = syn::parse2(quote! { reexporter::borsh }).unwrap(); + let crate_: Path = parse_quote! { reexporter::borsh }; let actual = process(&item_struct, crate_).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -99,13 +88,12 @@ mod tests { #[test] fn simple_generics() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: HashMap, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -113,10 +101,9 @@ mod tests { #[test] fn simple_generic_tuple_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct TupleA(T, u32); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -124,13 +111,12 @@ mod tests { #[test] fn bound_generics() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A where V: Value { x: HashMap, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -138,13 +124,12 @@ mod tests { #[test] fn recursive_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct CRecC { a: String, b: HashMap, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -153,14 +138,13 @@ mod tests { #[test] fn generic_tuple_struct_borsh_skip1() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G ( #[borsh(skip)] HashMap, U, ); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -169,14 +153,13 @@ mod tests { #[test] fn generic_tuple_struct_borsh_skip2() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G ( HashMap, #[borsh(skip)] U, ); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -185,14 +168,13 @@ mod tests { #[test] fn generic_named_fields_struct_borsh_skip() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G { #[borsh(skip)] x: HashMap, y: U, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -201,7 +183,7 @@ mod tests { #[test] fn generic_deserialize_bound() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct C { a: String, #[borsh(bound(deserialize = @@ -210,8 +192,7 @@ mod tests { ))] b: HashMap, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -220,14 +201,13 @@ mod tests { #[test] fn test_override_automatically_added_default_trait() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G1( #[borsh(skip,bound(deserialize = ""))] HashMap, U ); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -236,30 +216,29 @@ mod tests { #[test] fn check_deserialize_with_attr() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(deserialize_with = "third_party_impl::deserialize_third_party")] x: ThirdParty, y: u64, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } + #[test] fn borsh_init_func() { - let item_enum: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { #[borsh(init=initialization_method)] struct A { x: u64, y: String, } - }) - .unwrap(); - let actual = process(&item_enum, default_cratename()).unwrap(); + }; + let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/borsh_init_func.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/borsh_init_func.snap index 61f51e48e..e1f5c3ee6 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/borsh_init_func.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/borsh_init_func.snap @@ -7,10 +7,10 @@ impl borsh::de::BorshDeserialize for A { reader: &mut __R, ) -> ::core::result::Result { let mut return_value = Self { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + x: ::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, }; return_value.initialization_method(); - Ok(return_value) + ::core::result::Result::Ok(return_value) } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/bound_generics.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/bound_generics.snap index dc4514d64..cef97c63b 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/bound_generics.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/bound_generics.snap @@ -11,9 +11,9 @@ where fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok(Self { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::result::Result::Ok(Self { + x: as borsh::BorshDeserialize>::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, }) } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/check_deserialize_with_attr.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/check_deserialize_with_attr.snap index 79a844803..e6f59c5e7 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/check_deserialize_with_attr.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/check_deserialize_with_attr.snap @@ -10,9 +10,9 @@ where fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok(Self { + ::core::result::Result::Ok(Self { x: third_party_impl::deserialize_third_party(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, }) } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/generic_deserialize_bound.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/generic_deserialize_bound.snap index 7e4a0317b..ca1a130a7 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/generic_deserialize_bound.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/generic_deserialize_bound.snap @@ -10,9 +10,9 @@ where fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok(Self { - a: borsh::BorshDeserialize::deserialize_reader(reader)?, - b: borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::result::Result::Ok(Self { + a: ::deserialize_reader(reader)?, + b: as borsh::BorshDeserialize>::deserialize_reader(reader)?, }) } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/generic_named_fields_struct_borsh_skip.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/generic_named_fields_struct_borsh_skip.snap index c094081c6..e4214e4ee 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/generic_named_fields_struct_borsh_skip.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/generic_named_fields_struct_borsh_skip.snap @@ -5,15 +5,14 @@ expression: pretty_print_syn_str(&actual).unwrap() impl borsh::de::BorshDeserialize for G where U: borsh::de::BorshDeserialize, - K: core::default::Default, - V: core::default::Default, + HashMap: ::core::default::Default, { fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok(Self { - x: core::default::Default::default(), - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::result::Result::Ok(Self { + x: ::core::default::Default::default(), + y: ::deserialize_reader(reader)?, }) } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/generic_tuple_struct_borsh_skip1.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/generic_tuple_struct_borsh_skip1.snap index 492cc2b14..7a22794f8 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/generic_tuple_struct_borsh_skip1.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/generic_tuple_struct_borsh_skip1.snap @@ -5,16 +5,15 @@ expression: pretty_print_syn_str(&actual).unwrap() impl borsh::de::BorshDeserialize for G where U: borsh::de::BorshDeserialize, - K: core::default::Default, - V: core::default::Default, + HashMap: ::core::default::Default, { fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok( + ::core::result::Result::Ok( Self( - core::default::Default::default(), - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::default::Default::default(), + ::deserialize_reader(reader)?, ), ) } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/generic_tuple_struct_borsh_skip2.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/generic_tuple_struct_borsh_skip2.snap index 5abdae6be..77e5c0a83 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/generic_tuple_struct_borsh_skip2.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/generic_tuple_struct_borsh_skip2.snap @@ -6,15 +6,15 @@ impl borsh::de::BorshDeserialize for G where K: borsh::de::BorshDeserialize, V: borsh::de::BorshDeserialize, - U: core::default::Default, + U: ::core::default::Default, { fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok( + ::core::result::Result::Ok( Self( - borsh::BorshDeserialize::deserialize_reader(reader)?, - core::default::Default::default(), + as borsh::BorshDeserialize>::deserialize_reader(reader)?, + ::core::default::Default::default(), ), ) } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/override_automatically_added_default_trait.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/override_automatically_added_default_trait.snap index 546931471..21985b2f9 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/override_automatically_added_default_trait.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/override_automatically_added_default_trait.snap @@ -9,10 +9,10 @@ where fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok( + ::core::result::Result::Ok( Self( - core::default::Default::default(), - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::default::Default::default(), + ::deserialize_reader(reader)?, ), ) } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/recursive_struct.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/recursive_struct.snap index 0dd795c39..05ccdda53 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/recursive_struct.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/recursive_struct.snap @@ -6,9 +6,12 @@ impl borsh::de::BorshDeserialize for CRecC { fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok(Self { - a: borsh::BorshDeserialize::deserialize_reader(reader)?, - b: borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::result::Result::Ok(Self { + a: ::deserialize_reader(reader)?, + b: as borsh::BorshDeserialize>::deserialize_reader(reader)?, }) } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/simple_generic_tuple_struct.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/simple_generic_tuple_struct.snap index c1d69d951..3af146c3b 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/simple_generic_tuple_struct.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/simple_generic_tuple_struct.snap @@ -9,10 +9,10 @@ where fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok( + ::core::result::Result::Ok( Self( - borsh::BorshDeserialize::deserialize_reader(reader)?, - borsh::BorshDeserialize::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, + ::deserialize_reader(reader)?, ), ) } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/simple_generics.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/simple_generics.snap index f2a8c7c4b..01378a58e 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/simple_generics.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/simple_generics.snap @@ -10,9 +10,9 @@ where fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok(Self { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::result::Result::Ok(Self { + x: as borsh::BorshDeserialize>::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, }) } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/simple_struct.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/simple_struct.snap index 6026d09f0..2a4acfcd4 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/simple_struct.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/simple_struct.snap @@ -6,9 +6,9 @@ impl borsh::de::BorshDeserialize for A { fn deserialize_reader<__R: borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok(Self { - x: borsh::BorshDeserialize::deserialize_reader(reader)?, - y: borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::result::Result::Ok(Self { + x: ::deserialize_reader(reader)?, + y: ::deserialize_reader(reader)?, }) } } diff --git a/borsh-derive/src/internals/deserialize/structs/snapshots/simple_struct_with_custom_crate.snap b/borsh-derive/src/internals/deserialize/structs/snapshots/simple_struct_with_custom_crate.snap index ad7fb3788..be14dc1a4 100644 --- a/borsh-derive/src/internals/deserialize/structs/snapshots/simple_struct_with_custom_crate.snap +++ b/borsh-derive/src/internals/deserialize/structs/snapshots/simple_struct_with_custom_crate.snap @@ -6,9 +6,11 @@ impl reexporter::borsh::de::BorshDeserialize for A { fn deserialize_reader<__R: reexporter::borsh::io::Read>( reader: &mut __R, ) -> ::core::result::Result { - Ok(Self { - x: reexporter::borsh::BorshDeserialize::deserialize_reader(reader)?, - y: reexporter::borsh::BorshDeserialize::deserialize_reader(reader)?, + ::core::result::Result::Ok(Self { + x: ::deserialize_reader(reader)?, + y: ::deserialize_reader( + reader, + )?, }) } } diff --git a/borsh-derive/src/internals/generics.rs b/borsh-derive/src/internals/generics.rs index e3cf67d17..0db55fded 100644 --- a/borsh-derive/src/internals/generics.rs +++ b/borsh-derive/src/internals/generics.rs @@ -166,6 +166,7 @@ impl FindTyParams { } impl FindTyParams { + /// Visits the filed to collect its type parameters pub fn visit_field(&mut self, field: &Field) { self.visit_type_top_level(&field.ty); } diff --git a/borsh-derive/src/internals/schema/enums/mod.rs b/borsh-derive/src/internals/schema/enums/mod.rs index 95bbed06b..3b73529c6 100644 --- a/borsh-derive/src/internals/schema/enums/mod.rs +++ b/borsh-derive/src/internals/schema/enums/mod.rs @@ -185,18 +185,18 @@ mod tests { default_cratename, local_insta_assert_debug_snapshot, local_insta_assert_snapshot, pretty_print_syn_str, }; + use syn::parse_quote; use super::*; #[test] fn simple_enum() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { Bacon, Eggs } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); @@ -205,15 +205,14 @@ mod tests { #[test] fn simple_enum_with_custom_crate() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { Bacon, Eggs } - }) - .unwrap(); + }; - let crate_: Path = syn::parse2(quote! { reexporter::borsh }).unwrap(); + let crate_: Path = parse_quote! { reexporter::borsh }; let actual = process(&item_enum, crate_).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -221,7 +220,7 @@ mod tests { #[test] fn borsh_discriminant_false() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[borsh(use_discriminant = false)] enum X { A, @@ -231,15 +230,14 @@ mod tests { E = 10, F, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn borsh_discriminant_true() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[borsh(use_discriminant = true)] enum X { A, @@ -249,8 +247,7 @@ mod tests { E = 10, F, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -258,12 +255,11 @@ mod tests { #[test] fn single_field_enum() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { Bacon, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -271,15 +267,14 @@ mod tests { #[test] fn complex_enum() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { Bacon, Eggs, Salad(Tomatoes, Cucumber, Oil), Sausage{wrapper: Wrapper, filling: Filling}, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -287,15 +282,14 @@ mod tests { #[test] fn complex_enum_generics() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { Bacon, Eggs, Salad(Tomatoes, C, Oil), Sausage{wrapper: W, filling: Filling}, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -303,7 +297,7 @@ mod tests { #[test] fn trailing_comma_generics() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum Side where A: Display + Debug, @@ -312,16 +306,15 @@ mod tests { Left(A), Right(B), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn test_filter_foreign_attrs() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { #[serde(rename = "ab")] B { @@ -335,25 +328,23 @@ mod tests { beta: String, } } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn complex_enum_generics_borsh_skip_tuple_field() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where W: Hash { Bacon, Eggs, Salad(Tomatoes, #[borsh(skip)] C, Oil), Sausage{wrapper: W, filling: Filling}, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -361,7 +352,7 @@ mod tests { #[test] fn complex_enum_generics_borsh_skip_named_field() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { Bacon, Eggs, @@ -373,8 +364,7 @@ mod tests { unexpected: U, }, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -382,7 +372,7 @@ mod tests { #[test] fn recursive_enum() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { x: HashMap, @@ -390,17 +380,16 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn generic_associated_type() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum EnumParametrized where K: TraitName, @@ -415,16 +404,16 @@ mod tests { }, C(T, u16), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } + #[test] fn generic_associated_type_param_override() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum EnumParametrized where K: TraitName, @@ -440,17 +429,16 @@ mod tests { }, C(T, u16), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn generic_associated_type_param_override_conflict() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum EnumParametrized where K: TraitName, @@ -462,17 +450,16 @@ mod tests { }, C(T, u16), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()); + let actual = process(&item_enum, default_cratename()); local_insta_assert_debug_snapshot!(actual.unwrap_err()); } #[test] fn check_with_funcs_skip_conflict() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum C { C3(u64, u64), C4( @@ -484,17 +471,16 @@ mod tests { ThirdParty, ), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()); + let actual = process(&item_enum, default_cratename()); local_insta_assert_debug_snapshot!(actual.unwrap_err()); } #[test] fn with_funcs_attr() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum C { C3(u64, u64), C4( @@ -506,10 +492,9 @@ mod tests { ThirdParty, ), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } diff --git a/borsh-derive/src/internals/schema/mod.rs b/borsh-derive/src/internals/schema/mod.rs index b094a4452..94cbf8186 100644 --- a/borsh-derive/src/internals/schema/mod.rs +++ b/borsh-derive/src/internals/schema/mod.rs @@ -2,10 +2,7 @@ use std::collections::HashSet; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use syn::{ - punctuated::Punctuated, token::Comma, Field, Fields, GenericParam, Generics, Ident, Path, Type, - WherePredicate, -}; +use syn::{parse_quote, punctuated::Punctuated, token::Comma, Field, Fields, GenericParam, Generics, Ident, Path, Type, WherePredicate}; use crate::internals::{attributes::field, generics}; @@ -23,7 +20,7 @@ impl GenericsOutput { } } fn result(self, item_name: &str, cratename: &Path) -> (Vec, TokenStream2) { - let trait_path: Path = syn::parse2(quote! { #cratename::BorshSchema }).unwrap(); + let trait_path: Path = parse_quote! { #cratename::BorshSchema }; let predicates = generics::compute_predicates( self.params_visitor.clone().process_for_bounds(), &trait_path, diff --git a/borsh-derive/src/internals/schema/structs/mod.rs b/borsh-derive/src/internals/schema/structs/mod.rs index 8e388430f..0c21c32ff 100644 --- a/borsh-derive/src/internals/schema/structs/mod.rs +++ b/borsh-derive/src/internals/schema/structs/mod.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream as TokenStream2; use quote::{quote, ToTokens}; -use syn::{ExprPath, Fields, Ident, ItemStruct, Path, Type}; +use syn::{parse_quote, ExprPath, Fields, Ident, ItemStruct, Path, Type}; use crate::internals::{attributes::field, generics, schema}; @@ -14,7 +14,7 @@ fn field_declaration_output( declaration_override: Option, ) -> TokenStream2 { let default_path: ExprPath = - syn::parse2(quote! { <#field_type as #cratename::BorshSchema>::declaration }).unwrap(); + parse_quote! { <#field_type as #cratename::BorshSchema>::declaration }; let path = declaration_override.unwrap_or(default_path); @@ -171,10 +171,9 @@ mod tests { #[test] fn unit_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A; - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -182,10 +181,9 @@ mod tests { #[test] fn wrapper_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A(T); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -193,10 +191,9 @@ mod tests { #[test] fn tuple_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A(u64, String); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -204,10 +201,9 @@ mod tests { #[test] fn tuple_struct_params() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A(K, V); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -215,13 +211,12 @@ mod tests { #[test] fn simple_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: u64, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -229,28 +224,26 @@ mod tests { #[test] fn simple_struct_with_custom_crate() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: u64, y: String, } - }) - .unwrap(); + }; - let crate_: Path = syn::parse2(quote! { reexporter::borsh }).unwrap(); + let crate_: Path = parse_quote! { reexporter::borsh }; let actual = process(&item_struct, crate_).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn simple_generics() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: HashMap, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -258,7 +251,7 @@ mod tests { #[test] fn trailing_comma_generics() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A where K: Display + Debug, @@ -266,8 +259,7 @@ mod tests { x: HashMap, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -275,10 +267,9 @@ mod tests { #[test] fn tuple_struct_whole_skip() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A(#[borsh(skip)] String); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -286,10 +277,9 @@ mod tests { #[test] fn tuple_struct_partial_skip() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A(#[borsh(skip)] u64, String); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -297,14 +287,13 @@ mod tests { #[test] fn generic_tuple_struct_borsh_skip1() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G ( #[borsh(skip)] HashMap, U, ); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -313,14 +302,13 @@ mod tests { #[test] fn generic_tuple_struct_borsh_skip2() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G ( HashMap, #[borsh(skip)] U, ); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -329,15 +317,14 @@ mod tests { #[test] fn generic_tuple_struct_borsh_skip3() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G ( #[borsh(skip)] HashMap, U, K, ); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -346,10 +333,9 @@ mod tests { #[test] fn generic_tuple_struct_borsh_skip4() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct ASalad(Tomatoes, #[borsh(skip)] C, Oil); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -358,14 +344,13 @@ mod tests { #[test] fn generic_named_fields_struct_borsh_skip() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G { #[borsh(skip)] x: HashMap, y: U, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -374,13 +359,12 @@ mod tests { #[test] fn recursive_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct CRecC { a: String, b: HashMap, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -389,7 +373,7 @@ mod tests { #[test] fn generic_associated_type() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -397,8 +381,7 @@ mod tests { field: T::Associated, another: V, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -407,7 +390,7 @@ mod tests { #[test] fn generic_associated_type_param_override() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -418,8 +401,7 @@ mod tests { field: ::Associated, another: V, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -428,7 +410,7 @@ mod tests { #[test] fn generic_associated_type_param_override2() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -439,8 +421,7 @@ mod tests { field: (::Associated, T), another: V, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -449,7 +430,7 @@ mod tests { #[test] fn generic_associated_type_param_override_conflict() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -460,8 +441,7 @@ mod tests { field: ::Associated, another: V, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()); @@ -470,7 +450,7 @@ mod tests { #[test] fn check_with_funcs_skip_conflict() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(skip,schema(with_funcs( declaration = "third_party_impl::declaration::", @@ -479,8 +459,7 @@ mod tests { x: ThirdParty, y: u64, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()); @@ -489,7 +468,7 @@ mod tests { #[test] fn with_funcs_attr() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(schema(with_funcs( declaration = "third_party_impl::declaration::", @@ -498,8 +477,7 @@ mod tests { x: ThirdParty, y: u64, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -508,7 +486,7 @@ mod tests { #[test] fn schema_param_override3() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh( schema( @@ -518,8 +496,7 @@ mod tests { x: PrimaryMap, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); diff --git a/borsh-derive/src/internals/serialize/enums/mod.rs b/borsh-derive/src/internals/serialize/enums/mod.rs index 4e86ca2d4..b855afa6f 100644 --- a/borsh-derive/src/internals/serialize/enums/mod.rs +++ b/borsh-derive/src/internals/serialize/enums/mod.rs @@ -52,7 +52,7 @@ pub fn process(input: &ItemEnum, cratename: Path) -> syn::Result { writer.write_all(&variant_idx.to_le_bytes())?; #fields_body - Ok(()) + ::core::result::Result::Ok(()) } } }) @@ -202,11 +202,12 @@ mod tests { use crate::internals::test_helpers::{ default_cratename, local_insta_assert_snapshot, pretty_print_syn_str, }; + use syn::parse_quote; use super::*; #[test] fn borsh_skip_tuple_variant_field() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum AATTB { B(#[borsh(skip)] i32, #[borsh(skip)] u32), @@ -214,8 +215,7 @@ mod tests { beta: u8, } } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -223,7 +223,7 @@ mod tests { #[test] fn struct_variant_field() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum AB { B { c: i32, @@ -234,8 +234,7 @@ mod tests { beta: String, } } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); @@ -244,7 +243,7 @@ mod tests { #[test] fn simple_enum_with_custom_crate() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum AB { B { c: i32, @@ -255,10 +254,9 @@ mod tests { beta: String, } } - }) - .unwrap(); + }; - let crate_: Path = syn::parse2(quote! { reexporter::borsh }).unwrap(); + let crate_: Path = parse_quote! { reexporter::borsh }; let actual = process(&item_enum, crate_).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -266,7 +264,7 @@ mod tests { #[test] fn borsh_skip_struct_variant_field() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum AB { B { @@ -280,8 +278,7 @@ mod tests { beta: String, } } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); @@ -290,7 +287,7 @@ mod tests { #[test] fn borsh_skip_struct_variant_all_fields() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum AAB { B { @@ -305,8 +302,7 @@ mod tests { beta: String, } } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); @@ -315,7 +311,7 @@ mod tests { #[test] fn simple_generics() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { B { x: HashMap, @@ -323,16 +319,15 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn bound_generics() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { x: HashMap, @@ -340,16 +335,15 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn recursive_enum() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { x: HashMap, @@ -357,17 +351,16 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn generic_borsh_skip_struct_field() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { #[borsh(skip)] @@ -376,17 +369,16 @@ mod tests { }, C(K, Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn generic_borsh_skip_tuple_field() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A where V: Value { B { x: HashMap, @@ -394,17 +386,16 @@ mod tests { }, C(K, #[borsh(skip)] Vec), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn generic_serialize_bound() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum A { C { a: String, @@ -416,17 +407,16 @@ mod tests { }, D(u32, u32), } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn check_serialize_with_attr() { - let item_struct: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum C { C3(u64, u64), C4 { @@ -435,17 +425,16 @@ mod tests { y: ThirdParty }, } - }) - .unwrap(); + }; - let actual = process(&item_struct, default_cratename()).unwrap(); + let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } #[test] fn borsh_discriminant_false() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[borsh(use_discriminant = false)] enum X { A, @@ -455,15 +444,15 @@ mod tests { E = 10, F, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); } + #[test] fn borsh_discriminant_true() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { #[borsh(use_discriminant = true)] enum X { A, @@ -473,8 +462,7 @@ mod tests { E = 10, F, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -482,15 +470,14 @@ mod tests { #[test] fn mixed_with_unit_variants() { - let item_enum: ItemEnum = syn::parse2(quote! { + let item_enum: ItemEnum = parse_quote! { enum X { A(u16), B, C {x: i32, y: i32}, D, } - }) - .unwrap(); + }; let actual = process(&item_enum, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_discriminant_false.snap b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_discriminant_false.snap index 05e1f88e9..fa2df8a55 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_discriminant_false.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_discriminant_false.snap @@ -16,6 +16,6 @@ impl borsh::ser::BorshSerialize for X { X::F => 5u8, }; writer.write_all(&variant_idx.to_le_bytes())?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_discriminant_true.snap b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_discriminant_true.snap index ee3371232..423f30316 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_discriminant_true.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_discriminant_true.snap @@ -16,6 +16,6 @@ impl borsh::ser::BorshSerialize for X { X::F => 10 + 1, }; writer.write_all(&variant_idx.to_le_bytes())?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_struct_variant_all_fields.snap b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_struct_variant_all_fields.snap index b8943a467..77f36db64 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_struct_variant_all_fields.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_struct_variant_all_fields.snap @@ -18,6 +18,6 @@ impl borsh::ser::BorshSerialize for AAB { borsh::BorshSerialize::serialize(beta, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_struct_variant_field.snap b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_struct_variant_field.snap index f5ff6946d..eeeff99fc 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_struct_variant_field.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_struct_variant_field.snap @@ -20,6 +20,6 @@ impl borsh::ser::BorshSerialize for AB { borsh::BorshSerialize::serialize(beta, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_tuple_variant_field.snap b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_tuple_variant_field.snap index fc3be0087..b52bee283 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_tuple_variant_field.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/borsh_skip_tuple_variant_field.snap @@ -18,6 +18,6 @@ impl borsh::ser::BorshSerialize for AATTB { borsh::BorshSerialize::serialize(beta, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/bound_generics.snap b/borsh-derive/src/internals/serialize/enums/snapshots/bound_generics.snap index 9c1630967..7b9f5f46d 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/bound_generics.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/bound_generics.snap @@ -28,6 +28,6 @@ where borsh::BorshSerialize::serialize(id1, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/check_serialize_with_attr.snap b/borsh-derive/src/internals/serialize/enums/snapshots/check_serialize_with_attr.snap index 29f1619c1..2bbc7a90d 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/check_serialize_with_attr.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/check_serialize_with_attr.snap @@ -26,6 +26,6 @@ where third_party_impl::serialize_third_party(y, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/generic_borsh_skip_struct_field.snap b/borsh-derive/src/internals/serialize/enums/snapshots/generic_borsh_skip_struct_field.snap index 051033a64..82a500173 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/generic_borsh_skip_struct_field.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/generic_borsh_skip_struct_field.snap @@ -26,6 +26,6 @@ where borsh::BorshSerialize::serialize(id1, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/generic_borsh_skip_tuple_field.snap b/borsh-derive/src/internals/serialize/enums/snapshots/generic_borsh_skip_tuple_field.snap index 4f0ae41b7..416b4ab05 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/generic_borsh_skip_tuple_field.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/generic_borsh_skip_tuple_field.snap @@ -26,6 +26,6 @@ where borsh::BorshSerialize::serialize(id0, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/generic_serialize_bound.snap b/borsh-derive/src/internals/serialize/enums/snapshots/generic_serialize_bound.snap index 1e53690ec..e6615727a 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/generic_serialize_bound.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/generic_serialize_bound.snap @@ -26,6 +26,6 @@ where borsh::BorshSerialize::serialize(id1, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/mixed_with_unit_variants.snap b/borsh-derive/src/internals/serialize/enums/snapshots/mixed_with_unit_variants.snap index 69a56d5b9..a08708353 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/mixed_with_unit_variants.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/mixed_with_unit_variants.snap @@ -24,6 +24,6 @@ impl borsh::ser::BorshSerialize for X { } _ => {} } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/recursive_enum.snap b/borsh-derive/src/internals/serialize/enums/snapshots/recursive_enum.snap index d7aeab233..da07f723d 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/recursive_enum.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/recursive_enum.snap @@ -27,6 +27,6 @@ where borsh::BorshSerialize::serialize(id1, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/simple_enum_with_custom_crate.snap b/borsh-derive/src/internals/serialize/enums/snapshots/simple_enum_with_custom_crate.snap index fcfc55df6..e279b8d43 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/simple_enum_with_custom_crate.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/simple_enum_with_custom_crate.snap @@ -21,6 +21,6 @@ impl reexporter::borsh::ser::BorshSerialize for AB { reexporter::borsh::BorshSerialize::serialize(beta, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/simple_generics.snap b/borsh-derive/src/internals/serialize/enums/snapshots/simple_generics.snap index 70e2f6498..a4d642641 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/simple_generics.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/simple_generics.snap @@ -27,6 +27,6 @@ where borsh::BorshSerialize::serialize(id1, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/enums/snapshots/struct_variant_field.snap b/borsh-derive/src/internals/serialize/enums/snapshots/struct_variant_field.snap index 0ba345286..c6d4c4b7e 100644 --- a/borsh-derive/src/internals/serialize/enums/snapshots/struct_variant_field.snap +++ b/borsh-derive/src/internals/serialize/enums/snapshots/struct_variant_field.snap @@ -21,6 +21,6 @@ impl borsh::ser::BorshSerialize for AB { borsh::BorshSerialize::serialize(beta, writer)?; } } - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/mod.rs b/borsh-derive/src/internals/serialize/mod.rs index b4b7a20dc..aab983384 100644 --- a/borsh-derive/src/internals/serialize/mod.rs +++ b/borsh-derive/src/internals/serialize/mod.rs @@ -1,7 +1,7 @@ use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; use std::convert::TryFrom; -use syn::{Expr, ExprPath, Generics, Ident, Index, Path}; +use syn::{parse_quote, Expr, ExprPath, Generics, Ident, Index, Path}; use super::generics; @@ -22,7 +22,7 @@ impl GenericsOutput { } } fn extend(self, where_clause: &mut syn::WhereClause, cratename: &Path) { - let trait_path: Path = syn::parse2(quote! { #cratename::ser::BorshSerialize }).unwrap(); + let trait_path: Path = parse_quote! { #cratename::ser::BorshSerialize }; let predicates = generics::compute_predicates(self.serialize_visitor.process_for_bounds(), &trait_path); where_clause.predicates.extend(predicates); @@ -65,12 +65,12 @@ impl FieldId { impl FieldId { fn serialize_arg(&self) -> Expr { match self { - Self::Struct(name) => syn::parse2(quote! { &self.#name }).unwrap(), - Self::StructUnnamed(index) => syn::parse2(quote! { &self.#index }).unwrap(), - Self::Enum(name) => syn::parse2(quote! { #name }).unwrap(), + Self::Struct(name) => parse_quote! { &self.#name }, + Self::StructUnnamed(index) => parse_quote! { &self.#index }, + Self::Enum(name) => parse_quote! { #name }, Self::EnumUnnamed(ind) => { let field = Ident::new(&format!("id{}", ind.index), Span::mixed_site()); - syn::parse2(quote! { #field }).unwrap() + parse_quote! { #field } } } } diff --git a/borsh-derive/src/internals/serialize/structs/mod.rs b/borsh-derive/src/internals/serialize/structs/mod.rs index 2864c78e9..0a0bef39c 100644 --- a/borsh-derive/src/internals/serialize/structs/mod.rs +++ b/borsh-derive/src/internals/serialize/structs/mod.rs @@ -37,7 +37,7 @@ pub fn process(input: &ItemStruct, cratename: Path) -> syn::Result impl #impl_generics #cratename::ser::BorshSerialize for #name #ty_generics #where_clause { fn serialize<__W: #cratename::io::Write>(&self, writer: &mut __W) -> ::core::result::Result<(), #cratename::io::Error> { #body - Ok(()) + ::core::result::Result::Ok(()) } } }) @@ -73,18 +73,18 @@ mod tests { default_cratename, local_insta_assert_debug_snapshot, local_insta_assert_snapshot, pretty_print_syn_str, }; + use syn::parse_quote; use super::*; #[test] fn simple_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: u64, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -93,15 +93,14 @@ mod tests { #[test] fn simple_struct_with_custom_crate() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: u64, y: String, } - }) - .unwrap(); + }; - let crate_: Path = syn::parse2(quote! { reexporter::borsh }).unwrap(); + let crate_: Path = parse_quote! { reexporter::borsh }; let actual = process(&item_struct, crate_).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -109,13 +108,12 @@ mod tests { #[test] fn simple_generics() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { x: HashMap, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -123,10 +121,9 @@ mod tests { #[test] fn simple_generic_tuple_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct TupleA(T, u32); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -134,13 +131,12 @@ mod tests { #[test] fn bound_generics() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A where V: Value { x: HashMap, y: String, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap()); @@ -148,13 +144,12 @@ mod tests { #[test] fn recursive_struct() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct CRecC { a: String, b: HashMap, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -163,14 +158,13 @@ mod tests { #[test] fn generic_tuple_struct_borsh_skip1() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G ( #[borsh(skip)] HashMap, U, ); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -179,14 +173,13 @@ mod tests { #[test] fn generic_tuple_struct_borsh_skip2() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G ( HashMap, #[borsh(skip)] U, ); - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -195,14 +188,13 @@ mod tests { #[test] fn generic_named_fields_struct_borsh_skip() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct G { #[borsh(skip)] x: HashMap, y: U, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -211,7 +203,7 @@ mod tests { #[test] fn generic_associated_type() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName, @@ -219,8 +211,7 @@ mod tests { field: T::Associated, another: V, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -229,7 +220,7 @@ mod tests { #[test] fn generic_serialize_bound() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct C { a: String, #[borsh(bound(serialize = @@ -238,8 +229,7 @@ mod tests { ))] b: HashMap, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -248,7 +238,7 @@ mod tests { #[test] fn override_generic_associated_type_wrong_derive() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct Parametrized where T: TraitName { #[borsh(bound(serialize = "::Associated: borsh::ser::BorshSerialize" @@ -256,8 +246,7 @@ mod tests { field: ::Associated, another: V, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -266,14 +255,13 @@ mod tests { #[test] fn check_serialize_with_attr() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(serialize_with = "third_party_impl::serialize_third_party")] x: ThirdParty, y: u64, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()).unwrap(); @@ -282,14 +270,13 @@ mod tests { #[test] fn check_serialize_with_skip_conflict() { - let item_struct: ItemStruct = syn::parse2(quote! { + let item_struct: ItemStruct = parse_quote! { struct A { #[borsh(skip,serialize_with = "third_party_impl::serialize_third_party")] x: ThirdParty, y: u64, } - }) - .unwrap(); + }; let actual = process(&item_struct, default_cratename()); diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/bound_generics.snap b/borsh-derive/src/internals/serialize/structs/snapshots/bound_generics.snap index 5c7c6926b..771560bfa 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/bound_generics.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/bound_generics.snap @@ -14,6 +14,6 @@ where ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.x, writer)?; borsh::BorshSerialize::serialize(&self.y, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/check_serialize_with_attr.snap b/borsh-derive/src/internals/serialize/structs/snapshots/check_serialize_with_attr.snap index 6d977d521..bc17794f0 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/check_serialize_with_attr.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/check_serialize_with_attr.snap @@ -13,6 +13,6 @@ where ) -> ::core::result::Result<(), borsh::io::Error> { third_party_impl::serialize_third_party(&self.x, writer)?; borsh::BorshSerialize::serialize(&self.y, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/generic_associated_type.snap b/borsh-derive/src/internals/serialize/structs/snapshots/generic_associated_type.snap index 33b203f80..e50b9f5f9 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/generic_associated_type.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/generic_associated_type.snap @@ -14,6 +14,6 @@ where ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.field, writer)?; borsh::BorshSerialize::serialize(&self.another, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/generic_named_fields_struct_borsh_skip.snap b/borsh-derive/src/internals/serialize/structs/snapshots/generic_named_fields_struct_borsh_skip.snap index 5351f166f..4ebcce8bf 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/generic_named_fields_struct_borsh_skip.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/generic_named_fields_struct_borsh_skip.snap @@ -11,6 +11,6 @@ where writer: &mut __W, ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.y, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/generic_serialize_bound.snap b/borsh-derive/src/internals/serialize/structs/snapshots/generic_serialize_bound.snap index c0309d69a..9b57d8734 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/generic_serialize_bound.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/generic_serialize_bound.snap @@ -13,6 +13,6 @@ where ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.a, writer)?; borsh::BorshSerialize::serialize(&self.b, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/generic_tuple_struct_borsh_skip1.snap b/borsh-derive/src/internals/serialize/structs/snapshots/generic_tuple_struct_borsh_skip1.snap index 447fcb32e..4440bba7f 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/generic_tuple_struct_borsh_skip1.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/generic_tuple_struct_borsh_skip1.snap @@ -11,6 +11,6 @@ where writer: &mut __W, ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.1, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/generic_tuple_struct_borsh_skip2.snap b/borsh-derive/src/internals/serialize/structs/snapshots/generic_tuple_struct_borsh_skip2.snap index 8c5800a25..008ba296d 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/generic_tuple_struct_borsh_skip2.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/generic_tuple_struct_borsh_skip2.snap @@ -12,6 +12,6 @@ where writer: &mut __W, ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.0, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/override_generic_associated_type_wrong_derive.snap b/borsh-derive/src/internals/serialize/structs/snapshots/override_generic_associated_type_wrong_derive.snap index 9b2bf20b3..857aed58c 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/override_generic_associated_type_wrong_derive.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/override_generic_associated_type_wrong_derive.snap @@ -14,6 +14,6 @@ where ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.field, writer)?; borsh::BorshSerialize::serialize(&self.another, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/recursive_struct.snap b/borsh-derive/src/internals/serialize/structs/snapshots/recursive_struct.snap index 510b71b77..a4f31a627 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/recursive_struct.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/recursive_struct.snap @@ -9,6 +9,6 @@ impl borsh::ser::BorshSerialize for CRecC { ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.a, writer)?; borsh::BorshSerialize::serialize(&self.b, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/simple_generic_tuple_struct.snap b/borsh-derive/src/internals/serialize/structs/snapshots/simple_generic_tuple_struct.snap index 984defae9..cfeee40a6 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/simple_generic_tuple_struct.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/simple_generic_tuple_struct.snap @@ -12,6 +12,6 @@ where ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.0, writer)?; borsh::BorshSerialize::serialize(&self.1, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/simple_generics.snap b/borsh-derive/src/internals/serialize/structs/snapshots/simple_generics.snap index 3518ba3a4..30370eaf6 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/simple_generics.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/simple_generics.snap @@ -13,6 +13,6 @@ where ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.x, writer)?; borsh::BorshSerialize::serialize(&self.y, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/simple_struct.snap b/borsh-derive/src/internals/serialize/structs/snapshots/simple_struct.snap index 8904dca85..da47b8f26 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/simple_struct.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/simple_struct.snap @@ -9,6 +9,6 @@ impl borsh::ser::BorshSerialize for A { ) -> ::core::result::Result<(), borsh::io::Error> { borsh::BorshSerialize::serialize(&self.x, writer)?; borsh::BorshSerialize::serialize(&self.y, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } } diff --git a/borsh-derive/src/internals/serialize/structs/snapshots/simple_struct_with_custom_crate.snap b/borsh-derive/src/internals/serialize/structs/snapshots/simple_struct_with_custom_crate.snap index bd331f30d..65f5790bc 100644 --- a/borsh-derive/src/internals/serialize/structs/snapshots/simple_struct_with_custom_crate.snap +++ b/borsh-derive/src/internals/serialize/structs/snapshots/simple_struct_with_custom_crate.snap @@ -9,6 +9,6 @@ impl reexporter::borsh::ser::BorshSerialize for A { ) -> ::core::result::Result<(), reexporter::borsh::io::Error> { reexporter::borsh::BorshSerialize::serialize(&self.x, writer)?; reexporter::borsh::BorshSerialize::serialize(&self.y, writer)?; - Ok(()) + ::core::result::Result::Ok(()) } }