-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Use proc-macro to derive HashStable everywhere #66279
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
Changes from 1 commit
3e969e0
1de5fdb
640797f
bf7c9ba
3c5ddfd
0073d3b
31298b4
e85c195
8c86a79
edc5232
9efd320
ce30107
ea0c354
7e411e7
4d1674f
782cc9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
use crate::token::{self, DelimToken, Token, TokenKind}; | ||
|
||
use syntax_pos::{Span, DUMMY_SP}; | ||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; | ||
use rustc_data_structures::sync::Lrc; | ||
use smallvec::{SmallVec, smallvec}; | ||
|
||
|
@@ -51,6 +52,26 @@ where | |
TokenStream: Send + Sync, | ||
{} | ||
|
||
impl<CTX> HashStable<CTX> for TokenTree | ||
cjgillot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
where CTX: crate::StableHashingContextLike | ||
{ | ||
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { | ||
mem::discriminant(self).hash_stable(hcx, hasher); | ||
match *self { | ||
TokenTree::Token(ref token) => { | ||
token.hash_stable(hcx, hasher); | ||
} | ||
TokenTree::Delimited(span, delim, ref tts) => { | ||
span.hash_stable(hcx, hasher); | ||
std::hash::Hash::hash(&delim, hasher); | ||
for sub_tt in tts.trees() { | ||
sub_tt.hash_stable(hcx, hasher); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl TokenTree { | ||
/// Checks if this TokenTree is equal to the other, regardless of span information. | ||
pub fn eq_unspanned(&self, other: &TokenTree) -> bool { | ||
|
@@ -115,6 +136,16 @@ impl TokenTree { | |
} | ||
} | ||
|
||
impl<CTX> HashStable<CTX> for TokenStream | ||
where CTX: crate::StableHashingContextLike | ||
{ | ||
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { | ||
for sub_tt in self.trees() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nnethercote It seems like this iterator does a bunch of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @petrochenkov Do you know why this ignores |
||
sub_tt.hash_stable(hcx, hasher); | ||
} | ||
} | ||
} | ||
|
||
/// A `TokenStream` is an abstract sequence of tokens, organized into `TokenTree`s. | ||
/// | ||
/// The goal is for procedural macros to work with `TokenStream`s and `TokenTree`s | ||
|
Uh oh!
There was an error while loading. Please reload this page.