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

Raw identifiers cause error #3586

Closed
cam-narzt opened this issue Aug 30, 2023 · 6 comments · Fixed by #3621
Closed

Raw identifiers cause error #3586

cam-narzt opened this issue Aug 30, 2023 · 6 comments · Fixed by #3621
Labels

Comments

@cam-narzt
Copy link

Describe the Bug

Trying to use a struct with a raw identifier in wasm causes an error to be thrown.

Steps to Reproduce

use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct Column {
  pub r#type: u8,
}

Expected Behavior

I expect valid rust to compile to valid wasm.

Actual Behavior

rustc: custom attribute panicked

Additional Context

Docs about raw identifiers

@cam-narzt cam-narzt added the bug label Aug 30, 2023
@daxpedda
Copy link
Collaborator

daxpedda commented Sep 2, 2023

Happy to review a PR fixing this!
Should be pretty straightforward with syn.

@Liamolucko
Copy link
Collaborator

Liamolucko commented Sep 4, 2023

quote::format_ident will probably be useful here (similar to #3541).

EDIT: or maybe unraw. The idents often seem to have already been converted to strings by the time formatting is happening, so that might be easier.

@Solo-steven
Copy link
Contributor

Hi, I would like to take this issue, and I believe we can simply solve it by adding format_ident to theree and add format_ident to make js_name handle raw identifier correctly.

let (js_field_name, member) = match &field.ident {

Screenshot 2023-09-16 at 2 50 45 PM

it seems that unraw method belongs to the Ident structure in syn crate, but the Ident structure we use seems from the proc_macro mostly, so I think if we gonna using unraw method, maybe we need to convert Ident from proc_macro to ident from syn crate/

@daxpedda
Copy link
Collaborator

It sounds to me like format_ident should do the trick then if unraw requires unnecessary conversions.
I'm happy to review a PR.

@Liamolucko
Copy link
Collaborator

it seems that unraw method belongs to the Ident structure in syn crate, but the Ident structure we use seems from the proc_macro mostly, so I think if we gonna using unraw method, maybe we need to convert Ident from proc_macro to ident from syn crate/

We're using proc_macro2::Ident, not proc_macro::Ident, and syn::Ident is just a re-export of proc_macro2::Ident, so there's no conversion needed.

@Solo-steven
Copy link
Contributor

Hi @Liamolucko thanks for your reply, You are right! it's my fault that confused with proc_macro and proc_marco2, unraw would work as format_ident, thanks for your catch ~

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.

4 participants