Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro expansion code, export function parameter is &T #3078

Closed
wzjsun opened this issue Sep 11, 2022 · 0 comments · Fixed by #3625
Closed

Macro expansion code, export function parameter is &T #3078

wzjsun opened this issue Sep 11, 2022 · 0 comments · Fixed by #3625
Labels

Comments

@wzjsun
Copy link

wzjsun commented Sep 11, 2022

I have a structure TestStruct, When I take its reference as a parameter of an export function, it's OK, but once I put this export function in the macro, I will get the following error:

error[E0277]: the trait bound `&TestStruct: FromWasmAbi` is not satisfied
  --> src\style.rs:49:9
   |
49 |         #[wasm_bindgen]
   |         ^^^^^^^^^^^^^^^ the trait `FromWasmAbi` is not implemented for `&TestStruct`
...
55 | my_out_export!(&TestStruct);
   | --------------------------- in this macro invocation

The Code:

#[wasm_bindgen]
pub struct TestStruct(usize);

#[wasm_bindgen]
pub fn a_right_example(s: &TestStruct) { println!("a_right_example") }
macro_rules! my_out_export {
    ($x: ty) => {
        #[wasm_bindgen]
        pub fn a_error_example(s: $x) {
			println!("a_error_example")
		}
    };
}
my_out_export!(&TestStruct);
@wzjsun wzjsun added the bug label Sep 11, 2022
snOm3ad added a commit to snOm3ad/wasm-bindgen that referenced this issue Sep 19, 2023
`syn` wraps argument types in a `syn::TypeGroup` for free
functions/methods generated from `macro_rules!` this means that
references end up generating wrong code during proc macro expansion.

This PR unwraps argument types in `syn::TypeGroup` and matches against
the inner element for such cases.

Fixes rustwasm#3078

Signed-off-by: Oliver T <geronimooliver00@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant