Created
May 26, 2020 15:14
-
-
Save alexcrichton/3c93ab2547d45d9caa3b72309cd4262b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs | |
index 0838ad5b3..292c9add4 100644 | |
--- a/crates/macro-support/src/parser.rs | |
+++ b/crates/macro-support/src/parser.rs | |
@@ -414,18 +414,18 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a ast::ImportModule)> for syn::ForeignIte | |
let class = wasm.arguments.get(0).ok_or_else(|| { | |
err_span!(self, "imported methods must have at least one argument") | |
})?; | |
- let class = match &*class.ty { | |
+ let class = match get_ty(&class.ty) { | |
syn::Type::Reference(syn::TypeReference { | |
mutability: None, | |
elem, | |
.. | |
- }) => &**elem, | |
+ }) => get_ty(elem), | |
_ => bail_span!( | |
class.ty, | |
"first argument of method must be a shared reference" | |
), | |
}; | |
- let class_name = match *class { | |
+ let class_name = match get_ty(class) { | |
syn::Type::Path(syn::TypePath { | |
qself: None, | |
ref path, | |
@@ -466,7 +466,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a ast::ImportModule)> for syn::ForeignIte | |
Some(ref ty) => ty, | |
_ => bail_span!(self, "constructor returns must be bare types"), | |
}; | |
- let class_name = match *class { | |
+ let class_name = match get_ty(class) { | |
syn::Type::Path(syn::TypePath { | |
qself: None, | |
ref path, | |
@@ -528,6 +528,13 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a ast::ImportModule)> for syn::ForeignIte | |
} | |
} | |
+fn get_ty(ty: &syn::Type) -> &syn::Type { | |
+ match ty { | |
+ syn::Type::Group(g) => get_ty(&g.elem), | |
+ other => other, | |
+ } | |
+} | |
+ | |
impl ConvertToAst<BindgenAttrs> for syn::ForeignItemType { | |
type Target = ast::ImportKind; | |
diff --git a/crates/test-macro/src/lib.rs b/crates/test-macro/src/lib.rs | |
index e3033c446..66ca23abb 100644 | |
--- a/crates/test-macro/src/lib.rs | |
+++ b/crates/test-macro/src/lib.rs | |
@@ -43,8 +43,8 @@ pub fn wasm_bindgen_test( | |
} | |
} | |
} | |
- let ident = match body.next() { | |
- Some(TokenTree::Ident(token)) => token, | |
+ let ident = match find_ident(&mut body) { | |
+ Some(token) => token, | |
_ => panic!("expected a function name"), | |
}; | |
@@ -78,3 +78,13 @@ pub fn wasm_bindgen_test( | |
tokens.into_iter().collect::<TokenStream>().into() | |
} | |
+ | |
+fn find_ident(iter: &mut token_stream::IntoIter) -> Option<Ident> { | |
+ match iter.next()? { | |
+ TokenTree::Ident(i) => Some(i), | |
+ TokenTree::Group(g) if g.delimiter() == Delimiter::None => { | |
+ find_ident(&mut g.stream().into_iter()) | |
+ } | |
+ _ => None, | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment