Skip to content

Commit 77c96d7

Browse files
committed
disallow ident equality checks when contexts are not equal
1 parent 6e3b2ab commit 77c96d7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/libsyntax/ast.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,27 @@ use extra::serialize::{Encodable, Decodable, Encoder, Decoder};
2424
// table) and a SyntaxContext to track renaming and
2525
// macro expansion per Flatt et al., "Macros
2626
// That Work Together"
27-
#[deriving(Clone, Eq, IterBytes, ToStr)]
27+
#[deriving(Clone, IterBytes, ToStr)]
2828
pub struct Ident { name: Name, ctxt: SyntaxContext }
2929

3030
impl Ident {
3131
/// Construct an identifier with the given name and an empty context:
3232
pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}}
3333
}
3434

35+
impl Eq for Ident {
36+
fn eq(&self, other: &Ident) -> bool {
37+
if (self.ctxt == other.ctxt) {
38+
self.name == other.name
39+
} else {
40+
fail!(fmt!("not allowed to compare these idents: %?, %?", self, other));
41+
}
42+
}
43+
fn ne(&self, other: &Ident) -> bool {
44+
! self.eq(other)
45+
}
46+
}
47+
3548
/// A SyntaxContext represents a chain of macro-expandings
3649
/// and renamings. Each macro expansion corresponds to
3750
/// a fresh uint

0 commit comments

Comments
 (0)