diff options
Diffstat (limited to 'src/libsyntax/tokenstream.rs')
| -rw-r--r-- | src/libsyntax/tokenstream.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 40f00aaa5d8..6de9a0fb070 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -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 + 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() { + 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 |
