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

Ident construction example is incorrect in the presence of raw identifiers #302

Open
sfackler opened this issue Nov 23, 2021 · 1 comment
Labels

Comments

@sfackler
Copy link

The documentation for Ident has an example of how to make an ident with a name derived from another: https://docs.rs/proc-macro2/1.0.32/proc_macro2/struct.Ident.html#examples by just interpolating with format!(). However, it appears that if the original ident was raw, the output is invalid and unparseable: sfackler/rust-postgres#839.

Is there any way of handling this properly other than something like format!("__{}", ident.to_string().strip_prefix("r#"))?

@dtolnay
Copy link
Owner

dtolnay commented Nov 23, 2021

https://docs.rs/quote/1/quote/macro.format_ident.html is the best option: format_ident!("__{}", ident)

@dtolnay dtolnay added the docs label Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants