diff --git a/borsh-derive/src/internals/schema/enums/mod.rs b/borsh-derive/src/internals/schema/enums/mod.rs index 4f1f5f966..95bbed06b 100644 --- a/borsh-derive/src/internals/schema/enums/mod.rs +++ b/borsh-derive/src/internals/schema/enums/mod.rs @@ -39,7 +39,6 @@ pub fn process(input: &ItemEnum, cratename: Path) -> syn::Result { let discriminants = Discriminants::new(&input.variants); // Generate functions that return the schema for variants. - let mut discriminant_variables = vec![]; let mut variants_defs = vec![]; let mut inner_defs = TokenStream2::new(); let mut add_recursive_defs = TokenStream2::new(); @@ -60,14 +59,12 @@ pub fn process(input: &ItemEnum, cratename: Path) -> syn::Result { inner_defs.extend(variant_output.inner_struct); add_recursive_defs.extend(variant_output.add_definitions_recursively_call); variants_defs.push(variant_output.variant_entry); - discriminant_variables.push(variant_output.discriminant_variable_assignment); } let type_definitions = quote! { fn add_definitions_recursively(definitions: &mut #cratename::__private::maybestd::collections::BTreeMap<#cratename::schema::Declaration, #cratename::schema::Definition>) { #inner_defs #add_recursive_defs - #(#discriminant_variables)* let definition = #cratename::schema::Definition::Enum { tag_width: 1, variants: #cratename::__private::maybestd::vec![#(#variants_defs),*], @@ -93,8 +90,6 @@ struct VariantOutput { inner_struct: TokenStream2, /// call to `add_definitions_recursively`. add_definitions_recursively_call: TokenStream2, - /// declaration of `u8` variable, holding the value for discriminant of a variant - discriminant_variable_assignment: TokenStream2, /// entry with a variant's declaration, element in vector of whole enum's definition variant_entry: TokenStream2, } @@ -108,18 +103,9 @@ struct DiscriminantInfo<'a> { fn process_discriminant( variant_ident: &Ident, info: DiscriminantInfo<'_>, -) -> syn::Result<(Ident, TokenStream2)> { - let discriminant_value = - info.discriminants - .get(variant_ident, info.use_discriminant, info.variant_idx)?; - - let discriminant_variable_name = format!("discriminant_{}", info.variant_idx); - let discriminant_variable = Ident::new(&discriminant_variable_name, Span::call_site()); - - let discriminant_variable_assignment = quote! { - let #discriminant_variable: u8 = #discriminant_value; - }; - Ok((discriminant_variable, discriminant_variable_assignment)) +) -> syn::Result { + info.discriminants + .get(variant_ident, info.use_discriminant, info.variant_idx) } fn process_variant( @@ -139,21 +125,21 @@ fn process_variant( inner_struct_definition(variant, cratename, &full_variant_ident, enum_generics); let (_ig, inner_struct_ty_generics, _wc) = inner_struct_generics.split_for_impl(); - let add_definitions_recursively_call = quote! { - <#full_variant_ident #inner_struct_ty_generics as #cratename::BorshSchema>::add_definitions_recursively(definitions); + let variant_type = quote! { + <#full_variant_ident #inner_struct_ty_generics as #cratename::BorshSchema> }; + let discriminant_value = process_discriminant(&variant.ident, discriminant_info)?; - let (discriminant_variable, discriminant_variable_assignment) = - process_discriminant(&variant.ident, discriminant_info)?; - - let variant_entry = quote! { - (#discriminant_variable as i64, #variant_name.to_string(), <#full_variant_ident #inner_struct_ty_generics as #cratename::BorshSchema>::declaration()) - }; Ok(VariantOutput { inner_struct, - add_definitions_recursively_call, - variant_entry, - discriminant_variable_assignment, + add_definitions_recursively_call: quote! { + #variant_type::add_definitions_recursively(definitions); + }, + variant_entry: quote! { + (u8::from(#discriminant_value) as i64, + #variant_name.into(), + #variant_type::declaration()) + }, }) } diff --git a/borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_false.snap b/borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_false.snap index 681b361be..4fa592109 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_false.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_false.snap @@ -42,23 +42,17 @@ impl borsh::BorshSchema for X { ::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; - let discriminant_2: u8 = 2u8; - let discriminant_3: u8 = 3u8; - let discriminant_4: u8 = 4u8; - let discriminant_5: u8 = 5u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "A".to_string(), < XA as borsh::BorshSchema > - ::declaration()), (discriminant_1 as i64, "B".to_string(), < XB as - borsh::BorshSchema > ::declaration()), (discriminant_2 as i64, "C" - .to_string(), < XC as borsh::BorshSchema > ::declaration()), - (discriminant_3 as i64, "D".to_string(), < XD as borsh::BorshSchema > - ::declaration()), (discriminant_4 as i64, "E".to_string(), < XE as - borsh::BorshSchema > ::declaration()), (discriminant_5 as i64, "F" - .to_string(), < XF as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "A".into(), < XA as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "B".into(), < XB as + borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "C".into(), + < XC as borsh::BorshSchema > ::declaration()), (u8::from(3u8) as i64, "D" + .into(), < XD as borsh::BorshSchema > ::declaration()), (u8::from(4u8) as + i64, "E".into(), < XE as borsh::BorshSchema > ::declaration()), + (u8::from(5u8) as i64, "F".into(), < XF as borsh::BorshSchema > + ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_true.snap b/borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_true.snap index 0d592f39c..1b234f1df 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_true.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/borsh_discriminant_true.snap @@ -42,23 +42,17 @@ impl borsh::BorshSchema for X { ::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0; - let discriminant_1: u8 = 20; - let discriminant_2: u8 = 20 + 1; - let discriminant_3: u8 = 20 + 1 + 1; - let discriminant_4: u8 = 10; - let discriminant_5: u8 = 10 + 1; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "A".to_string(), < XA as borsh::BorshSchema > - ::declaration()), (discriminant_1 as i64, "B".to_string(), < XB as - borsh::BorshSchema > ::declaration()), (discriminant_2 as i64, "C" - .to_string(), < XC as borsh::BorshSchema > ::declaration()), - (discriminant_3 as i64, "D".to_string(), < XD as borsh::BorshSchema > - ::declaration()), (discriminant_4 as i64, "E".to_string(), < XE as - borsh::BorshSchema > ::declaration()), (discriminant_5 as i64, "F" - .to_string(), < XF as borsh::BorshSchema > ::declaration()) + (u8::from(0) as i64, "A".into(), < XA as borsh::BorshSchema > + ::declaration()), (u8::from(20) as i64, "B".into(), < XB as + borsh::BorshSchema > ::declaration()), (u8::from(20 + 1) as i64, "C" + .into(), < XC as borsh::BorshSchema > ::declaration()), (u8::from(20 + 1 + + 1) as i64, "D".into(), < XD as borsh::BorshSchema > ::declaration()), + (u8::from(10) as i64, "E".into(), < XE as borsh::BorshSchema > + ::declaration()), (u8::from(10 + 1) as i64, "F".into(), < XF as + borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/complex_enum.snap b/borsh-derive/src/internals/schema/enums/snapshots/complex_enum.snap index 9049c4a46..60006941b 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/complex_enum.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/complex_enum.snap @@ -35,19 +35,15 @@ impl borsh::BorshSchema for A { ::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; - let discriminant_2: u8 = 2u8; - let discriminant_3: u8 = 3u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "Bacon".to_string(), < ABacon as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs" - .to_string(), < AEggs as borsh::BorshSchema > ::declaration()), - (discriminant_2 as i64, "Salad".to_string(), < ASalad as - borsh::BorshSchema > ::declaration()), (discriminant_3 as i64, "Sausage" - .to_string(), < ASausage as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < AEggs as + borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "Salad" + .into(), < ASalad as borsh::BorshSchema > ::declaration()), + (u8::from(3u8) as i64, "Sausage".into(), < ASausage as borsh::BorshSchema + > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics.snap b/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics.snap index abee2c0c9..46c0ca102 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics.snap @@ -43,19 +43,15 @@ where ::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; - let discriminant_2: u8 = 2u8; - let discriminant_3: u8 = 3u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "Bacon".to_string(), < ABacon as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs" - .to_string(), < AEggs as borsh::BorshSchema > ::declaration()), - (discriminant_2 as i64, "Salad".to_string(), < ASalad < C > as - borsh::BorshSchema > ::declaration()), (discriminant_3 as i64, "Sausage" - .to_string(), < ASausage < W > as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < AEggs as + borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "Salad" + .into(), < ASalad < C > as borsh::BorshSchema > ::declaration()), + (u8::from(3u8) as i64, "Sausage".into(), < ASausage < W > as + borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_named_field.snap b/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_named_field.snap index 82c48d235..c73bb784d 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_named_field.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_named_field.snap @@ -45,20 +45,15 @@ where ::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; - let discriminant_2: u8 = 2u8; - let discriminant_3: u8 = 3u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "Bacon".to_string(), < ABacon as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs" - .to_string(), < AEggs as borsh::BorshSchema > ::declaration()), - (discriminant_2 as i64, "Salad".to_string(), < ASalad < C > as - borsh::BorshSchema > ::declaration()), (discriminant_3 as i64, "Sausage" - .to_string(), < ASausage < W, U > as borsh::BorshSchema > - ::declaration()) + (u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < AEggs as + borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "Salad" + .into(), < ASalad < C > as borsh::BorshSchema > ::declaration()), + (u8::from(3u8) as i64, "Sausage".into(), < ASausage < W, U > as + borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_tuple_field.snap b/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_tuple_field.snap index ed2938d98..a531044c8 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_tuple_field.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/complex_enum_generics_borsh_skip_tuple_field.snap @@ -45,19 +45,15 @@ where ::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; - let discriminant_2: u8 = 2u8; - let discriminant_3: u8 = 3u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "Bacon".to_string(), < ABacon as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs" - .to_string(), < AEggs as borsh::BorshSchema > ::declaration()), - (discriminant_2 as i64, "Salad".to_string(), < ASalad < C > as - borsh::BorshSchema > ::declaration()), (discriminant_3 as i64, "Sausage" - .to_string(), < ASausage < W > as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < AEggs as + borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "Salad" + .into(), < ASalad < C > as borsh::BorshSchema > ::declaration()), + (u8::from(3u8) as i64, "Sausage".into(), < ASausage < W > as + borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/filter_foreign_attrs.snap b/borsh-derive/src/internals/schema/enums/snapshots/filter_foreign_attrs.snap index 9cd99256d..3eaab191e 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/filter_foreign_attrs.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/filter_foreign_attrs.snap @@ -29,14 +29,12 @@ impl borsh::BorshSchema for A { } ::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "B".to_string(), < AB as borsh::BorshSchema > - ::declaration()), (discriminant_1 as i64, "Negative".to_string(), < - ANegative as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "B".into(), < AB as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "Negative".into(), < ANegative + as borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type.snap b/borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type.snap index 8f8cd55a8..c87de892b 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type.snap @@ -56,15 +56,12 @@ where as borsh::BorshSchema>::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "B".to_string(), < EnumParametrizedB < K, V > as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "C" - .to_string(), < EnumParametrizedC < T > as borsh::BorshSchema > - ::declaration()) + (u8::from(0u8) as i64, "B".into(), < EnumParametrizedB < K, V > as + borsh::BorshSchema > ::declaration()), (u8::from(1u8) as i64, "C".into(), + < EnumParametrizedC < T > as borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type_param_override.snap b/borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type_param_override.snap index 16550cca5..9389a848d 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type_param_override.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/generic_associated_type_param_override.snap @@ -57,15 +57,12 @@ where as borsh::BorshSchema>::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "B".to_string(), < EnumParametrizedB < K, V > as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "C" - .to_string(), < EnumParametrizedC < T > as borsh::BorshSchema > - ::declaration()) + (u8::from(0u8) as i64, "B".into(), < EnumParametrizedB < K, V > as + borsh::BorshSchema > ::declaration()), (u8::from(1u8) as i64, "C".into(), + < EnumParametrizedC < T > as borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/recursive_enum.snap b/borsh-derive/src/internals/schema/enums/snapshots/recursive_enum.snap index d3eaee6e4..856f9f630 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/recursive_enum.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/recursive_enum.snap @@ -37,14 +37,12 @@ where struct AC(K, Vec); as borsh::BorshSchema>::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "B".to_string(), < AB < K, V > as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "C" - .to_string(), < AC < K > as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "B".into(), < AB < K, V > as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "C".into(), < AC < K > as + borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/simple_enum.snap b/borsh-derive/src/internals/schema/enums/snapshots/simple_enum.snap index 43e2bb65c..cbadbaf7f 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/simple_enum.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/simple_enum.snap @@ -22,14 +22,12 @@ impl borsh::BorshSchema for A { struct AEggs; ::add_definitions_recursively(definitions); ::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "Bacon".to_string(), < ABacon as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Eggs" - .to_string(), < AEggs as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < AEggs as + borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/simple_enum_with_custom_crate.snap b/borsh-derive/src/internals/schema/enums/snapshots/simple_enum_with_custom_crate.snap index 1ca082356..368a39d92 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/simple_enum_with_custom_crate.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/simple_enum_with_custom_crate.snap @@ -26,14 +26,12 @@ impl reexporter::borsh::BorshSchema for A { ::add_definitions_recursively( definitions, ); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; let definition = reexporter::borsh::schema::Definition::Enum { tag_width: 1, variants: reexporter::borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "Bacon".to_string(), < ABacon as - reexporter::borsh::BorshSchema > ::declaration()), (discriminant_1 as - i64, "Eggs".to_string(), < AEggs as reexporter::borsh::BorshSchema > + (u8::from(0u8) as i64, "Bacon".into(), < ABacon as + reexporter::borsh::BorshSchema > ::declaration()), (u8::from(1u8) as i64, + "Eggs".into(), < AEggs as reexporter::borsh::BorshSchema > ::declaration()) ], }; diff --git a/borsh-derive/src/internals/schema/enums/snapshots/single_field_enum.snap b/borsh-derive/src/internals/schema/enums/snapshots/single_field_enum.snap index c8fb45780..f3a886f9b 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/single_field_enum.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/single_field_enum.snap @@ -17,12 +17,11 @@ impl borsh::BorshSchema for A { #[borsh(crate = "borsh")] struct ABacon; ::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "Bacon".to_string(), < ABacon as - borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema > + ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/trailing_comma_generics.snap b/borsh-derive/src/internals/schema/enums/snapshots/trailing_comma_generics.snap index 59bee36d8..d6dfffc9a 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/trailing_comma_generics.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/trailing_comma_generics.snap @@ -40,14 +40,12 @@ where B: Display + Debug; as borsh::BorshSchema>::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "Left".to_string(), < SideLeft < A > as - borsh::BorshSchema > ::declaration()), (discriminant_1 as i64, "Right" - .to_string(), < SideRight < B > as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "Left".into(), < SideLeft < A > as + borsh::BorshSchema > ::declaration()), (u8::from(1u8) as i64, "Right" + .into(), < SideRight < B > as borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition( diff --git a/borsh-derive/src/internals/schema/enums/snapshots/with_funcs_attr.snap b/borsh-derive/src/internals/schema/enums/snapshots/with_funcs_attr.snap index 87836edcb..17f16077c 100644 --- a/borsh-derive/src/internals/schema/enums/snapshots/with_funcs_attr.snap +++ b/borsh-derive/src/internals/schema/enums/snapshots/with_funcs_attr.snap @@ -41,14 +41,12 @@ where ); ::add_definitions_recursively(definitions); as borsh::BorshSchema>::add_definitions_recursively(definitions); - let discriminant_0: u8 = 0u8; - let discriminant_1: u8 = 1u8; let definition = borsh::schema::Definition::Enum { tag_width: 1, variants: borsh::__private::maybestd::vec![ - (discriminant_0 as i64, "C3".to_string(), < CC3 as borsh::BorshSchema > - ::declaration()), (discriminant_1 as i64, "C4".to_string(), < CC4 < K, V - > as borsh::BorshSchema > ::declaration()) + (u8::from(0u8) as i64, "C3".into(), < CC3 as borsh::BorshSchema > + ::declaration()), (u8::from(1u8) as i64, "C4".into(), < CC4 < K, V > as + borsh::BorshSchema > ::declaration()) ], }; borsh::schema::add_definition(