Flatten type groups and types in parentheses.

This commit is contained in:
Stephen Chung 2020-09-22 21:29:44 +08:00
parent 3224c5baf5
commit 5a37497a22
2 changed files with 15 additions and 5 deletions

View File

@ -85,12 +85,22 @@ pub(crate) fn generate_body(
.map(|fnarg| match fnarg { .map(|fnarg| match fnarg {
syn::FnArg::Receiver(_) => panic!("internal error: receiver fn outside impl!?"), syn::FnArg::Receiver(_) => panic!("internal error: receiver fn outside impl!?"),
syn::FnArg::Typed(syn::PatType { ref ty, .. }) => { syn::FnArg::Typed(syn::PatType { ref ty, .. }) => {
let arg_type = match ty.as_ref() { fn flatten_groups(ty: &syn::Type) -> &syn::Type {
match ty {
syn::Type::Group(syn::TypeGroup { ref elem, .. })
| syn::Type::Paren(syn::TypeParen { ref elem, .. }) => {
flatten_groups(elem.as_ref())
}
_ => ty,
}
}
let arg_type = match flatten_groups(ty.as_ref()) {
syn::Type::Reference(syn::TypeReference { syn::Type::Reference(syn::TypeReference {
mutability: None, mutability: None,
ref elem, ref elem,
.. ..
}) => match elem.as_ref() { }) => match flatten_groups(elem.as_ref()) {
syn::Type::Path(ref p) if p.path == str_type_path => { syn::Type::Path(ref p) if p.path == str_type_path => {
syn::parse2::<syn::Type>(quote! { syn::parse2::<syn::Type>(quote! {
ImmutableString }) ImmutableString })
@ -107,11 +117,11 @@ pub(crate) fn generate_body(
mutability: Some(_), mutability: Some(_),
ref elem, ref elem,
.. ..
}) => match elem.as_ref() { }) => match flatten_groups(elem.as_ref()) {
syn::Type::Path(ref p) => syn::parse2::<syn::Type>(quote! { syn::Type::Path(ref p) => syn::parse2::<syn::Type>(quote! {
#p }) #p })
.unwrap(), .unwrap(),
_ => panic!("internal error: non-string shared reference!?"), _ => panic!("internal error: invalid mutable reference!?"),
}, },
t => t.clone(), t => t.clone(),
}; };

View File

@ -40,7 +40,7 @@ macro_rules! gen_concat_functions {
macro_rules! reg_functions { macro_rules! reg_functions {
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $( ($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
combine_with_exported_module!($mod_name, "strings_merge", $root::$arg_type::functions); combine_with_exported_module!($mod_name, "strings_concat", $root::$arg_type::functions);
)* } )* }
} }