Skip to content

Commit dba6070

Browse files
committed
auto merge of #10117 : huonw/rust/dead-visits, r=sanxiyn
Used nowhere, and these are likely incorrect anyway: self needs to be dereferenced once more otherwise the method calls will be reusing the current impl... bam! Infinite recursion.
2 parents c0222cd + 17b87d2 commit dba6070

File tree

2 files changed

+70
-126
lines changed

2 files changed

+70
-126
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,11 @@ fn expand_non_macro_stmt(exts: SyntaxEnv, s: &Stmt, fld: &MacroExpander)
566566
// oh dear heaven... this is going to include the enum names, as well....
567567
// ... but that should be okay, as long as the new names are gensyms
568568
// for the old ones.
569-
let idents = @mut ~[];
570-
let name_finder = new_name_finder(idents);
569+
let mut name_finder = new_name_finder(~[]);
571570
name_finder.visit_pat(expanded_pat,());
572571
// generate fresh names, push them to a new pending list
573572
let new_pending_renames = @mut ~[];
574-
for ident in idents.iter() {
573+
for ident in name_finder.ident_accumulator.iter() {
575574
let new_name = fresh_name(ident);
576575
new_pending_renames.push((*ident,new_name));
577576
}
@@ -609,7 +608,7 @@ fn expand_non_macro_stmt(exts: SyntaxEnv, s: &Stmt, fld: &MacroExpander)
609608
// array (passed in to the traversal)
610609
#[deriving(Clone)]
611610
struct NewNameFinderContext {
612-
ident_accumulator: @mut ~[ast::Ident],
611+
ident_accumulator: ~[ast::Ident],
613612
}
614613

615614
impl Visitor<()> for NewNameFinderContext {
@@ -653,50 +652,13 @@ impl Visitor<()> for NewNameFinderContext {
653652

654653
}
655654

656-
// a visitor that extracts the paths
657-
// from a given thingy and puts them in a mutable
658-
// array (passed in to the traversal)
659-
#[deriving(Clone)]
660-
struct NewPathExprFinderContext {
661-
path_accumulator: @mut ~[ast::Path],
662-
}
663-
664-
impl Visitor<()> for NewPathExprFinderContext {
665-
666-
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
667-
match *expr {
668-
ast::Expr{id:_,span:_,node:ast::ExprPath(ref p)} => {
669-
self.path_accumulator.push(p.clone());
670-
// not calling visit_path, should be fine.
671-
}
672-
_ => visit::walk_expr(self,expr,())
673-
}
674-
}
675-
676-
fn visit_ty(&mut self, typ: &ast::Ty, _: ()) {
677-
visit::walk_ty(self, typ, ())
678-
}
679-
680-
}
681-
682655
// return a visitor that extracts the pat_ident paths
683656
// from a given thingy and puts them in a mutable
684657
// array (passed in to the traversal)
685-
pub fn new_name_finder(idents: @mut ~[ast::Ident]) -> @mut Visitor<()> {
686-
let context = @mut NewNameFinderContext {
658+
pub fn new_name_finder(idents: ~[ast::Ident]) -> NewNameFinderContext {
659+
NewNameFinderContext {
687660
ident_accumulator: idents,
688-
};
689-
context as @mut Visitor<()>
690-
}
691-
692-
// return a visitor that extracts the paths
693-
// from a given pattern and puts them in a mutable
694-
// array (passed in to the traversal)
695-
pub fn new_path_finder(paths: @mut ~[ast::Path]) -> @mut Visitor<()> {
696-
let context = @mut NewPathExprFinderContext {
697-
path_accumulator: paths,
698-
};
699-
context as @mut Visitor<()>
661+
}
700662
}
701663

702664
// expand a block. pushes a new exts_frame, then calls expand_block_elts
@@ -1371,6 +1333,42 @@ mod test {
13711333
use util::parser_testing::{string_to_crate, string_to_crate_and_sess};
13721334
use util::parser_testing::{string_to_pat, string_to_tts, strs_to_idents};
13731335
use visit;
1336+
use visit::Visitor;
1337+
1338+
// a visitor that extracts the paths
1339+
// from a given thingy and puts them in a mutable
1340+
// array (passed in to the traversal)
1341+
#[deriving(Clone)]
1342+
struct NewPathExprFinderContext {
1343+
path_accumulator: ~[ast::Path],
1344+
}
1345+
1346+
impl Visitor<()> for NewPathExprFinderContext {
1347+
1348+
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
1349+
match *expr {
1350+
ast::Expr{id:_,span:_,node:ast::ExprPath(ref p)} => {
1351+
self.path_accumulator.push(p.clone());
1352+
// not calling visit_path, should be fine.
1353+
}
1354+
_ => visit::walk_expr(self,expr,())
1355+
}
1356+
}
1357+
1358+
fn visit_ty(&mut self, typ: &ast::Ty, _: ()) {
1359+
visit::walk_ty(self, typ, ())
1360+
}
1361+
1362+
}
1363+
1364+
// return a visitor that extracts the paths
1365+
// from a given pattern and puts them in a mutable
1366+
// array (passed in to the traversal)
1367+
pub fn new_path_finder(paths: ~[ast::Path]) -> NewPathExprFinderContext {
1368+
NewPathExprFinderContext {
1369+
path_accumulator: paths
1370+
}
1371+
}
13741372

13751373
// make sure that fail! is present
13761374
#[test] fn fail_exists_test () {
@@ -1498,10 +1496,11 @@ mod test {
14981496
let renamer = new_rename_folder(ast::Ident{name:a_name,ctxt:EMPTY_CTXT},
14991497
a2_name);
15001498
let renamed_ast = renamer.fold_crate(item_ast.clone());
1501-
let varrefs = @mut ~[];
1502-
visit::walk_crate(&mut new_path_finder(varrefs), &renamed_ast, ());
1503-
match varrefs {
1504-
@[ast::Path{segments:[ref seg],_}] =>
1499+
let mut path_finder = new_path_finder(~[]);
1500+
visit::walk_crate(&mut path_finder, &renamed_ast, ());
1501+
1502+
match path_finder.path_accumulator {
1503+
[ast::Path{segments:[ref seg],_}] =>
15051504
assert_eq!(mtwt_resolve(seg.identifier),a2_name),
15061505
_ => assert_eq!(0,1)
15071506
}
@@ -1513,10 +1512,10 @@ mod test {
15131512
let pending_renames = @mut ~[(ast::Ident::new(a_name),a2_name),
15141513
(ast::Ident{name:a_name,ctxt:ctxt2},a3_name)];
15151514
let double_renamed = renames_to_fold(pending_renames).fold_crate(item_ast);
1516-
let varrefs = @mut ~[];
1517-
visit::walk_crate(&mut new_path_finder(varrefs), &double_renamed, ());
1518-
match varrefs {
1519-
@[ast::Path{segments:[ref seg],_}] =>
1515+
let mut path_finder = new_path_finder(~[]);
1516+
visit::walk_crate(&mut path_finder, &double_renamed, ());
1517+
match path_finder.path_accumulator {
1518+
[ast::Path{segments:[ref seg],_}] =>
15201519
assert_eq!(mtwt_resolve(seg.identifier),a3_name),
15211520
_ => assert_eq!(0,1)
15221521
}
@@ -1623,11 +1622,15 @@ mod test {
16231622
};
16241623
let cr = expand_crate_str(teststr.to_managed());
16251624
// find the bindings:
1626-
let bindings = @mut ~[];
1627-
visit::walk_crate(&mut new_name_finder(bindings),&cr,());
1625+
let mut name_finder = new_name_finder(~[]);
1626+
visit::walk_crate(&mut name_finder,&cr,());
1627+
let bindings = name_finder.ident_accumulator;
1628+
16281629
// find the varrefs:
1629-
let varrefs = @mut ~[];
1630-
visit::walk_crate(&mut new_path_finder(varrefs),&cr,());
1630+
let mut path_finder = new_path_finder(~[]);
1631+
visit::walk_crate(&mut path_finder,&cr,());
1632+
let varrefs = path_finder.path_accumulator;
1633+
16311634
// must be one check clause for each binding:
16321635
assert_eq!(bindings.len(),bound_connections.len());
16331636
for (binding_idx,shouldmatch) in bound_connections.iter().enumerate() {
@@ -1686,8 +1689,10 @@ foo_module!()
16861689
";
16871690
let cr = expand_crate_str(crate_str);
16881691
// find the xx binding
1689-
let bindings = @mut ~[];
1690-
visit::walk_crate(&mut new_name_finder(bindings), &cr, ());
1692+
let mut name_finder = new_name_finder(~[]);
1693+
visit::walk_crate(&mut name_finder, &cr, ());
1694+
let bindings = name_finder.ident_accumulator;
1695+
16911696
let cxbinds : ~[&ast::Ident] =
16921697
bindings.iter().filter(|b|{@"xx" == (ident_to_str(*b))}).collect();
16931698
let cxbind = match cxbinds {
@@ -1696,8 +1701,10 @@ foo_module!()
16961701
};
16971702
let resolved_binding = mtwt_resolve(*cxbind);
16981703
// find all the xx varrefs:
1699-
let varrefs = @mut ~[];
1700-
visit::walk_crate(&mut new_path_finder(varrefs), &cr, ());
1704+
let mut path_finder = new_path_finder(~[]);
1705+
visit::walk_crate(&mut path_finder, &cr, ());
1706+
let varrefs = path_finder.path_accumulator;
1707+
17011708
// the xx binding should bind all of the xx varrefs:
17021709
for (idx,v) in varrefs.iter().filter(|p|{ p.segments.len() == 1
17031710
&& (@"xx" == (ident_to_str(&p.segments[0].identifier)))
@@ -1723,10 +1730,10 @@ foo_module!()
17231730
#[test]
17241731
fn pat_idents(){
17251732
let pat = string_to_pat(@"(a,Foo{x:c @ (b,9),y:Bar(4,d)})");
1726-
let idents = @mut ~[];
1727-
let pat_idents = new_name_finder(idents);
1733+
let mut pat_idents = new_name_finder(~[]);
17281734
pat_idents.visit_pat(pat, ());
1729-
assert_eq!(idents, @mut strs_to_idents(~["a","c","b","d"]));
1735+
assert_eq!(pat_idents.ident_accumulator,
1736+
strs_to_idents(~["a","c","b","d"]));
17301737
}
17311738

17321739
}

src/libsyntax/visit.rs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -93,69 +93,6 @@ pub trait Visitor<E:Clone> {
9393
fn visit_mac(&mut self, m:&mac, e:E) { walk_mac(self, m, e); }
9494
}
9595

96-
impl<E:Clone> Visitor<E> for @mut Visitor<E> {
97-
fn visit_mod(&mut self, a:&_mod, b:Span, c:NodeId, e:E) {
98-
(*self).visit_mod(a, b, c, e)
99-
}
100-
fn visit_view_item(&mut self, a:&view_item, e:E) {
101-
(*self).visit_view_item(a, e)
102-
}
103-
fn visit_foreign_item(&mut self, a:@foreign_item, e:E) {
104-
(*self).visit_foreign_item(a, e)
105-
}
106-
fn visit_item(&mut self, a:@item, e:E) {
107-
(*self).visit_item(a, e)
108-
}
109-
fn visit_local(&mut self, a:@Local, e:E) {
110-
(*self).visit_local(a, e)
111-
}
112-
fn visit_block(&mut self, a:&Block, e:E) {
113-
(*self).visit_block(a, e)
114-
}
115-
fn visit_stmt(&mut self, a:@Stmt, e:E) {
116-
(*self).visit_stmt(a, e)
117-
}
118-
fn visit_arm(&mut self, a:&Arm, e:E) {
119-
(*self).visit_arm(a, e)
120-
}
121-
fn visit_pat(&mut self, a:@Pat, e:E) {
122-
(*self).visit_pat(a, e)
123-
}
124-
fn visit_decl(&mut self, a:@Decl, e:E) {
125-
(*self).visit_decl(a, e)
126-
}
127-
fn visit_expr(&mut self, a:@Expr, e:E) {
128-
(*self).visit_expr(a, e)
129-
}
130-
fn visit_expr_post(&mut self, a:@Expr, e:E) {
131-
(*self).visit_expr_post(a, e)
132-
}
133-
fn visit_ty(&mut self, a:&Ty, e:E) {
134-
(*self).visit_ty(a, e)
135-
}
136-
fn visit_generics(&mut self, a:&Generics, e:E) {
137-
(*self).visit_generics(a, e)
138-
}
139-
fn visit_fn(&mut self, a:&fn_kind, b:&fn_decl, c:&Block, d:Span, f:NodeId, e:E) {
140-
(*self).visit_fn(a, b, c, d, f, e)
141-
}
142-
fn visit_ty_method(&mut self, a:&TypeMethod, e:E) {
143-
(*self).visit_ty_method(a, e)
144-
}
145-
fn visit_trait_method(&mut self, a:&trait_method, e:E) {
146-
(*self).visit_trait_method(a, e)
147-
}
148-
fn visit_struct_def(&mut self, a:@struct_def, b:Ident, c:&Generics, d:NodeId, e:E) {
149-
(*self).visit_struct_def(a, b, c, d, e)
150-
}
151-
fn visit_struct_field(&mut self, a:@struct_field, e:E) {
152-
(*self).visit_struct_field(a, e)
153-
}
154-
fn visit_mac(&mut self, macro:&mac, e:E) {
155-
(*self).visit_mac(macro, e);
156-
}
157-
}
158-
15996
pub fn walk_crate<E:Clone, V:Visitor<E>>(visitor: &mut V, crate: &Crate, env: E) {
16097
visitor.visit_mod(&crate.module, crate.span, CRATE_NODE_ID, env)
16198
}

0 commit comments

Comments
 (0)