From 6732d8b38a34305e0461752fc401dd97bc1e0455 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 30 May 2020 23:58:43 -0400 Subject: [PATCH] Handle nested `syn::Type:::Group` Currently, rustc does not pass the exact original TokenStream to proc-macros in several cases. This has many undesirable effects, such as losing correct location information in error message. See rust-lang/rust#43081 for more details In the future, rustc will begin passing the correct TokenStream to proc-macros. As a result, `syn` may wrap a type in one or more `syn::Type::Group`s (if the proc-macro input came from a `macro_rules!` expansion). I've determined that this can cause `yaserde-derive` to fail to match a `Type::Path`. This PR should properly handle nested groups, allowing your crate to work with both old and new input. If you have any questions, feel free to ask me. See rust-lang/rust#72622 for more details. --- yaserde_derive/src/common/field.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yaserde_derive/src/common/field.rs b/yaserde_derive/src/common/field.rs index 1c9125e..35ecc79 100644 --- a/yaserde_derive/src/common/field.rs +++ b/yaserde_derive/src/common/field.rs @@ -225,7 +225,11 @@ impl From<&syn::Path> for Field { impl From<&syn::Field> for Field { fn from(field: &syn::Field) -> Self { - match field.ty { + let mut ty = &field.ty; + while let syn::Type::Group(g) = ty { + ty = &g.elem; + } + match ty { Path(ref path) => Field::from(&path.path), _ => panic!("unable to match {:?}", field.ty), }