From 4d1a30c92b50c5965ed26449758fca81bee15747 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 21 Mar 2018 01:58:25 +0300 Subject: Remove most of `PartialEq` impls from AST and HIR structures --- src/libsyntax/parse/attr.rs | 4 ++-- src/libsyntax/parse/lexer/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 10 +++++----- src/libsyntax/parse/token.rs | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 9919d910fbc..4d59f64bb6b 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -16,7 +16,7 @@ use parse::token::{self, Nonterminal}; use parse::parser::{Parser, TokenType, PathStyle}; use tokenstream::TokenStream; -#[derive(PartialEq, Eq, Debug)] +#[derive(Debug)] enum InnerAttributeParsePolicy<'a> { Permitted, NotPermitted { reason: &'a str }, @@ -94,7 +94,7 @@ impl<'a> Parser<'a> { let lo = self.span; self.bump(); - if inner_parse_policy == InnerAttributeParsePolicy::Permitted { + if let InnerAttributeParsePolicy::Permitted = inner_parse_policy { self.expected_tokens.push(TokenType::Token(token::Not)); } let style = if self.token == token::Not { diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index dcc71e78778..92fcf865042 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -26,7 +26,7 @@ pub mod comments; mod tokentrees; mod unicode_chars; -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Clone, Debug)] pub struct TokenAndSpan { pub tok: token::Token, pub sp: Span, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a1b78a23b8f..8bd4a7d71d7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -95,13 +95,13 @@ pub enum PathStyle { Mod, } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, PartialEq, Debug)] enum SemiColonMode { Break, Ignore, } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, PartialEq, Debug)] enum BlockMode { Break, Ignore, @@ -376,7 +376,7 @@ impl TokenCursor { } } -#[derive(PartialEq, Eq, Clone)] +#[derive(Clone, PartialEq)] crate enum TokenType { Token(token::Token), Keyword(keywords::Keyword), @@ -522,7 +522,7 @@ fn dummy_arg(span: Span) -> Arg { Arg { ty: P(ty), pat: pat, id: ast::DUMMY_NODE_ID } } -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug)] enum TokenExpectType { Expect, NoExpect, @@ -6999,7 +6999,7 @@ impl<'a> Parser<'a> { // Verify whether we have encountered a struct or method definition where the user forgot to // add the `struct` or `fn` keyword after writing `pub`: `pub S {}` - if visibility.node == VisibilityKind::Public && + if visibility.node.is_public() && self.check_ident() && self.look_ahead(1, |t| *t != token::Not) { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 7ea047d332b..8e9c192c737 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -30,7 +30,7 @@ use std::{cmp, fmt}; use std::mem; use rustc_data_structures::sync::{Lrc, Lock}; -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum BinOpToken { Plus, Minus, @@ -45,7 +45,7 @@ pub enum BinOpToken { } /// A delimiter token -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum DelimToken { /// A round parenthesis: `(` or `)` Paren, @@ -67,7 +67,7 @@ impl DelimToken { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum Lit { Byte(ast::Name), Char(ast::Name), @@ -139,7 +139,7 @@ fn ident_can_begin_type(ident: ast::Ident, is_raw: bool) -> bool { ].contains(&ident.name) } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Hash, Debug)] pub enum Token { /* Expression-operator symbols. */ Eq, @@ -638,7 +638,7 @@ impl Token { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Eq, Hash)] +#[derive(Clone, RustcEncodable, RustcDecodable, Hash)] /// For interpolation during macro expansion. pub enum Nonterminal { NtItem(P), -- cgit 1.4.1-3-g733a5 From 5987fe8f75c443d4f73603fa5a3af8ab41ee1b01 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 27 Jun 2018 00:57:27 +0300 Subject: Remove most of `Hash` impls from AST and HIR structures --- src/librustc/hir/mod.rs | 171 +++++++++++++++++------------------ src/librustc/middle/cstore.rs | 2 +- src/librustdoc/clean/mod.rs | 17 +++- src/libsyntax/ast.rs | 198 ++++++++++++++++++++--------------------- src/libsyntax/ext/tt/quoted.rs | 6 +- src/libsyntax/parse/token.rs | 4 +- src/libsyntax/tokenstream.rs | 20 +---- 7 files changed, 208 insertions(+), 210 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index e98e9b17603..09fc824750d 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -172,7 +172,7 @@ pub const DUMMY_HIR_ID: HirId = HirId { pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId(!0); -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Clone, RustcEncodable, RustcDecodable, Copy)] pub struct Label { pub ident: Ident, } @@ -183,7 +183,7 @@ impl fmt::Debug for Label { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Clone, RustcEncodable, RustcDecodable, Copy)] pub struct Lifetime { pub id: NodeId, pub span: Span, @@ -312,7 +312,7 @@ impl Lifetime { /// A "Path" is essentially Rust's notion of a name; for instance: /// `std::cmp::PartialEq`. It's represented as a sequence of identifiers, /// along with a bunch of supporting information. -#[derive(Clone, RustcEncodable, RustcDecodable, Hash)] +#[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Path { pub span: Span, /// The definition that the path resolved to. @@ -341,7 +341,7 @@ impl fmt::Display for Path { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct PathSegment { /// The identifier portion of this path segment. pub ident: Ident, @@ -396,7 +396,7 @@ impl PathSegment { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum GenericArg { Lifetime(Lifetime), Type(Ty), @@ -411,7 +411,7 @@ impl GenericArg { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct GenericArgs { /// The generic arguments for this path segment. pub args: HirVec, @@ -467,7 +467,7 @@ pub enum TraitBoundModifier { /// typeck::collect::compute_bounds matches these against /// the "special" built-in traits (see middle::lang_items) and /// detects Copy, Send and Sync. -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum GenericBound { Trait(PolyTraitRef, TraitBoundModifier), Outlives(Lifetime), @@ -484,7 +484,7 @@ impl GenericBound { pub type GenericBounds = HirVec; -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum GenericParamKind { /// A lifetime definition, eg `'a: 'b + 'c + 'd`. Lifetime { @@ -499,7 +499,7 @@ pub enum GenericParamKind { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct GenericParam { pub id: NodeId, pub name: ParamName, @@ -518,7 +518,7 @@ pub struct GenericParamCount { /// Represents lifetimes and type parameters attached to a declaration /// of a function, enum, trait, etc. -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Generics { pub params: HirVec, pub where_clause: WhereClause, @@ -574,7 +574,7 @@ pub enum SyntheticTyParamKind { } /// A `where` clause in a definition -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereClause { pub id: NodeId, pub predicates: HirVec, @@ -593,7 +593,7 @@ impl WhereClause { } /// A single predicate in a `where` clause -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum WherePredicate { /// A type binding, eg `for<'c> Foo: Send+Clone+'c` BoundPredicate(WhereBoundPredicate), @@ -614,7 +614,7 @@ impl WherePredicate { } /// A type bound, eg `for<'c> Foo: Send+Clone+'c` -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereBoundPredicate { pub span: Span, /// Any generics from a `for` binding @@ -626,7 +626,7 @@ pub struct WhereBoundPredicate { } /// A lifetime predicate, e.g. `'a: 'b+'c` -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, @@ -634,7 +634,7 @@ pub struct WhereRegionPredicate { } /// An equality predicate (unsupported), e.g. `T=int` -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereEqPredicate { pub id: NodeId, pub span: Span, @@ -748,7 +748,7 @@ impl Crate { /// A macro definition, in this crate or imported from another. /// /// Not parsed directly, but created on macro import or `macro_rules!` expansion. -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct MacroDef { pub name: Name, pub vis: Visibility, @@ -759,7 +759,7 @@ pub struct MacroDef { pub legacy: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Block { /// Statements in a block pub stmts: HirVec, @@ -782,7 +782,7 @@ pub struct Block { pub recovered: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash)] +#[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Pat { pub id: NodeId, pub hir_id: HirId, @@ -844,7 +844,7 @@ impl Pat { /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` /// are treated the same as` x: x, y: ref y, z: ref mut z`, /// except is_shorthand is true -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct FieldPat { pub id: NodeId, /// The identifier for the field @@ -857,7 +857,7 @@ pub struct FieldPat { /// Explicit binding annotations given in the HIR for a binding. Note /// that this is not the final binding *mode* that we infer after type /// inference. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum BindingAnnotation { /// No binding annotation given: this means that the final binding mode /// will depend on whether we have skipped through a `&` reference @@ -878,13 +878,13 @@ pub enum BindingAnnotation { RefMut, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] pub enum RangeEnd { Included, Excluded, } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum PatKind { /// Represents a wildcard pattern (`_`) Wild, @@ -940,7 +940,7 @@ impl Mutability { } } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum BinOp_ { /// The `+` operator (addition) BiAdd, @@ -1069,7 +1069,7 @@ impl Into for BinOp_ { pub type BinOp = Spanned; -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum UnOp { /// The `*` operator for dereferencing UnDeref, @@ -1111,7 +1111,7 @@ impl fmt::Debug for Stmt_ { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash)] +#[derive(Clone, RustcEncodable, RustcDecodable)] pub enum Stmt_ { /// Could be an item or a local (let) binding: StmtDecl(P, NodeId), @@ -1142,7 +1142,7 @@ impl Stmt_ { } /// Local represents a `let` statement, e.g., `let : = ;` -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Local { pub pat: P, pub ty: Option>, @@ -1157,7 +1157,7 @@ pub struct Local { pub type Decl = Spanned; -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum Decl_ { /// A local (let) binding: DeclLocal(P), @@ -1182,7 +1182,7 @@ impl Decl_ { } /// represents one arm of a 'match' -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Arm { pub attrs: HirVec, pub pats: HirVec>, @@ -1190,7 +1190,7 @@ pub struct Arm { pub body: P, } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Field { pub id: NodeId, pub ident: Ident, @@ -1199,7 +1199,7 @@ pub struct Field { pub is_shorthand: bool, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), @@ -1207,7 +1207,7 @@ pub enum BlockCheckMode { PopUnsafeBlock(UnsafeSource), } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum UnsafeSource { CompilerGenerated, UserProvided, @@ -1239,7 +1239,7 @@ pub struct BodyId { /// /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Body { pub arguments: HirVec, pub value: Expr, @@ -1271,7 +1271,7 @@ pub enum BodyOwnerKind { /// These are usually found nested inside types (e.g. array lengths) /// or expressions (e.g. repeat counts), and also used to define /// explicit discriminant values for enum variants. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] pub struct AnonConst { pub id: NodeId, pub hir_id: HirId, @@ -1279,7 +1279,7 @@ pub struct AnonConst { } /// An expression -#[derive(Clone, RustcEncodable, RustcDecodable, Hash)] +#[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Expr { pub id: NodeId, pub span: Span, @@ -1330,7 +1330,7 @@ impl fmt::Debug for Expr { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum Expr_ { /// A `box x` expression. ExprBox(P), @@ -1432,7 +1432,7 @@ pub enum Expr_ { } /// Optionally `Self`-qualified value/type path or associated extension. -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum QPath { /// Path to a definition, optionally "fully-qualified" with a `Self` /// type, if the path points to an associated item in a trait. @@ -1452,7 +1452,7 @@ pub enum QPath { } /// Hints at the original code for a let statement -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum LocalSource { /// A `match _ { .. }` Normal, @@ -1479,7 +1479,7 @@ pub enum MatchSource { } /// The loop type that yielded an ExprLoop -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum LoopSource { /// A `loop { .. }` loop Loop, @@ -1489,7 +1489,7 @@ pub enum LoopSource { ForLoop, } -#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum LoopIdError { OutsideLoopScope, UnlabeledCfInWhileCondition, @@ -1507,6 +1507,7 @@ impl fmt::Display for LoopIdError { } } +#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] pub struct Destination { // This is `Some(_)` iff there is an explicit user-specified `label pub label: Option