Skip to content

Commit df483e8

Browse files
committed
auto merge of #7084 : pnkfelix/rust/fsk-visitor-refactoring, r=pnkfelix
This step 1 in my plan for issue #7081: Refactor visit.rs with a `@Visitor` trait.
2 parents 78cddc8 + 009a2fd commit df483e8

36 files changed

+765
-775
lines changed

src/libfuzzer/fuzzer.rc

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub fn steal(crate: @ast::crate, tm: test_mode) -> StolenStuff {
176176
visit_ty: |a| stash_ty_if(safe_to_steal_ty, tys, a, tm),
177177
.. *visit::default_simple_visitor()
178178
});
179-
visit::visit_crate(crate, (), v);
179+
visit::visit_crate(crate, ((), v));
180180
StolenStuff {
181181
exprs: (*exprs).clone(),
182182
tys: (*tys).clone(),
@@ -539,7 +539,7 @@ pub fn has_raw_pointers(c: @ast::crate) -> bool {
539539
visit::mk_simple_visitor(@visit::SimpleVisitor {
540540
visit_ty: |a| visit_ty(has_rp, a),
541541
.. *visit::default_simple_visitor()});
542-
visit::visit_crate(c, (), v);
542+
visit::visit_crate(c, ((), v));
543543
return *has_rp;
544544
}
545545

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn read_crates(diag: @span_handler,
5252
visit_item: |a| visit_item(e, a),
5353
.. *visit::default_simple_visitor()});
5454
visit_crate(e, crate);
55-
visit::visit_crate(crate, (), v);
55+
visit::visit_crate(crate, ((), v));
5656
dump_crates(e.crate_cache);
5757
warn_if_multiple_versions(e, diag, e.crate_cache);
5858
}

src/librustc/metadata/encoder.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1120,12 +1120,12 @@ fn encode_info_for_items(ecx: @EncodeContext,
11201120
encode_info_for_mod(ecx, ebml_w, &crate.node.module,
11211121
crate_node_id, [],
11221122
syntax::parse::token::special_idents::invalid);
1123-
visit::visit_crate(crate, (), visit::mk_vt(@visit::Visitor {
1124-
visit_expr: |_e, _cx, _v| { },
1123+
visit::visit_crate(crate, ((), visit::mk_vt(@visit::Visitor {
1124+
visit_expr: |_e, (_cx, _v)| { },
11251125
visit_item: {
11261126
let ebml_w = copy *ebml_w;
1127-
|i, cx, v| {
1128-
visit::visit_item(i, cx, v);
1127+
|i, (cx, v)| {
1128+
visit::visit_item(i, (cx, v));
11291129
match ecx.tcx.items.get_copy(&i.id) {
11301130
ast_map::node_item(_, pt) => {
11311131
let mut ebml_w = copy ebml_w;
@@ -1137,8 +1137,8 @@ fn encode_info_for_items(ecx: @EncodeContext,
11371137
},
11381138
visit_foreign_item: {
11391139
let ebml_w = copy *ebml_w;
1140-
|ni, cx, v| {
1141-
visit::visit_foreign_item(ni, cx, v);
1140+
|ni, (cx, v)| {
1141+
visit::visit_foreign_item(ni, (cx, v));
11421142
match ecx.tcx.items.get_copy(&ni.id) {
11431143
ast_map::node_foreign_item(_, abi, _, pt) => {
11441144
let mut ebml_w = copy ebml_w;
@@ -1155,7 +1155,7 @@ fn encode_info_for_items(ecx: @EncodeContext,
11551155
}
11561156
},
11571157
..*visit::default_visitor()
1158-
}));
1158+
})));
11591159
ebml_w.end_tag();
11601160
return /*bad*/copy *index;
11611161
}

src/librustc/middle/borrowck/check_loans.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn check_loans(bccx: @BorrowckCtxt,
6262
visit_pat: check_loans_in_pat,
6363
visit_fn: check_loans_in_fn,
6464
.. *visit::default_visitor()});
65-
(vt.visit_block)(body, clcx, vt);
65+
(vt.visit_block)(body, (clcx, vt));
6666
}
6767

6868
enum MoveError {
@@ -614,8 +614,8 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
614614
body: &ast::blk,
615615
sp: span,
616616
id: ast::node_id,
617-
this: @mut CheckLoanCtxt<'a>,
618-
visitor: visit::vt<@mut CheckLoanCtxt<'a>>) {
617+
(this, visitor): (@mut CheckLoanCtxt<'a>,
618+
visit::vt<@mut CheckLoanCtxt<'a>>)) {
619619
match *fk {
620620
visit::fk_item_fn(*) |
621621
visit::fk_method(*) => {
@@ -629,7 +629,7 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
629629
}
630630
}
631631

632-
visit::visit_fn(fk, decl, body, sp, id, this, visitor);
632+
visit::visit_fn(fk, decl, body, sp, id, (this, visitor));
633633

634634
fn check_captured_variables(this: @mut CheckLoanCtxt,
635635
closure_id: ast::node_id,
@@ -677,15 +677,15 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
677677
}
678678

679679
fn check_loans_in_local<'a>(local: @ast::local,
680-
this: @mut CheckLoanCtxt<'a>,
681-
vt: visit::vt<@mut CheckLoanCtxt<'a>>) {
682-
visit::visit_local(local, this, vt);
680+
(this, vt): (@mut CheckLoanCtxt<'a>,
681+
visit::vt<@mut CheckLoanCtxt<'a>>)) {
682+
visit::visit_local(local, (this, vt));
683683
}
684684

685685
fn check_loans_in_expr<'a>(expr: @ast::expr,
686-
this: @mut CheckLoanCtxt<'a>,
687-
vt: visit::vt<@mut CheckLoanCtxt<'a>>) {
688-
visit::visit_expr(expr, this, vt);
686+
(this, vt): (@mut CheckLoanCtxt<'a>,
687+
visit::vt<@mut CheckLoanCtxt<'a>>)) {
688+
visit::visit_expr(expr, (this, vt));
689689

690690
debug!("check_loans_in_expr(expr=%s)",
691691
expr.repr(this.tcx()));
@@ -740,8 +740,8 @@ fn check_loans_in_expr<'a>(expr: @ast::expr,
740740
}
741741

742742
fn check_loans_in_pat<'a>(pat: @ast::pat,
743-
this: @mut CheckLoanCtxt<'a>,
744-
vt: visit::vt<@mut CheckLoanCtxt<'a>>)
743+
(this, vt): (@mut CheckLoanCtxt<'a>,
744+
visit::vt<@mut CheckLoanCtxt<'a>>))
745745
{
746746
this.check_for_conflicting_loans(pat.id);
747747

@@ -756,13 +756,13 @@ fn check_loans_in_pat<'a>(pat: @ast::pat,
756756
// rewalk the patterns and rebuild the pattern
757757
// categorizations.
758758

759-
visit::visit_pat(pat, this, vt);
759+
visit::visit_pat(pat, (this, vt));
760760
}
761761

762762
fn check_loans_in_block<'a>(blk: &ast::blk,
763-
this: @mut CheckLoanCtxt<'a>,
764-
vt: visit::vt<@mut CheckLoanCtxt<'a>>)
763+
(this, vt): (@mut CheckLoanCtxt<'a>,
764+
visit::vt<@mut CheckLoanCtxt<'a>>))
765765
{
766-
visit::visit_block(blk, this, vt);
766+
visit::visit_block(blk, (this, vt));
767767
this.check_for_conflicting_loans(blk.node.id);
768768
}

src/librustc/middle/borrowck/gather_loans/mod.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,28 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
9292
visit_pat: add_pat_to_id_range,
9393
visit_local: gather_loans_in_local,
9494
.. *visit::default_visitor()});
95-
(v.visit_block)(body, glcx, v);
95+
(v.visit_block)(body, (glcx, v));
9696
return (glcx.id_range, glcx.all_loans, glcx.move_data);
9797
}
9898

9999
fn add_pat_to_id_range(p: @ast::pat,
100-
this: @mut GatherLoanCtxt,
101-
v: visit::vt<@mut GatherLoanCtxt>) {
100+
(this, v): (@mut GatherLoanCtxt,
101+
visit::vt<@mut GatherLoanCtxt>)) {
102102
// NB: This visitor function just adds the pat ids into the id
103103
// range. We gather loans that occur in patterns using the
104104
// `gather_pat()` method below. Eventually these two should be
105105
// brought together.
106106
this.id_range.add(p.id);
107-
visit::visit_pat(p, this, v);
107+
visit::visit_pat(p, (this, v));
108108
}
109109

110110
fn gather_loans_in_fn(fk: &visit::fn_kind,
111111
decl: &ast::fn_decl,
112112
body: &ast::blk,
113113
sp: span,
114114
id: ast::node_id,
115-
this: @mut GatherLoanCtxt,
116-
v: visit::vt<@mut GatherLoanCtxt>) {
115+
(this, v): (@mut GatherLoanCtxt,
116+
visit::vt<@mut GatherLoanCtxt>)) {
117117
match fk {
118118
// Do not visit items here, the outer loop in borrowck/mod
119119
// will visit them for us in turn.
@@ -124,22 +124,22 @@ fn gather_loans_in_fn(fk: &visit::fn_kind,
124124
// Visit closures as part of the containing item.
125125
&visit::fk_anon(*) | &visit::fk_fn_block(*) => {
126126
this.push_repeating_id(body.node.id);
127-
visit::visit_fn(fk, decl, body, sp, id, this, v);
127+
visit::visit_fn(fk, decl, body, sp, id, (this, v));
128128
this.pop_repeating_id(body.node.id);
129129
}
130130
}
131131
}
132132

133133
fn gather_loans_in_block(blk: &ast::blk,
134-
this: @mut GatherLoanCtxt,
135-
vt: visit::vt<@mut GatherLoanCtxt>) {
134+
(this, vt): (@mut GatherLoanCtxt,
135+
visit::vt<@mut GatherLoanCtxt>)) {
136136
this.id_range.add(blk.node.id);
137-
visit::visit_block(blk, this, vt);
137+
visit::visit_block(blk, (this, vt));
138138
}
139139

140140
fn gather_loans_in_local(local: @ast::local,
141-
this: @mut GatherLoanCtxt,
142-
vt: visit::vt<@mut GatherLoanCtxt>) {
141+
(this, vt): (@mut GatherLoanCtxt,
142+
visit::vt<@mut GatherLoanCtxt>)) {
143143
if local.node.init.is_none() {
144144
// Variable declarations without initializers are considered "moves":
145145
let tcx = this.bccx.tcx;
@@ -163,12 +163,12 @@ fn gather_loans_in_local(local: @ast::local,
163163
}
164164
}
165165

166-
visit::visit_local(local, this, vt);
166+
visit::visit_local(local, (this, vt));
167167
}
168168

169169
fn gather_loans_in_expr(ex: @ast::expr,
170-
this: @mut GatherLoanCtxt,
171-
vt: visit::vt<@mut GatherLoanCtxt>) {
170+
(this, vt): (@mut GatherLoanCtxt,
171+
visit::vt<@mut GatherLoanCtxt>)) {
172172
let bccx = this.bccx;
173173
let tcx = bccx.tcx;
174174

@@ -208,7 +208,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
208208
// for the lifetime `scope_r` of the resulting ptr:
209209
let scope_r = ty_region(tcx, ex.span, ty::expr_ty(tcx, ex));
210210
this.guarantee_valid(ex.id, ex.span, base_cmt, mutbl, scope_r);
211-
visit::visit_expr(ex, this, vt);
211+
visit::visit_expr(ex, (this, vt));
212212
}
213213

214214
ast::expr_assign(l, _) | ast::expr_assign_op(_, _, l, _) => {
@@ -225,7 +225,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
225225
// with moves etc, just ignore.
226226
}
227227
}
228-
visit::visit_expr(ex, this, vt);
228+
visit::visit_expr(ex, (this, vt));
229229
}
230230

231231
ast::expr_match(ex_v, ref arms) => {
@@ -235,7 +235,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
235235
this.gather_pat(cmt, *pat, arm.body.node.id, ex.id);
236236
}
237237
}
238-
visit::visit_expr(ex, this, vt);
238+
visit::visit_expr(ex, (this, vt));
239239
}
240240

241241
ast::expr_index(_, _, arg) |
@@ -249,36 +249,36 @@ fn gather_loans_in_expr(ex: @ast::expr,
249249
let scope_r = ty::re_scope(ex.id);
250250
let arg_cmt = this.bccx.cat_expr(arg);
251251
this.guarantee_valid(arg.id, arg.span, arg_cmt, m_imm, scope_r);
252-
visit::visit_expr(ex, this, vt);
252+
visit::visit_expr(ex, (this, vt));
253253
}
254254

255255
// see explanation attached to the `root_ub` field:
256256
ast::expr_while(cond, ref body) => {
257257
// during the condition, can only root for the condition
258258
this.push_repeating_id(cond.id);
259-
(vt.visit_expr)(cond, this, vt);
259+
(vt.visit_expr)(cond, (this, vt));
260260
this.pop_repeating_id(cond.id);
261261

262262
// during body, can only root for the body
263263
this.push_repeating_id(body.node.id);
264-
(vt.visit_block)(body, this, vt);
264+
(vt.visit_block)(body, (this, vt));
265265
this.pop_repeating_id(body.node.id);
266266
}
267267

268268
// see explanation attached to the `root_ub` field:
269269
ast::expr_loop(ref body, _) => {
270270
this.push_repeating_id(body.node.id);
271-
visit::visit_expr(ex, this, vt);
271+
visit::visit_expr(ex, (this, vt));
272272
this.pop_repeating_id(body.node.id);
273273
}
274274

275275
ast::expr_fn_block(*) => {
276276
gather_moves::gather_captures(this.bccx, this.move_data, ex);
277-
visit::visit_expr(ex, this, vt);
277+
visit::visit_expr(ex, (this, vt));
278278
}
279279

280280
_ => {
281-
visit::visit_expr(ex, this, vt);
281+
visit::visit_expr(ex, (this, vt));
282282
}
283283
}
284284
}
@@ -702,13 +702,13 @@ impl GatherLoanCtxt {
702702
// Setting up info that preserve needs.
703703
// This is just the most convenient place to do it.
704704
fn add_stmt_to_map(stmt: @ast::stmt,
705-
this: @mut GatherLoanCtxt,
706-
vt: visit::vt<@mut GatherLoanCtxt>) {
705+
(this, vt): (@mut GatherLoanCtxt,
706+
visit::vt<@mut GatherLoanCtxt>)) {
707707
match stmt.node {
708708
ast::stmt_expr(_, id) | ast::stmt_semi(_, id) => {
709709
this.bccx.stmt_map.insert(id);
710710
}
711711
_ => ()
712712
}
713-
visit::visit_stmt(stmt, this, vt);
713+
visit::visit_stmt(stmt, (this, vt));
714714
}

src/librustc/middle/borrowck/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn check_crate(
8181

8282
let v = visit::mk_vt(@visit::Visitor {visit_fn: borrowck_fn,
8383
..*visit::default_visitor()});
84-
visit::visit_crate(crate, bccx, v);
84+
visit::visit_crate(crate, (bccx, v));
8585

8686
if tcx.sess.borrowck_stats() {
8787
io::println("--- borrowck stats ---");
@@ -111,8 +111,8 @@ fn borrowck_fn(fk: &visit::fn_kind,
111111
body: &ast::blk,
112112
sp: span,
113113
id: ast::node_id,
114-
this: @BorrowckCtxt,
115-
v: visit::vt<@BorrowckCtxt>) {
114+
(this, v): (@BorrowckCtxt,
115+
visit::vt<@BorrowckCtxt>)) {
116116
match fk {
117117
&visit::fk_anon(*) |
118118
&visit::fk_fn_block(*) => {
@@ -149,7 +149,7 @@ fn borrowck_fn(fk: &visit::fn_kind,
149149
}
150150
}
151151

152-
visit::visit_fn(fk, decl, body, sp, id, this, v);
152+
visit::visit_fn(fk, decl, body, sp, id, (this, v));
153153
}
154154

155155
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)