about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJohn Clements <clements@racket-lang.org>2013-07-09 22:52:34 -0700
committerJohn Clements <clements@racket-lang.org>2013-09-06 09:28:45 -0700
commit77c96d754e3a5d4b8dd59269b0cb0324350ccbec (patch)
treede640b571f07e4da4d8b9f2ba985e39b7b70d35e /src/libsyntax
parent6e3b2ab44d9c03fb7aa8e8b94e711c197de3d337 (diff)
downloadrust-77c96d754e3a5d4b8dd59269b0cb0324350ccbec.tar.gz
rust-77c96d754e3a5d4b8dd59269b0cb0324350ccbec.zip
disallow ident equality checks when contexts are not equal
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index c7ebc344a9c..8a9bd5192ad 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