From c2e1658c6758ccbc1e12e37193e9780398368698 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 20:56:19 +0100 Subject: Use proc_macro for HashStable derive in libsyntax. --- src/libsyntax/Cargo.toml | 1 + src/libsyntax/ast.rs | 33 ++++++++++++++++++--------------- src/libsyntax/attr/builtin.rs | 2 +- src/libsyntax/lib.rs | 2 ++ 4 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/Cargo.toml b/src/libsyntax/Cargo.toml index d96b5b7a3dd..dff23076c82 100644 --- a/src/libsyntax/Cargo.toml +++ b/src/libsyntax/Cargo.toml @@ -20,5 +20,6 @@ errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_index = { path = "../librustc_index" } rustc_lexer = { path = "../librustc_lexer" } +rustc_macros = { path = "../librustc_macros" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_error_codes = { path = "../librustc_error_codes" } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index bbf00825acb..fb9c7e9bd56 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1328,7 +1328,7 @@ pub struct QSelf { } /// A capture clause used in closures and `async` blocks. -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum CaptureBy { /// `move |x| y + x`. Value, @@ -1339,7 +1339,7 @@ pub enum CaptureBy { /// The movability of a generator / closure literal: /// whether a generator contains self-references, causing it to be `!Unpin`. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, - RustcEncodable, RustcDecodable, Debug, Copy)] + RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] pub enum Movability { /// May contain self-references, `!Unpin`. Static, @@ -1400,7 +1400,7 @@ impl MacroDef { } // Clippy uses Hash and PartialEq -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, PartialEq)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, PartialEq, HashStable_Generic)] pub enum StrStyle { /// A regular string, like `"foo"`. Cooked, @@ -1451,7 +1451,7 @@ impl StrLit { // Clippy uses Hash and PartialEq /// Type of the integer literal based on provided suffix. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)] +#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)] pub enum LitIntType { /// e.g. `42_i32`. Signed(IntTy), @@ -1462,7 +1462,7 @@ pub enum LitIntType { } /// Type of the float literal based on provided suffix. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)] +#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)] pub enum LitFloatType { /// A float literal with a suffix (`1f32` or `1E10f32`). Suffixed(FloatTy), @@ -1609,7 +1609,8 @@ pub enum ImplItemKind { Macro(Mac), } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, + RustcEncodable, RustcDecodable, Debug)] pub enum FloatTy { F32, F64, @@ -1638,7 +1639,8 @@ impl FloatTy { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, + RustcEncodable, RustcDecodable, Debug)] pub enum IntTy { Isize, I8, @@ -1690,7 +1692,8 @@ impl IntTy { } } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Copy, Debug)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, + RustcEncodable, RustcDecodable, Copy, Debug)] pub enum UintTy { Usize, U8, @@ -1863,7 +1866,7 @@ pub enum TraitObjectSyntax { /// Inline assembly dialect. /// /// E.g., `"intel"` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] pub enum AsmDialect { Att, Intel, @@ -2021,14 +2024,14 @@ impl FnDecl { } /// Is the trait definition an auto trait? -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum IsAuto { Yes, No, } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, - RustcEncodable, RustcDecodable, Debug)] + RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum Unsafety { Unsafe, Normal, @@ -2085,7 +2088,7 @@ impl IsAsync { } } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum Constness { Const, NotConst, @@ -2093,13 +2096,13 @@ pub enum Constness { /// Item defaultness. /// For details see the [RFC #2532](https://github.com/rust-lang/rfcs/pull/2532). -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum Defaultness { Default, Final, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum ImplPolarity { /// `impl Trait for Type` Positive, @@ -2233,7 +2236,7 @@ impl UseTree { /// Distinguishes between `Attribute`s that decorate items and Attributes that /// are contained as statements within items. These two cases need to be /// distinguished for pretty-printing. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] pub enum AttrStyle { Outer, Inner, diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 767fcabc017..d7f4c9469f6 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -763,7 +763,7 @@ pub enum ReprAttr { ReprAlign(u32), } -#[derive(Eq, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)] +#[derive(Eq, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone, HashStable_Generic)] pub enum IntType { SignedInt(ast::IntTy), UnsignedInt(ast::UintTy) diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index e3eca75dfe7..23db4cf985c 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -19,6 +19,8 @@ #![recursion_limit="256"] +#[macro_use] extern crate rustc_macros; + pub use errors; use rustc_data_structures::sync::Lock; use rustc_index::bit_set::GrowableBitSet; -- 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') 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 2a67986eb6970f5ec1d4df8e409f04397568935b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 22:02:24 +0100 Subject: HashStable literals in libsyntax. --- src/librustc/ich/impls_syntax.rs | 19 ------------------- src/libsyntax/token.rs | 4 ++-- 2 files changed, 2 insertions(+), 21 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index bf716dbf061..d86fd0f1dc3 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -137,25 +137,6 @@ for tokenstream::TokenStream { } } -impl_stable_hash_for!(enum token::LitKind { - Bool, - Byte, - Char, - Integer, - Float, - Str, - ByteStr, - StrRaw(n), - ByteStrRaw(n), - Err -}); - -impl_stable_hash_for!(struct token::Lit { - kind, - symbol, - suffix -}); - impl<'a> HashStable> for token::TokenKind { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); diff --git a/src/libsyntax/token.rs b/src/libsyntax/token.rs index ab798e93d67..8099b55780c 100644 --- a/src/libsyntax/token.rs +++ b/src/libsyntax/token.rs @@ -53,7 +53,7 @@ impl DelimToken { } } -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum LitKind { Bool, // AST only, must never appear in a `Token` Byte, @@ -68,7 +68,7 @@ pub enum LitKind { } /// A literal token. -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Lit { pub kind: LitKind, pub symbol: Symbol, -- cgit 1.4.1-3-g733a5 From 375a7613036f92881f8cbc6e9cde186ee7a326c7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Nov 2019 23:18:36 +0100 Subject: HashStable in libsyntax. --- src/librustc/ich/impls_hir.rs | 5 ----- src/librustc/ich/impls_ty.rs | 5 ----- src/libsyntax/ast.rs | 7 +++---- 3 files changed, 3 insertions(+), 14 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index c0255e5b8a4..bec1a14d612 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -220,11 +220,6 @@ impl<'a> HashStable> for hir::ImplItem { } } -impl_stable_hash_for!(enum ast::CrateSugar { - JustCrate, - PubCrate, -}); - impl<'a> HashStable> for hir::VisibilityKind { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index c643baf1125..7f50d859cde 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -159,11 +159,6 @@ where } } -impl_stable_hash_for!(enum ::syntax::ast::Mutability { - Immutable, - Mutable -}); - impl<'a> ToStableHashKey> for region::Scope { type KeyType = region::Scope; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 19a8398ae78..aa658986d87 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -722,9 +722,8 @@ pub enum PatKind { Mac(Mac), } -#[derive( - Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug, Copy, -)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, + RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] pub enum Mutability { Mutable, Immutable, @@ -2334,7 +2333,7 @@ impl PolyTraitRef { } } -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum CrateSugar { /// Source is `pub(crate)`. PubCrate, -- cgit 1.4.1-3-g733a5 From 3d97a91e7f896e8fbb94fef43dd57f2e6fb061c8 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 16 Nov 2019 11:53:44 +0100 Subject: Remove extern crate. --- src/libsyntax/ast.rs | 1 + src/libsyntax/attr/builtin.rs | 1 + src/libsyntax/lib.rs | 2 -- src/libsyntax/token.rs | 1 + 4 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index aa658986d87..a9f03e4af5b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -37,6 +37,7 @@ use rustc_data_structures::sync::Lrc; use rustc_data_structures::thin_vec::ThinVec; use rustc_index::vec::Idx; use rustc_serialize::{self, Decoder, Encoder}; +use rustc_macros::HashStable_Generic; use std::fmt; diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 6032e8a5b21..c10541c8c7e 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -9,6 +9,7 @@ use errors::{Applicability, Handler}; use std::num::NonZeroU32; use syntax_pos::hygiene::Transparency; use syntax_pos::{symbol::Symbol, symbol::sym, Span}; +use rustc_macros::HashStable_Generic; use super::{mark_used, MetaItemKind}; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 23db4cf985c..e3eca75dfe7 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -19,8 +19,6 @@ #![recursion_limit="256"] -#[macro_use] extern crate rustc_macros; - pub use errors; use rustc_data_structures::sync::Lock; use rustc_index::bit_set::GrowableBitSet; diff --git a/src/libsyntax/token.rs b/src/libsyntax/token.rs index 8099b55780c..fd1623384a4 100644 --- a/src/libsyntax/token.rs +++ b/src/libsyntax/token.rs @@ -15,6 +15,7 @@ use syntax_pos::{self, Span, DUMMY_SP}; use std::fmt; use std::mem; use rustc_data_structures::sync::Lrc; +use rustc_macros::HashStable_Generic; #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum BinOpToken { -- cgit 1.4.1-3-g733a5