mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2025-01-05 19:53:55 +03:00
Unwrap argument types in macro (#3625)
This commit is contained in:
parent
9ae2a606e1
commit
4bafdbebcc
@ -129,6 +129,9 @@
|
||||
proc-macro.
|
||||
[#3601](https://github.com/rustwasm/wasm-bindgen/pull/3601)
|
||||
|
||||
* Fix bug with function arguments coming from `macro_rules!`.
|
||||
[#3625](https://github.com/rustwasm/wasm-bindgen/pull/3625)
|
||||
|
||||
### Removed
|
||||
|
||||
* Removed `ReadableStreamByobReader::read_with_u8_array()` because it doesn't work with Wasm.
|
||||
|
@ -523,8 +523,16 @@ impl TryToTokens for ast::Export {
|
||||
argtys.push(&*arg.ty);
|
||||
let i = i + offset;
|
||||
let ident = Ident::new(&format!("arg{}", i), Span::call_site());
|
||||
let ty = &arg.ty;
|
||||
match &*arg.ty {
|
||||
fn unwrap_nested_types(ty: &syn::Type) -> &syn::Type {
|
||||
match &ty {
|
||||
syn::Type::Group(syn::TypeGroup { ref elem, .. }) => unwrap_nested_types(elem),
|
||||
syn::Type::Paren(syn::TypeParen { ref elem, .. }) => unwrap_nested_types(elem),
|
||||
_ => ty,
|
||||
}
|
||||
}
|
||||
let ty = unwrap_nested_types(&arg.ty);
|
||||
|
||||
match &ty {
|
||||
syn::Type::Reference(syn::TypeReference {
|
||||
mutability: Some(_),
|
||||
elem,
|
||||
|
12
tests/wasm/macro_rules.rs
Normal file
12
tests/wasm/macro_rules.rs
Normal file
@ -0,0 +1,12 @@
|
||||
//! This tests that the `wasm_bindgen` macro produces code that compiles for this use case.
|
||||
//! `cargo test --target wasm32-unknown-unknown` will not run if this test breaks.
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
macro_rules! my_export {
|
||||
($i: ident, $s: ty) => {
|
||||
#[wasm_bindgen]
|
||||
pub fn $i(_: $s) {}
|
||||
};
|
||||
}
|
||||
|
||||
my_export!(should_compile, &[i32]);
|
@ -35,6 +35,7 @@ pub mod js_keywords;
|
||||
pub mod js_objects;
|
||||
pub mod jscast;
|
||||
pub mod link_to;
|
||||
pub mod macro_rules;
|
||||
pub mod math;
|
||||
pub mod no_shims;
|
||||
pub mod node;
|
||||
|
Loading…
Reference in New Issue
Block a user