disallow ident equality checks when contexts are not equal

This commit is contained in:
John Clements 2013-07-09 22:52:34 -07:00
parent 6e3b2ab44d
commit 77c96d754e

View File

@ -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