-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 Ident, PartialEq for TokenStream #51074
Comments
I'm curious to hear @nrc's thoughts on this, but I'd personally prefer if we don't do this quite just yet. Hygeiene is enough of an open question and these seem like they'll be a small enough quality of life improvement that I'd prefer to take the conservative route until we have more information on the hygiene story. Now that being said, if @nrc isn't necessarily diametrically opposed to this I think we can probably go ahead and do this in |
Seems reasonable, unscheduling from 1.2. |
For the compiler's internal versions of Normally you want to strip some layers of macro expansions from the ident's context before comparing - "legacy" If macro authors want to do string-based comparisons, this should preferably be done in some explicit way. |
I totally agree - if you have two idents from different hygiene contexts, I don't think you'd ever want them to compare equal (in fact, for some hygiene algorithms, equality as a concept doesn't make sense at all). |
Ok given that In any case |
@petrochenkov would you consider an Ident—string implementation of PartialEq? impl PartialEq<str> for Ident
impl<'a> PartialEq<&'a str> for Ident These would address the use case of checking for keywords / recognized attribute names while being unmistakable in terms of how they compare hygiene. |
@dtolnay |
Triage: these types do not implement these traits today. |
The original hesitation around these impls was whether to consider things equal that have different
Span
s.I propose that if somebody is writing a macro that relies on knowing whether two tokens are the very same down to their syntax context, we should consider that an unhelpable case of "doing it wrong." On the other hand comparing the text of an Ident is quite common and perfectly correct. For example when iterating through field attributes in a custom derive to handle something like
#[serde(rename = "...")]
it makes sense to compare whether the idents in the token stream are== i_serde
or== i_rename
.tracking issue: #38356
cc @Eijebong @alexcrichton
The text was updated successfully, but these errors were encountered: