Skip to content

Commit ea30f6d

Browse files
committed
Derive Hash for TokenStream
1 parent f9f055b commit ea30f6d

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3243,7 +3243,18 @@ impl UseTree {
32433243
/// Distinguishes between `Attribute`s that decorate items and Attributes that
32443244
/// are contained as statements within items. These two cases need to be
32453245
/// distinguished for pretty-printing.
3246-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic, Walkable)]
3246+
#[derive(
3247+
Clone,
3248+
PartialEq,
3249+
Eq,
3250+
Encodable,
3251+
Decodable,
3252+
Hash,
3253+
Debug,
3254+
Copy,
3255+
HashStable_Generic,
3256+
Walkable
3257+
)]
32473258
pub enum AttrStyle {
32483259
Outer,
32493260
Inner,

compiler/rustc_ast/src/token.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ use rustc_span::{Ident, Symbol};
1616
use crate::ast;
1717
use crate::util::case::Case;
1818

19-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
19+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
2020
pub enum CommentKind {
2121
Line,
2222
Block,
2323
}
2424

25-
#[derive(Copy, Clone, PartialEq, Debug, Encodable, Decodable, HashStable_Generic)]
25+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)]
2626
pub enum InvisibleOrigin {
2727
// From the expansion of a metavariable in a declarative macro.
2828
MetaVar(MetaVarKind),
@@ -99,7 +99,7 @@ impl fmt::Display for MetaVarKind {
9999
/// Describes how a sequence of token trees is delimited.
100100
/// Cannot use `proc_macro::Delimiter` directly because this
101101
/// structure should implement some additional traits.
102-
#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
102+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
103103
pub enum Delimiter {
104104
/// `( ... )`
105105
Parenthesis,
@@ -162,7 +162,7 @@ impl Delimiter {
162162
// type. This means that float literals like `1f32` are classified by this type
163163
// as `Int`. Only upon conversion to `ast::LitKind` will such a literal be
164164
// given the `Float` kind.
165-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
165+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
166166
pub enum LitKind {
167167
Bool, // AST only, must never appear in a `Token`
168168
Byte,
@@ -179,7 +179,7 @@ pub enum LitKind {
179179
}
180180

181181
/// A literal token.
182-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
182+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
183183
pub struct Lit {
184184
pub kind: LitKind,
185185
pub symbol: Symbol,
@@ -325,7 +325,7 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
325325
.contains(&name)
326326
}
327327

328-
#[derive(PartialEq, Encodable, Decodable, Debug, Copy, Clone, HashStable_Generic)]
328+
#[derive(PartialEq, Eq, Encodable, Decodable, Hash, Debug, Copy, Clone, HashStable_Generic)]
329329
pub enum IdentIsRaw {
330330
No,
331331
Yes,
@@ -352,7 +352,7 @@ impl From<bool> for IdentIsRaw {
352352
}
353353
}
354354

355-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
355+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
356356
pub enum TokenKind {
357357
/* Expression-operator symbols. */
358358
/// `=`
@@ -502,7 +502,7 @@ pub enum TokenKind {
502502
Eof,
503503
}
504504

505-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
505+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
506506
pub struct Token {
507507
pub kind: TokenKind,
508508
pub span: Span,

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ use std::{cmp, fmt, iter, mem};
1313
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1414
use rustc_data_structures::sync;
1515
use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable};
16-
use rustc_serialize::{Decodable, Encodable, Encoder};
17-
use rustc_span::def_id::{CrateNum, DefIndex};
18-
use rustc_span::{ByteSymbol, DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
16+
use rustc_serialize::{Decodable, Encodable};
17+
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
1918
use thin_vec::ThinVec;
2019

2120
use crate::ast::AttrStyle;
@@ -24,7 +23,7 @@ use crate::token::{self, Delimiter, Token, TokenKind};
2423
use crate::{AttrVec, Attribute};
2524

2625
/// Part of a `TokenStream`.
27-
#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
26+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
2827
pub enum TokenTree {
2928
/// A single token. Should never be `OpenDelim` or `CloseDelim`, because
3029
/// delimiters are implicitly represented by `Delimited`.
@@ -542,7 +541,7 @@ pub struct AttrsTarget {
542541
/// compound token. Used for conversions to `proc_macro::Spacing`. Also used to
543542
/// guide pretty-printing, which is where the `JointHidden` value (which isn't
544543
/// part of `proc_macro::Spacing`) comes in useful.
545-
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
544+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
546545
pub enum Spacing {
547546
/// The token cannot join with the following token to form a compound
548547
/// token.
@@ -599,7 +598,7 @@ pub enum Spacing {
599598
}
600599

601600
/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
602-
#[derive(Clone, Debug, Default, Encodable, Decodable)]
601+
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Encodable, Decodable)]
603602
pub struct TokenStream(pub(crate) Arc<Vec<TokenTree>>);
604603

605604
impl TokenStream {
@@ -815,14 +814,6 @@ impl TokenStream {
815814
}
816815
}
817816

818-
impl PartialEq<TokenStream> for TokenStream {
819-
fn eq(&self, other: &TokenStream) -> bool {
820-
self.iter().eq(other.iter())
821-
}
822-
}
823-
824-
impl Eq for TokenStream {}
825-
826817
impl FromIterator<TokenTree> for TokenStream {
827818
fn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self {
828819
TokenStream::new(iter.into_iter().collect::<Vec<TokenTree>>())
@@ -974,7 +965,18 @@ impl TokenCursor {
974965
}
975966
}
976967

977-
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)]
968+
#[derive(
969+
Debug,
970+
Copy,
971+
Clone,
972+
PartialEq,
973+
Eq,
974+
Hash,
975+
Encodable,
976+
Decodable,
977+
HashStable_Generic,
978+
Walkable
979+
)]
978980
pub struct DelimSpan {
979981
pub open: Span,
980982
pub close: Span,
@@ -998,7 +1000,7 @@ impl DelimSpan {
9981000
}
9991001
}
10001002

1001-
#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
1003+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
10021004
pub struct DelimSpacing {
10031005
pub open: Spacing,
10041006
pub close: Spacing,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ rustc_queries! {
168168
/// Caches the expansion of a derive proc macro, e.g. `#[derive(Serialize)]`.
169169
/// The key is:
170170
/// - A unique key corresponding to the invocation of a macro.
171-
/// - Strict Version Hash of a crate.
171+
/// - Strict Version Hash of the crate defining the proc macro.
172172
/// - Token stream which serves as an input to the macro.
173173
///
174174
/// The output is the token stream generated by the proc macro.

0 commit comments

Comments
 (0)