Skip to content

Commit b813582

Browse files
committed
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.
1 parent 97c90e4 commit b813582

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

oauth1-request-derive/src/method_body.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ impl<'a> ToTokens for MethodBody<'a> {
4747
}
4848

4949
let ty_is_option = f.meta.option.get().map(|v| **v).unwrap_or_else(|| {
50-
if let Type::Path(ref ty_path) = f.ty {
50+
let mut ty = &f.ty;
51+
while let Type::Group(g) = ty {
52+
ty = &g.elem;
53+
}
54+
if let Type::Path(ref ty_path) = ty {
5155
let path = &ty_path.path;
5256
path.leading_colon.is_none()
5357
&& path.segments.len() == 1

0 commit comments

Comments
 (0)