-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement PartialEq for proc_macro::Ident == strings #78634
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
👍 Recently I've looked for an allocation free method for comparing idents with str's and couldn't find one. Had to use |
I've nominated both this PR and the |
@rfcbot fcp merge |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
cc #59070 |
I thought about this a little. I wonder about raw vs non-raw idents and whether there should be something to accommodate for it. As in, should an Ident If you are checking for keywords, then you don't want them to compare equal to each other. If you are checking for variable/function names etc, then usually you want In my puny little proc macro that I'm writing, I'm mainly comparing with keywords, so having them be not equal is good for me, but maybe some folks want to compare to function/variable names and they'll have to do Maybe there could be a function like |
We do pretty much that in Syn. There is a function |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I've just checked and looks like the standard library doesn't currently any have any |
I am not dead set on that exact impl signature, but I have found some level of reference unwrapping quite key in practice specifically for Ident. proc_macro2 accomplishes the reference unwrapping by having: impl<T> PartialEq<T> for Ident
where
T: ?Sized + AsRef<str>; where impl<U, V> AsRef<V> for &'_ U
where
U: ?Sized + AsRef<V>,
V: ?Sized; However I felt |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
let _ = ident == "serde"; | ||
let _ = *ident == "serde"; | ||
let _ = *ident == string; | ||
let _ = *ident == &&&string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some tests for raw identifiers?
☔ The latest upstream changes (presumably #78636) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
This concern was discussed in the libs team meeting of 2020-11-18. Although this hasn't been done before in (Thanks for pointing it out!) |
Closing due to inactivity. |
Closes #51074.
We avoid implementing PartialEq<Ident> because "comparison in vacuum doesn't generally make sense in presence of hygiene and it became a source of bugs" --- see #51074 (comment). However, comparing an Ident to a string is "probably explicit enough" --- see #51074 (comment).
The use case is to support attribute parsing, among other things. For example parsing #[serde(rename = "...")] might involve
if ident == "serde"
andif ident == "rename"
.