@@ -985,13 +985,50 @@ pub fn getLast(arr: &~[Mrk]) -> uint {
985
985
*arr.last()
986
986
}
987
987
988
+ // are two paths equal when compared unhygienically?
989
+ // since I'm using this to replace ==, it seems appropriate
990
+ // to compare the span, global, etc. fields as well.
991
+ pub fn path_name_eq(a : &ast::Path, b : &ast::Path) -> bool {
992
+ (a.span == b.span)
993
+ && (a.global == b.global)
994
+ // NOTE: ident->name in lifetimes!
995
+ && (a.rp == b.rp)
996
+ // NOTE: can a type contain an ident?
997
+ && (a.types == b.types)
998
+ && (idents_name_eq(a.idents, b.idents))
999
+ }
1000
+
1001
+ // are two arrays of idents equal when compared unhygienically?
1002
+ pub fn idents_name_eq(a : &[ast::ident], b : &[ast::ident]) -> bool {
1003
+ if (a.len() != b.len()) {
1004
+ false
1005
+ } else {
1006
+ for a.iter().enumerate().advance |(idx,id)|{
1007
+ if (id.name != b[idx].name) {
1008
+ return false;
1009
+ }
1010
+ }
1011
+ true
1012
+ }
1013
+ }
988
1014
989
1015
#[cfg(test)]
990
1016
mod test {
991
1017
use ast::*;
992
1018
use super::*;
993
1019
use std::io;
994
1020
1021
+ #[test] fn idents_name_eq_test() {
1022
+ assert!(idents_name_eq(~[ident{name:3,ctxt:4},
1023
+ ident{name:78,ctxt:82}],
1024
+ ~[ident{name:3,ctxt:104},
1025
+ ident{name:78,ctxt:182}]));
1026
+ assert!(!idents_name_eq(~[ident{name:3,ctxt:4},
1027
+ ident{name:78,ctxt:82}],
1028
+ ~[ident{name:3,ctxt:104},
1029
+ ident{name:77,ctxt:182}]));
1030
+ }
1031
+
995
1032
#[test] fn xorpush_test () {
996
1033
let mut s = ~[];
997
1034
xorPush(&mut s,14);
0 commit comments