From 05f5f76b3b2b225420d81b5ad632e4aadd882595 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 21:07:58 +0100 Subject: Move impl HashStable for SymbolStr in libsyntax_pos. --- src/libsyntax_pos/symbol.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/libsyntax_pos') diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 86eaeeab5a4..63368831614 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -8,6 +8,7 @@ use rustc_index::vec::Idx; use rustc_macros::symbols; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{UseSpecializedDecodable, UseSpecializedEncodable}; +use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; use std::cmp::{PartialEq, PartialOrd, Ord}; use std::fmt; @@ -1136,3 +1137,20 @@ impl fmt::Display for SymbolStr { fmt::Display::fmt(self.string, f) } } + +impl HashStable for SymbolStr { + #[inline] + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + let str = self as &str; + str.hash_stable(hcx, hasher) + } +} + +impl ToStableHashKey for SymbolStr { + type KeyType = SymbolStr; + + #[inline] + fn to_stable_hash_key(&self, _: &CTX) -> SymbolStr { + self.clone() + } +} -- cgit 1.4.1-3-g733a5 From 1dd5133dce33fed1cffea9bc6fb6ee4f37dc7053 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 21:17:21 +0100 Subject: Move impl HashStable for Symbol in libsyntax_pos. --- src/librustc/ich/impls_syntax.rs | 21 +-------------------- src/libsyntax_pos/symbol.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 20 deletions(-) (limited to 'src/libsyntax_pos') diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 4a331cbf40d..005d03f4d0a 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -10,31 +10,12 @@ use syntax::ast; use syntax::feature_gate; use syntax::token; use syntax::tokenstream; -use syntax_pos::symbol::SymbolStr; use syntax_pos::SourceFile; use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX}; use smallvec::SmallVec; -use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; - -impl<'a> HashStable> for ast::Name { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.as_str().hash_stable(hcx, hasher); - } -} - -impl<'a> ToStableHashKey> for ast::Name { - type KeyType = SymbolStr; - - #[inline] - fn to_stable_hash_key(&self, - _: &StableHashingContext<'a>) - -> SymbolStr { - self.as_str() - } -} +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; impl_stable_hash_for!(enum ::syntax_pos::hygiene::MacroKind { Bang, diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 63368831614..f6377633857 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -940,6 +940,22 @@ impl Decodable for Symbol { } } +impl HashStable for Symbol { + #[inline] + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + self.as_str().hash_stable(hcx, hasher); + } +} + +impl ToStableHashKey for Symbol { + type KeyType = SymbolStr; + + #[inline] + fn to_stable_hash_key(&self, _: &CTX) -> SymbolStr { + self.as_str() + } +} + // The `&'static str`s in this type actually point into the arena. #[derive(Default)] pub struct Interner { -- cgit 1.4.1-3-g733a5 From efcb695f4c38f653d8f0adb70f94aa29328be679 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 21:34:12 +0100 Subject: Further HashStable_Generic derives. --- src/librustc/ich/impls_syntax.rs | 47 ---------------------------------------- src/libsyntax/ast.rs | 2 +- src/libsyntax/attr/builtin.rs | 11 ++++++---- src/libsyntax_pos/hygiene.rs | 4 +++- 4 files changed, 11 insertions(+), 53 deletions(-) (limited to 'src/libsyntax_pos') diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 005d03f4d0a..bf716dbf061 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -17,13 +17,6 @@ use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX}; use smallvec::SmallVec; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -impl_stable_hash_for!(enum ::syntax_pos::hygiene::MacroKind { - Bang, - Attr, - Derive, -}); - - impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi { Cdecl, Stdcall, @@ -47,57 +40,17 @@ impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi { Unadjusted }); -impl_stable_hash_for!(struct ::syntax::attr::Deprecation { since, note }); -impl_stable_hash_for!(struct ::syntax::attr::Stability { - level, - feature, - rustc_depr, - promotable, - allow_const_fn_ptr, - const_stability -}); - impl_stable_hash_for!(enum ::syntax::edition::Edition { Edition2015, Edition2018, }); -impl<'a> HashStable> -for ::syntax::attr::StabilityLevel { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - ::syntax::attr::StabilityLevel::Unstable { ref reason, ref issue, ref is_soft } => { - reason.hash_stable(hcx, hasher); - issue.hash_stable(hcx, hasher); - is_soft.hash_stable(hcx, hasher); - } - ::syntax::attr::StabilityLevel::Stable { ref since } => { - since.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct ::syntax::attr::RustcDeprecation { since, reason, suggestion }); - impl_stable_hash_for!(struct ::syntax::ast::Lit { kind, token, span }); -impl_stable_hash_for!(enum ::syntax::ast::LitKind { - Str(value, style), - ByteStr(value), - Byte(value), - Char(value), - Int(value, lit_int_type), - Float(value, lit_float_type), - Bool(value), - Err(value) -}); - impl_stable_hash_for_spanned!(::syntax::ast::LitKind); impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident }); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index fb9c7e9bd56..19a8398ae78 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1474,7 +1474,7 @@ pub enum LitFloatType { /// /// E.g., `"foo"`, `42`, `12.34`, or `bool`. // Clippy uses Hash and PartialEq -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)] pub enum LitKind { /// A string literal (`"foo"`). Str(Symbol, StrStyle), diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index d7f4c9469f6..6032e8a5b21 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -141,7 +141,8 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op } /// Represents the #[stable], #[unstable], #[rustc_{deprecated,const_unstable}] attributes. -#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, + PartialEq, Eq, Hash, HashStable_Generic)] pub struct Stability { pub level: StabilityLevel, pub feature: Symbol, @@ -157,7 +158,8 @@ pub struct Stability { } /// The available stability levels. -#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)] +#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, + Copy, Clone, Debug, Eq, Hash, HashStable_Generic)] pub enum StabilityLevel { // Reason for the current stability level and the relevant rust-lang issue Unstable { reason: Option, issue: Option, is_soft: bool }, @@ -181,7 +183,8 @@ impl StabilityLevel { } } -#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)] +#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, + Copy, Clone, Debug, Eq, Hash, HashStable_Generic)] pub struct RustcDeprecation { pub since: Symbol, pub reason: Symbol, @@ -636,7 +639,7 @@ pub fn eval_condition(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F) } } -#[derive(RustcEncodable, RustcDecodable, Clone)] +#[derive(RustcEncodable, RustcDecodable, Clone, HashStable_Generic)] pub struct Deprecation { pub since: Option, pub note: Option, diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 2a48f8e44aa..daabd0569dc 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -30,6 +30,7 @@ use crate::{Span, DUMMY_SP}; use crate::edition::Edition; use crate::symbol::{kw, sym, Symbol}; +use rustc_macros::HashStable_Generic; use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; @@ -707,7 +708,8 @@ impl ExpnKind { } /// The kind of macro invocation or definition. -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, + Hash, Debug, HashStable_Generic)] pub enum MacroKind { /// A bang macro `foo!()`. Bang, -- cgit 1.4.1-3-g733a5 From a265bc22f161c7399c5a35835305d2dacf24753a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 22:25:30 +0100 Subject: HashStable_Generic for libsyntax_pos. --- src/librustc/ich/impls_syntax.rs | 48 ---------------------------------------- src/libsyntax_pos/edition.rs | 5 ++++- src/libsyntax_pos/hygiene.rs | 9 ++++---- src/libsyntax_pos/lib.rs | 4 +++- 4 files changed, 12 insertions(+), 54 deletions(-) (limited to 'src/libsyntax_pos') diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index d86fd0f1dc3..42d6576ba6d 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -40,11 +40,6 @@ impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi { Unadjusted }); -impl_stable_hash_for!(enum ::syntax::edition::Edition { - Edition2015, - Edition2018, -}); - impl_stable_hash_for!(struct ::syntax::ast::Lit { kind, token, @@ -222,12 +217,6 @@ impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind { NameValue(lit) }); -impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency { - Transparent, - SemiTransparent, - Opaque, -}); - impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData { kind, parent -> _, @@ -239,43 +228,6 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData { edition }); -impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind { - Root, - Macro(kind, descr), - AstPass(kind), - Desugaring(kind) -}); - -impl_stable_hash_for!(enum ::syntax_pos::hygiene::AstPass { - StdImports, - TestHarness, - ProcMacroHarness, - PluginMacroDefs, -}); - -impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind { - CondTemporary, - Async, - Await, - QuestionMark, - OpaqueTy, - ForLoop, - TryBlock -}); - -impl_stable_hash_for!(enum ::syntax_pos::FileName { - Real(pb), - Macros(s), - QuoteExpansion(s), - Anon(s), - MacroExpansion(s), - ProcMacroSourceCode(s), - CliCrateAttr(s), - CfgSpec(s), - Custom(s), - DocTest(pb, line), -}); - impl<'a> HashStable> for SourceFile { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let SourceFile { diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs index 00cd00f2837..727aad546f5 100644 --- a/src/libsyntax_pos/edition.rs +++ b/src/libsyntax_pos/edition.rs @@ -2,8 +2,11 @@ use crate::symbol::{Symbol, sym}; use std::fmt; use std::str::FromStr; +use rustc_macros::HashStable_Generic; + /// The edition of the compiler (RFC 2052) -#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable, Eq)] +#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, + RustcEncodable, RustcDecodable, Eq, HashStable_Generic)] pub enum Edition { // editions must be kept in order, oldest to newest diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index daabd0569dc..eb420454f03 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -59,7 +59,8 @@ pub struct ExpnId(u32); /// A property of a macro expansion that determines how identifiers /// produced by that expansion are resolved. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug, + RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum Transparency { /// Identifier produced by a transparent expansion is always resolved at call-site. /// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this. @@ -684,7 +685,7 @@ impl ExpnData { } /// Expansion kind. -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum ExpnKind { /// No expansion, aka root expansion. Only `ExpnId::root()` has this kind. Root, @@ -744,7 +745,7 @@ impl MacroKind { } /// The kind of AST transform. -#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum AstPass { StdImports, TestHarness, @@ -764,7 +765,7 @@ impl AstPass { } /// The kind of compiler desugaring. -#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum DesugaringKind { /// We desugar `if c { i } else { e }` to `match $ExprKind::Use(c) { true => i, _ => e }`. /// However, we do not want to blame `c` for unreachability but rather say that `i` diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index b88d6dbc3f3..720ace90324 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -15,6 +15,7 @@ #![feature(step_trait)] use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; +use rustc_macros::HashStable_Generic; pub mod source_map; @@ -66,7 +67,8 @@ impl Globals { scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals); /// Differentiates between real files and common virtual files. -#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)] +#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, + RustcDecodable, RustcEncodable, HashStable_Generic)] pub enum FileName { Real(PathBuf), /// A macro. This includes the full name of the macro, so that there are no clashes. -- cgit 1.4.1-3-g733a5 From 44a595f52ca0dec2cf7a08ba182ce9f1eb637795 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 16 Nov 2019 11:59:46 +0100 Subject: Simplify impl for SymbolStr. --- src/libsyntax_pos/symbol.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/libsyntax_pos') diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index f6377633857..d885133db65 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -1157,8 +1157,7 @@ impl fmt::Display for SymbolStr { impl HashStable for SymbolStr { #[inline] fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { - let str = self as &str; - str.hash_stable(hcx, hasher) + self.string.hash_stable(hcx, hasher) } } -- cgit 1.4.1-3-g733a5