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

Avoid panic when using quote! on raw identifiers #140

Merged
merged 1 commit into from
Dec 23, 2019

Conversation

mystor
Copy link
Collaborator

@mystor mystor commented Dec 23, 2019

The quote! optimization added in 8d155b0 calls Ident::new, which does not handle identifiers containing the r# raw prefix, panicing if they are passed in.

As Ident::new_raw is not stable, raw identifiers are parsed using the existing parse codepath, with only non-raw identifiers being passed to Ident::new. This mimics the logic from the mk_ident method created for format_ident!, with some small optimizations due to relaxed requirements.

The previous is_ident optimization within __rt::parse has also been removed, as it is now redundant.

The `quote!` optimization added in 8d155b0
calls `Ident::new`, which does not handle identifiers containing the `r#` raw
prefix, panicing if they are passed in.

As `Ident::new_raw` is not stable, raw identifiers are parsed using the existing
`parse` codepath, with only non-raw identifiers being passed to `Ident::new`.
This mimics the logic from the `mk_ident` method created for `format_ident!`,
with some small optimizations due to relaxed requirements.

The previous `is_ident` optimization within `__rt::parse` has also been removed,
as it is now redundant.
Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay dtolnay merged commit 2a803f7 into dtolnay:master Dec 23, 2019
@mystor mystor deleted the quote_raw_id branch December 24, 2019 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants