From 77c96d754e3a5d4b8dd59269b0cb0324350ccbec Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 9 Jul 2013 22:52:34 -0700 Subject: [PATCH] disallow ident equality checks when contexts are not equal --- src/libsyntax/ast.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c7ebc344a9c8..8a9bd5192ad8 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -24,7 +24,7 @@ use extra::serialize::{Encodable, Decodable, Encoder, Decoder}; // table) and a SyntaxContext to track renaming and // macro expansion per Flatt et al., "Macros // That Work Together" -#[deriving(Clone, Eq, IterBytes, ToStr)] +#[deriving(Clone, IterBytes, ToStr)] pub struct Ident { name: Name, ctxt: SyntaxContext } impl Ident { @@ -32,6 +32,19 @@ impl Ident { pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}} } +impl Eq for Ident { + fn eq(&self, other: &Ident) -> bool { + if (self.ctxt == other.ctxt) { + self.name == other.name + } else { + fail!(fmt!("not allowed to compare these idents: %?, %?", self, other)); + } + } + fn ne(&self, other: &Ident) -> bool { + ! self.eq(other) + } +} + /// A SyntaxContext represents a chain of macro-expandings /// and renamings. Each macro expansion corresponds to /// a fresh uint