@@ -22,9 +22,8 @@ use std::{cmp, fmt, iter, mem};
2222use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
2323use rustc_data_structures:: sync;
2424use rustc_macros:: { Decodable , Encodable , HashStable_Generic , Walkable } ;
25- use rustc_serialize:: { Decodable , Encodable , Encoder } ;
26- use rustc_span:: def_id:: { CrateNum , DefIndex } ;
27- use rustc_span:: { ByteSymbol , DUMMY_SP , Span , SpanDecoder , SpanEncoder , Symbol , sym} ;
25+ use rustc_serialize:: { Decodable , Encodable } ;
26+ use rustc_span:: { DUMMY_SP , Span , SpanDecoder , SpanEncoder , Symbol , sym} ;
2827use thin_vec:: ThinVec ;
2928
3029use crate :: ast:: AttrStyle ;
@@ -33,7 +32,7 @@ use crate::token::{self, Delimiter, Token, TokenKind};
3332use crate :: { AttrVec , Attribute } ;
3433
3534/// Part of a `TokenStream`.
36- #[ derive( Debug , Clone , PartialEq , Encodable , Decodable , HashStable_Generic ) ]
35+ #[ derive( Debug , Clone , PartialEq , Hash , Encodable , Decodable , HashStable_Generic ) ]
3736pub enum TokenTree {
3837 /// A single token. Should never be `OpenDelim` or `CloseDelim`, because
3938 /// delimiters are implicitly represented by `Delimited`.
@@ -559,110 +558,14 @@ pub struct AttrsTarget {
559558}
560559
561560/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
562- #[ derive( Clone , Debug , Default , Encodable , Decodable ) ]
561+ #[ derive( Clone , Debug , Default , Hash , Encodable , Decodable ) ]
563562pub struct TokenStream ( pub ( crate ) Arc < Vec < TokenTree > > ) ;
564563
565- struct HashEncoder < H : std:: hash:: Hasher > {
566- hasher : H ,
567- }
568-
569- impl < H : std:: hash:: Hasher > Encoder for HashEncoder < H > {
570- fn emit_usize ( & mut self , v : usize ) {
571- self . hasher . write_usize ( v)
572- }
573-
574- fn emit_u128 ( & mut self , v : u128 ) {
575- self . hasher . write_u128 ( v)
576- }
577-
578- fn emit_u64 ( & mut self , v : u64 ) {
579- self . hasher . write_u64 ( v)
580- }
581-
582- fn emit_u32 ( & mut self , v : u32 ) {
583- self . hasher . write_u32 ( v)
584- }
585-
586- fn emit_u16 ( & mut self , v : u16 ) {
587- self . hasher . write_u16 ( v)
588- }
589-
590- fn emit_u8 ( & mut self , v : u8 ) {
591- self . hasher . write_u8 ( v)
592- }
593-
594- fn emit_isize ( & mut self , v : isize ) {
595- self . hasher . write_isize ( v)
596- }
597-
598- fn emit_i128 ( & mut self , v : i128 ) {
599- self . hasher . write_i128 ( v)
600- }
601-
602- fn emit_i64 ( & mut self , v : i64 ) {
603- self . hasher . write_i64 ( v)
604- }
605-
606- fn emit_i32 ( & mut self , v : i32 ) {
607- self . hasher . write_i32 ( v)
608- }
609-
610- fn emit_i16 ( & mut self , v : i16 ) {
611- self . hasher . write_i16 ( v)
612- }
613-
614- fn emit_raw_bytes ( & mut self , s : & [ u8 ] ) {
615- self . hasher . write ( s)
616- }
617- }
618-
619- impl < H : std:: hash:: Hasher > SpanEncoder for HashEncoder < H > {
620- fn encode_span ( & mut self , span : Span ) {
621- span. hash ( & mut self . hasher )
622- }
623-
624- fn encode_symbol ( & mut self , symbol : Symbol ) {
625- symbol. hash ( & mut self . hasher )
626- }
627-
628- fn encode_byte_symbol ( & mut self , byte_sym : ByteSymbol ) {
629- byte_sym. hash ( & mut self . hasher ) ;
630- }
631-
632- fn encode_expn_id ( & mut self , expn_id : rustc_span:: ExpnId ) {
633- expn_id. hash ( & mut self . hasher )
634- }
635-
636- fn encode_syntax_context ( & mut self , syntax_context : rustc_span:: SyntaxContext ) {
637- syntax_context. hash ( & mut self . hasher )
638- }
639-
640- fn encode_crate_num ( & mut self , crate_num : CrateNum ) {
641- crate_num. hash ( & mut self . hasher )
642- }
643-
644- fn encode_def_index ( & mut self , def_index : DefIndex ) {
645- def_index. hash ( & mut self . hasher )
646- }
647-
648- fn encode_def_id ( & mut self , def_id : rustc_span:: def_id:: DefId ) {
649- def_id. hash ( & mut self . hasher )
650- }
651- }
652-
653- /// TokenStream needs to be hashable because it is used as a query key for caching derive macro
654- /// expansions.
655- impl Hash for TokenStream {
656- fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
657- Encodable :: encode ( self , & mut HashEncoder { hasher : state } ) ;
658- }
659- }
660-
661564/// Indicates whether a token can join with the following token to form a
662565/// compound token. Used for conversions to `proc_macro::Spacing`. Also used to
663566/// guide pretty-printing, which is where the `JointHidden` value (which isn't
664567/// part of `proc_macro::Spacing`) comes in useful.
665- #[ derive( Clone , Copy , Debug , PartialEq , Encodable , Decodable , HashStable_Generic ) ]
568+ #[ derive( Clone , Copy , Debug , PartialEq , Hash , Encodable , Decodable , HashStable_Generic ) ]
666569pub enum Spacing {
667570 /// The token cannot join with the following token to form a compound
668571 /// token.
@@ -1075,7 +978,7 @@ impl TokenCursor {
1075978 }
1076979}
1077980
1078- #[ derive( Debug , Copy , Clone , PartialEq , Encodable , Decodable , HashStable_Generic , Walkable ) ]
981+ #[ derive( Debug , Copy , Clone , PartialEq , Hash , Encodable , Decodable , HashStable_Generic , Walkable ) ]
1079982pub struct DelimSpan {
1080983 pub open : Span ,
1081984 pub close : Span ,
@@ -1099,7 +1002,7 @@ impl DelimSpan {
10991002 }
11001003}
11011004
1102- #[ derive( Copy , Clone , Debug , PartialEq , Encodable , Decodable , HashStable_Generic ) ]
1005+ #[ derive( Copy , Clone , Debug , PartialEq , Hash , Encodable , Decodable , HashStable_Generic ) ]
11031006pub struct DelimSpacing {
11041007 pub open : Spacing ,
11051008 pub close : Spacing ,
0 commit comments