Skip to content

Commit 8df7c2b

Browse files
committed
Fuzzer: first steps of making steal_exprs more generic
1 parent cdf30c2 commit 8df7c2b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/fuzzer/fuzzer.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ fn find_rust_files(files: &mutable [str], path: &str) {
4848
}
4949
}
5050

51-
fn safe_to_steal(e: ast::expr_) -> bool {
52-
alt e {
51+
fn safe_to_steal_expr(e: &@ast::expr) -> bool {
52+
alt e.node {
5353

5454
// https://github.com/graydon/rust/issues/890
5555
ast::expr_lit(lit) {
@@ -89,17 +89,19 @@ fn safe_to_steal(e: ast::expr_) -> bool {
8989
}
9090
}
9191

92+
// Not type-parameterized: https://github.com/graydon/rust/issues/898
93+
fn stash_expr_if(c: fn(&@ast::expr)->bool, es: @mutable [ast::expr], e: &@ast::expr) {
94+
if c(e) {
95+
*es += [*e];
96+
} else {/* now my indices are wrong :( */ }
97+
}
98+
9299
fn steal_exprs(crate: &ast::crate) -> [ast::expr] {
93100
let exprs: @mutable [ast::expr] = @mutable [];
94-
// "Stash" is not type-parameterized because of the need for safe_to_steal
95-
fn stash_expr(es: @mutable [ast::expr], e: &@ast::expr) {
96-
if safe_to_steal(e.node) {
97-
*es += [*e];
98-
} else {/* now my indices are wrong :( */ }
99-
}
100-
let v =
101-
visit::mk_simple_visitor(@{visit_expr: bind stash_expr(exprs, _)
102-
with *visit::default_simple_visitor()});
101+
let v = visit::mk_simple_visitor(@{
102+
visit_expr: bind stash_expr_if(safe_to_steal_expr, exprs, _)
103+
with *visit::default_simple_visitor()
104+
});
103105
visit::visit_crate(crate, (), v);;
104106
*exprs
105107
}

0 commit comments

Comments
 (0)