diff --git a/macros/macros_impl/src/asn_type.rs b/macros/macros_impl/src/asn_type.rs index 63f7905a..a4cf7303 100644 --- a/macros/macros_impl/src/asn_type.rs +++ b/macros/macros_impl/src/asn_type.rs @@ -62,7 +62,7 @@ pub fn derive_struct_impl( paren_token: Some(<_>::default()), modifier: syn::TraitBoundModifier::None, lifetimes: None, - path: syn::parse_str("rasn::AsnType").unwrap(), + path: syn::parse_quote!(#crate_root::AsnType), })); } diff --git a/macros/macros_impl/src/enum.rs b/macros/macros_impl/src/enum.rs index a07d0657..f080c009 100644 --- a/macros/macros_impl/src/enum.rs +++ b/macros/macros_impl/src/enum.rs @@ -39,10 +39,10 @@ impl Enum { quote! { { - const VARIANT_LIST: &'static [#crate_root::types::TagTree] = &[#(#field_tags),*]; - const VARIANT_TAG_TREE: #crate_root::types::TagTree = #crate_root::types::TagTree::Choice(VARIANT_LIST); - const _: () = assert!(VARIANT_TAG_TREE.is_unique(), #error_message); - VARIANT_TAG_TREE + let variant_list: &'static [#crate_root::types::TagTree] = const { &[#(#field_tags),*] }; + let variant_tag_tree: #crate_root::types::TagTree = #crate_root::types::TagTree::Choice(variant_list); + assert!(variant_tag_tree.is_unique(), #error_message); + variant_tag_tree } } } else { @@ -50,13 +50,24 @@ impl Enum { }; let name = &self.name; - let (impl_generics, ty_generics, where_clause) = self.generics.split_for_impl(); + let mut generics = self.generics.clone(); + + for param in &mut generics.params { + if let syn::GenericParam::Type(type_param) = param { + type_param + .bounds + .push(syn::parse_quote!(#crate_root::AsnType)); + } + } + + let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); + let return_val = self .config .tag .is_some() .then(|| quote!(#crate_root::types::TagTree::Leaf(Self::TAG))) - .unwrap_or_else(|| quote!(TAG_TREE)); + .unwrap_or_else(|| quote!(tag_tree)); let (base_variants, extended_variants): (Vec<_>, Vec<_>) = self .variants @@ -174,10 +185,12 @@ impl Enum { const TAG: #crate_root::types::Tag = { #tag }; - const TAG_TREE: #crate_root::types::TagTree = { - const LIST: &'static [#crate_root::types::TagTree] = &[#tag_tree]; - const TAG_TREE: #crate_root::types::TagTree = #crate_root::types::TagTree::Choice(LIST); - const _: () = assert!(TAG_TREE.is_unique(), #error_message); + const TAG_TREE: #crate_root::types::TagTree = const { + let list: &'static [#crate_root::types::TagTree] = const { + &[#tag_tree] + }; + let tag_tree: #crate_root::types::TagTree = #crate_root::types::TagTree::Choice(list); + assert!(tag_tree.is_unique(), #error_message); #return_val }; #alt_identifier diff --git a/tests/derive.rs b/tests/derive.rs index 9aee8df3..a3c75a4a 100644 --- a/tests/derive.rs +++ b/tests/derive.rs @@ -144,6 +144,13 @@ pub enum ExplicitChoice { ByKey, } +#[derive(AsnType, Decode, Encode)] +#[rasn(choice)] +pub enum GenericEnum { + FixedString(FixedOctetString), + Sequence(Vec), +} + #[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct BasicConstraints { #[rasn(default)]