Flatten types in functions.
This commit is contained in:
@@ -85,22 +85,12 @@ pub(crate) fn generate_body(
|
||||
.map(|fnarg| match fnarg {
|
||||
syn::FnArg::Receiver(_) => panic!("internal error: receiver fn outside impl!?"),
|
||||
syn::FnArg::Typed(syn::PatType { ref ty, .. }) => {
|
||||
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()) {
|
||||
let arg_type = match flatten_type_groups(ty.as_ref()) {
|
||||
syn::Type::Reference(syn::TypeReference {
|
||||
mutability: None,
|
||||
ref elem,
|
||||
..
|
||||
}) => match flatten_groups(elem.as_ref()) {
|
||||
}) => match flatten_type_groups(elem.as_ref()) {
|
||||
syn::Type::Path(ref p) if p.path == str_type_path => {
|
||||
syn::parse2::<syn::Type>(quote! {
|
||||
ImmutableString })
|
||||
@@ -117,7 +107,7 @@ pub(crate) fn generate_body(
|
||||
mutability: Some(_),
|
||||
ref elem,
|
||||
..
|
||||
}) => match flatten_groups(elem.as_ref()) {
|
||||
}) => match flatten_type_groups(elem.as_ref()) {
|
||||
syn::Type::Path(ref p) => syn::parse2::<syn::Type>(quote! {
|
||||
#p })
|
||||
.unwrap(),
|
||||
@@ -184,6 +174,14 @@ pub(crate) fn generate_body(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn flatten_type_groups(ty: &syn::Type) -> &syn::Type {
|
||||
match ty {
|
||||
syn::Type::Group(syn::TypeGroup { ref elem, .. })
|
||||
| syn::Type::Paren(syn::TypeParen { ref elem, .. }) => flatten_type_groups(elem.as_ref()),
|
||||
_ => ty,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn check_rename_collisions(fns: &Vec<ExportedFn>) -> Result<(), syn::Error> {
|
||||
let mut renames = HashMap::<String, proc_macro2::Span>::new();
|
||||
let mut names = HashMap::<String, proc_macro2::Span>::new();
|
||||
|
Reference in New Issue
Block a user