From b8135828384197d58e0711b4b08d03f141d65544 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 30 May 2020 23:31:41 -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 `oauth1-request-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. --- oauth1-request-derive/src/method_body.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/oauth1-request-derive/src/method_body.rs b/oauth1-request-derive/src/method_body.rs index c2a63a4..94fb1ed 100644 --- a/oauth1-request-derive/src/method_body.rs +++ b/oauth1-request-derive/src/method_body.rs @@ -47,7 +47,11 @@ impl<'a> ToTokens for MethodBody<'a> { } let ty_is_option = f.meta.option.get().map(|v| **v).unwrap_or_else(|| { - if let Type::Path(ref ty_path) = f.ty { + let mut ty = &f.ty; + while let Type::Group(g) = ty { + ty = &g.elem; + } + if let Type::Path(ref ty_path) = ty { let path = &ty_path.path; path.leading_colon.is_none() && path.segments.len() == 1