Skip to content

Commit 893930d

Browse files
committed
---
yaml --- r: 144828 b: refs/heads/try2 c: 0954e66 h: refs/heads/master v: v3
1 parent d64430d commit 893930d

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: d9ba61c786f94ff86339fe83136061657a4c19f9
8+
refs/heads/try2: 0954e66442a169be40f1e65de68a85d7e3dacf3a
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/resolve.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use middle::pat_util::pat_bindings;
2323

2424
use syntax::ast::*;
2525
use syntax::ast;
26-
use syntax::ast_util::{def_id_of_def, local_def}; // mtwt_resolve
26+
use syntax::ast_util::{def_id_of_def, local_def, mtwt_resolve};
2727
use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method};
2828
use syntax::ast_util::{Privacy, Public, Private};
2929
use syntax::ast_util::{variant_visibility_to_privacy, visibility_to_privacy};
@@ -4067,17 +4067,23 @@ impl Resolver {
40674067
None, visitor);
40684068
}
40694069

4070+
// build a map from pattern identifiers to binding-info's.
4071+
// this is done hygienically. This could arise for a macro
4072+
// that expands into an or-pattern where one 'x' was from the
4073+
// user and one 'x' came from the macro.
40704074
pub fn binding_mode_map(@mut self, pat: @Pat) -> BindingMap {
40714075
let mut result = HashMap::new();
40724076
do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| {
4073-
let name = path_to_ident(path).name; // mtwt_resolve(path_to_ident(path));
4077+
let name = mtwt_resolve(path_to_ident(path));
40744078
result.insert(name,
40754079
binding_info {span: sp,
40764080
binding_mode: binding_mode});
40774081
}
40784082
return result;
40794083
}
40804084

4085+
// check that all of the arms in an or-pattern have exactly the
4086+
// same set of bindings, with the same binding modes for each.
40814087
pub fn check_consistent_bindings(@mut self, arm: &Arm) {
40824088
if arm.pats.len() == 0 { return; }
40834089
let map_0 = self.binding_mode_map(arm.pats[0]);
@@ -4293,7 +4299,7 @@ impl Resolver {
42934299
// what you want).
42944300

42954301
let ident = path.segments[0].identifier;
4296-
let renamed = ident.name; // mtwt_resolve(ident);
4302+
let renamed = mtwt_resolve(ident);
42974303

42984304
match self.resolve_bare_identifier_pattern(ident) {
42994305
FoundStructOrEnumVariant(def)
@@ -4833,7 +4839,7 @@ impl Resolver {
48334839
let search_result;
48344840
match namespace {
48354841
ValueNS => {
4836-
let renamed = ident.name; // mtwt_resolve(ident);
4842+
let renamed = mtwt_resolve(ident);
48374843
search_result = self.search_ribs(self.value_ribs, renamed,
48384844
span,
48394845
DontAllowCapturingSelf);

branches/try2/src/libsyntax/ast_util.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -991,20 +991,19 @@ pub fn getLast(arr: &~[Mrk]) -> uint {
991991
pub fn path_name_eq(a : &ast::Path, b : &ast::Path) -> bool {
992992
(a.span == b.span)
993993
&& (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))
994+
&& (segments_name_eq(a.segments, b.segments))
999995
}
1000996
1001-
// are two arrays of idents equal when compared unhygienically?
1002-
pub fn idents_name_eq(a : &[ast::ident], b : &[ast::ident]) -> bool {
997+
// are two arrays of segments equal when compared unhygienically?
998+
pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> bool {
1003999
if (a.len() != b.len()) {
10041000
false
10051001
} else {
1006-
for a.iter().enumerate().advance |(idx,id)|{
1007-
if (id.name != b[idx].name) {
1002+
for (idx,seg) in a.iter().enumerate() {
1003+
if (seg.identifier.name != b[idx].identifier.name)
1004+
// ident -> name problems in lifetime comparison?
1005+
|| (seg.lifetime != b[idx].lifetime)
1006+
|| (seg.types != b[idx].types) {
10081007
return false;
10091008
}
10101009
}
@@ -1017,16 +1016,21 @@ mod test {
10171016
use ast::*;
10181017
use super::*;
10191018
use std::io;
1019+
use opt_vec;
1020+
1021+
fn ident_to_segment(id : &ident) -> PathSegment {
1022+
PathSegment{identifier:id.clone(), lifetime: None, types: opt_vec::Empty}
1023+
}
10201024
10211025
#[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}]));
1026+
assert!(segments_name_eq([ident{name:3,ctxt:4},
1027+
ident{name:78,ctxt:82}].map(ident_to_segment),
1028+
[ident{name:3,ctxt:104},
1029+
ident{name:78,ctxt:182}].map(ident_to_segment)));
1030+
assert!(!segments_name_eq([ident{name:3,ctxt:4},
1031+
ident{name:78,ctxt:82}].map(ident_to_segment),
1032+
[ident{name:3,ctxt:104},
1033+
ident{name:77,ctxt:182}].map(ident_to_segment)));
10301034
}
10311035
10321036
#[test] fn xorpush_test () {

branches/try2/src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ pub fn parse(
355355
match_nonterminal(_,_,_) => { bb_eis.push(ei) }
356356
match_tok(ref t) => {
357357
let mut ei_t = ei.clone();
358-
if (token_name_eq(t,&tok)) {
359-
//if (token::mtwt_token_eq(t,&tok)) {
358+
//if (token_name_eq(t,&tok)) {
359+
if (token::mtwt_token_eq(t,&tok)) {
360360
ei_t.idx += 1;
361361
next_eis.push(ei_t);
362362
}

branches/try2/src/libsyntax/parse/token.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,15 @@ pub fn is_reserved_keyword(tok: &Token) -> bool {
720720
}
721721
}
722722

723+
pub fn mtwt_token_eq(t1 : &Token, t2 : &Token) -> bool {
724+
match (t1,t2) {
725+
(&IDENT(id1,_),&IDENT(id2,_)) =>
726+
ast_util::mtwt_resolve(id1) == ast_util::mtwt_resolve(id2),
727+
_ => *t1 == *t2
728+
}
729+
}
730+
731+
723732
#[cfg(test)]
724733
mod test {
725734
use super::*;
@@ -728,6 +737,17 @@ mod test {
728737
use ast;
729738
use ast_util;
730739

740+
fn mark_ident(id : ast::ident, m : ast::Mrk) -> ast::ident {
741+
ast::ident{name:id.name,ctxt:ast_util::new_mark(m,id.ctxt)}
742+
}
743+
744+
#[test] fn mtwt_token_eq_test() {
745+
assert!(mtwt_token_eq(&GT,&GT));
746+
let a = str_to_ident("bac");
747+
let a1 = mark_ident(a,92);
748+
assert!(mtwt_token_eq(&IDENT(a,true),&IDENT(a1,false)));
749+
}
750+
731751

732752
#[test] fn str_ptr_eq_tests(){
733753
let a = @"abc";

0 commit comments

Comments
 (0)