Skip to content

Commit 782cc9f

Browse files
committed
Derive HashStable for TokenKind.
1 parent 4d1674f commit 782cc9f

File tree

3 files changed

+12
-79
lines changed

3 files changed

+12
-79
lines changed

src/librustc/ich/impls_syntax.rs

+1-66
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
44
use crate::ich::StableHashingContext;
55

6-
use std::hash as std_hash;
7-
use std::mem;
8-
96
use syntax::ast;
107
use syntax::feature_gate;
11-
use syntax::token;
128
use syntax_pos::SourceFile;
139

1410
use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
@@ -65,68 +61,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ast::Attribute {
6561
}
6662
}
6763

68-
impl<'ctx> syntax::HashStableContext for StableHashingContext<'ctx> {
69-
fn hash_stable_tokenkind(&mut self, tokenkind: &token::TokenKind, hasher: &mut StableHasher) {
70-
mem::discriminant(tokenkind).hash_stable(self, hasher);
71-
match *tokenkind {
72-
token::Eq |
73-
token::Lt |
74-
token::Le |
75-
token::EqEq |
76-
token::Ne |
77-
token::Ge |
78-
token::Gt |
79-
token::AndAnd |
80-
token::OrOr |
81-
token::Not |
82-
token::Tilde |
83-
token::At |
84-
token::Dot |
85-
token::DotDot |
86-
token::DotDotDot |
87-
token::DotDotEq |
88-
token::Comma |
89-
token::Semi |
90-
token::Colon |
91-
token::ModSep |
92-
token::RArrow |
93-
token::LArrow |
94-
token::FatArrow |
95-
token::Pound |
96-
token::Dollar |
97-
token::Question |
98-
token::SingleQuote |
99-
token::Whitespace |
100-
token::Comment |
101-
token::Eof => {}
102-
103-
token::BinOp(bin_op_token) |
104-
token::BinOpEq(bin_op_token) => {
105-
std_hash::Hash::hash(&bin_op_token, hasher);
106-
}
107-
108-
token::OpenDelim(delim_token) |
109-
token::CloseDelim(delim_token) => {
110-
std_hash::Hash::hash(&delim_token, hasher);
111-
}
112-
token::Literal(lit) => lit.hash_stable(self, hasher),
113-
114-
token::Ident(name, is_raw) => {
115-
name.hash_stable(self, hasher);
116-
is_raw.hash_stable(self, hasher);
117-
}
118-
token::Lifetime(name) => name.hash_stable(self, hasher),
119-
120-
token::Interpolated(_) => {
121-
bug!("interpolated tokens should not be present in the HIR")
122-
}
123-
124-
token::DocComment(val) |
125-
token::Shebang(val) |
126-
token::Unknown(val) => val.hash_stable(self, hasher),
127-
}
128-
}
129-
}
64+
impl<'ctx> syntax::HashStableContext for StableHashingContext<'ctx> {}
13065

13166
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
13267
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {

src/libsyntax/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![recursion_limit="256"]
2121

2222
pub use errors;
23-
use rustc_data_structures::stable_hasher::StableHasher;
2423
use rustc_data_structures::sync::Lock;
2524
use rustc_index::bit_set::GrowableBitSet;
2625
pub use rustc_data_structures::thin_vec::ThinVec;
@@ -115,6 +114,4 @@ pub mod early_buffered_lints;
115114
/// Requirements for a `StableHashingContext` to be used in this crate.
116115
/// This is a hack to allow using the `HashStable_Generic` derive macro
117116
/// instead of implementing everything in librustc.
118-
pub trait HashStableContext: syntax_pos::HashStableContext {
119-
fn hash_stable_tokenkind(&mut self, tokenkind: &token::TokenKind, hasher: &mut StableHasher);
120-
}
117+
pub trait HashStableContext: syntax_pos::HashStableContext {}

src/libsyntax/token.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_data_structures::sync::Lrc;
1919
use rustc_macros::HashStable_Generic;
2020

2121
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
22+
#[derive(HashStable_Generic)]
2223
pub enum BinOpToken {
2324
Plus,
2425
Minus,
@@ -192,7 +193,7 @@ fn ident_can_begin_type(name: ast::Name, span: Span, is_raw: bool) -> bool {
192193
].contains(&name)
193194
}
194195

195-
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
196+
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
196197
pub enum TokenKind {
197198
/* Expression-operator symbols. */
198199
Eq,
@@ -264,14 +265,6 @@ pub enum TokenKind {
264265
#[cfg(target_arch = "x86_64")]
265266
rustc_data_structures::static_assert_size!(TokenKind, 16);
266267

267-
impl<CTX> HashStable<CTX> for TokenKind
268-
where CTX: crate::HashStableContext
269-
{
270-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
271-
hcx.hash_stable_tokenkind(self, hasher)
272-
}
273-
}
274-
275268
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
276269
pub struct Token {
277270
pub kind: TokenKind,
@@ -735,3 +728,11 @@ impl fmt::Debug for Nonterminal {
735728
}
736729
}
737730
}
731+
732+
impl<CTX> HashStable<CTX> for Nonterminal
733+
where CTX: crate::HashStableContext
734+
{
735+
fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) {
736+
panic!("interpolated tokens should not be present in the HIR")
737+
}
738+
}

0 commit comments

Comments
 (0)