From 782cc9f65c0c19ef79bd009074e09bf0394674f4 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 23 Nov 2019 14:47:31 +0100 Subject: Derive HashStable for TokenKind. --- src/libsyntax/lib.rs | 5 +---- src/libsyntax/token.rs | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 579d2657939..22b49862f49 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -20,7 +20,6 @@ #![recursion_limit="256"] pub use errors; -use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::sync::Lock; use rustc_index::bit_set::GrowableBitSet; pub use rustc_data_structures::thin_vec::ThinVec; @@ -115,6 +114,4 @@ pub mod early_buffered_lints; /// Requirements for a `StableHashingContext` to be used in this crate. /// This is a hack to allow using the `HashStable_Generic` derive macro /// instead of implementing everything in librustc. -pub trait HashStableContext: syntax_pos::HashStableContext { - fn hash_stable_tokenkind(&mut self, tokenkind: &token::TokenKind, hasher: &mut StableHasher); -} +pub trait HashStableContext: syntax_pos::HashStableContext {} diff --git a/src/libsyntax/token.rs b/src/libsyntax/token.rs index 045e9f8689f..6f45211ac5f 100644 --- a/src/libsyntax/token.rs +++ b/src/libsyntax/token.rs @@ -19,6 +19,7 @@ use rustc_data_structures::sync::Lrc; use rustc_macros::HashStable_Generic; #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(HashStable_Generic)] pub enum BinOpToken { Plus, Minus, @@ -192,7 +193,7 @@ fn ident_can_begin_type(name: ast::Name, span: Span, is_raw: bool) -> bool { ].contains(&name) } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum TokenKind { /* Expression-operator symbols. */ Eq, @@ -264,14 +265,6 @@ pub enum TokenKind { #[cfg(target_arch = "x86_64")] rustc_data_structures::static_assert_size!(TokenKind, 16); -impl HashStable for TokenKind - where CTX: crate::HashStableContext -{ - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { - hcx.hash_stable_tokenkind(self, hasher) - } -} - #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Token { pub kind: TokenKind, @@ -735,3 +728,11 @@ impl fmt::Debug for Nonterminal { } } } + +impl HashStable for Nonterminal + where CTX: crate::HashStableContext +{ + fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) { + panic!("interpolated tokens should not be present in the HIR") + } +} -- cgit 1.4.1-3-g733a5