From 7e1f73beb6144503851c71b28fc50fd477afe622 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 24 Mar 2018 16:00:44 +0300 Subject: macros: Do not match on "complex" nonterminals requiring AST comparisons --- src/libsyntax/parse/token.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse/token.rs') diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 8da79f92768..35a745ccdee 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -565,7 +565,7 @@ impl Token { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash)] +#[derive(Clone, RustcEncodable, RustcDecodable, Eq, Hash)] /// For interpolation during macro expansion. pub enum Nonterminal { NtItem(P), @@ -591,6 +591,22 @@ pub enum Nonterminal { NtArg(ast::Arg), } +impl PartialEq for Nonterminal { + fn eq(&self, rhs: &Self) -> bool { + match (self, rhs) { + (NtIdent(ident_lhs, is_raw_lhs), NtIdent(ident_rhs, is_raw_rhs)) => + ident_lhs == ident_rhs && is_raw_lhs == is_raw_rhs, + (NtLifetime(ident_lhs), NtLifetime(ident_rhs)) => ident_lhs == ident_rhs, + (NtTT(tt_lhs), NtTT(tt_rhs)) => tt_lhs == tt_rhs, + // FIXME: Assume that all "complex" nonterminal are not equal, we can't compare them + // correctly based on data from AST. This will prevent them from matching each other + // in macros. The comparison will become possible only when each nonterminal has an + // attached token stream from which it was parsed. + _ => false, + } + } +} + impl fmt::Debug for Nonterminal { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { -- cgit 1.4.1-3-g733a5