about summary refs log tree commit diff
path: root/src/libsyntax/tokenstream.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-11-25 09:28:59 +0000
committerbors <bors@rust-lang.org>2019-11-25 09:28:59 +0000
commit582a4eaee6b3674a34aeefaa5ecad0207bac9b4b (patch)
tree6c33a566e5fc413793dba4c935ffc7b4b969b255 /src/libsyntax/tokenstream.rs
parent4eee955502558a049df75b4313a60cf57c885aa6 (diff)
parent782cc9f65c0c19ef79bd009074e09bf0394674f4 (diff)
downloadrust-582a4eaee6b3674a34aeefaa5ecad0207bac9b4b.tar.gz
rust-582a4eaee6b3674a34aeefaa5ecad0207bac9b4b.zip
Auto merge of #66279 - cjgillot:hashstable, r=Zoxc
Use proc-macro to derive HashStable everywhere

Hello,

A second proc-macro is added to derive HashStable for crates librustc depends on.
This proc-macro `HashStable_Generic` (to bikeshed) allows to decouple code and strip much of librustc's boilerplate.

Still, two implementations `Span` and `TokenKind` require to be placed in librustc.
The latter only depends on the `bug` macro. Advise welcome on how to sever that link.
A trait `StableHasingContextLike` has been introduced at each crate root,
in order to handle those implementations which require librustc's very `StableHashingContext`.

This overall effort allowed to remove the `impl_stable_hash_for` macro.

Each commit passes the `x.py check`.
I still have to double check there was no change in the implementation.
Diffstat (limited to 'src/libsyntax/tokenstream.rs')
-rw-r--r--src/libsyntax/tokenstream.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs
index 2201f1ed6ca..6a0523dd655 100644
--- a/src/libsyntax/tokenstream.rs
+++ b/src/libsyntax/tokenstream.rs
@@ -16,6 +16,8 @@
 use crate::token::{self, DelimToken, Token, TokenKind};
 
 use syntax_pos::{Span, DUMMY_SP};
+use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
+use rustc_macros::HashStable_Generic;
 use rustc_data_structures::sync::Lrc;
 use smallvec::{SmallVec, smallvec};
 
@@ -33,7 +35,7 @@ use std::{iter, mem};
 ///
 /// The RHS of an MBE macro is the only place `SubstNt`s are substituted.
 /// Nothing special happens to misnamed or misplaced `SubstNt`s.
-#[derive(Debug, Clone, PartialEq, RustcEncodable, RustcDecodable)]
+#[derive(Debug, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)]
 pub enum TokenTree {
     /// A single token
     Token(Token),
@@ -115,6 +117,16 @@ impl TokenTree {
     }
 }
 
+impl<CTX> HashStable<CTX> for TokenStream
+    where CTX: crate::HashStableContext
+{
+    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
@@ -444,7 +456,7 @@ impl Cursor {
     }
 }
 
-#[derive(Debug, Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
+#[derive(Debug, Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)]
 pub struct DelimSpan {
     pub open: Span,
     pub close: Span,