Skip to content

Commit 222de70

Browse files
committed
---
yaml --- r: 77663 b: refs/heads/master c: 6af6b08 h: refs/heads/master i: 77661: ddf47b6 77659: af003f3 77655: cf14dcb 77647: b8bb182 77631: 1d79d6e v: v3
1 parent f2a7f64 commit 222de70

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ec6ab8c8996d1a08cab3546aa853df3cfbc729c7
2+
refs/heads/master: 6af6b088ad0a283cdf6fc14291d1a35efa1297cb
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 60fba4d7d677ec098e6a43014132fe99f7547363
55
refs/heads/try: ebfe63cd1c0b5d23f7ea60c69b4fde2e30cfd42a

trunk/src/librustc/middle/moves.rs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ use std::at_vec;
139139
use std::hashmap::{HashSet, HashMap};
140140
use syntax::ast::*;
141141
use syntax::ast_util;
142-
use syntax::oldvisit;
143-
use syntax::oldvisit::vt;
142+
use syntax::visit;
143+
use syntax::visit::Visitor;
144144
use syntax::codemap::span;
145145

146146
#[deriving(Encodable, Decodable)]
@@ -190,16 +190,25 @@ enum UseMode {
190190
Read // Read no matter what the type.
191191
}
192192

193+
struct ComputeModesVisitor;
194+
195+
impl visit::Visitor<VisitContext> for ComputeModesVisitor {
196+
fn visit_fn(&mut self, fk:&visit::fn_kind, fd:&fn_decl, b:&Block, s:span, n:NodeId, e:VisitContext) {
197+
compute_modes_for_fn(*self, fk, fd, b, s, n, e);
198+
}
199+
fn visit_expr(&mut self, ex:@expr, e:VisitContext) {
200+
compute_modes_for_expr(*self, ex, e);
201+
}
202+
fn visit_local(&mut self, l:@Local, e:VisitContext) {
203+
compute_modes_for_local(*self, l, e);
204+
}
205+
}
206+
193207
pub fn compute_moves(tcx: ty::ctxt,
194208
method_map: method_map,
195209
crate: &Crate) -> MoveMaps
196210
{
197-
let visitor = oldvisit::mk_vt(@oldvisit::Visitor {
198-
visit_fn: compute_modes_for_fn,
199-
visit_expr: compute_modes_for_expr,
200-
visit_local: compute_modes_for_local,
201-
.. *oldvisit::default_visitor()
202-
});
211+
let mut visitor = ComputeModesVisitor;
203212
let visit_cx = VisitContext {
204213
tcx: tcx,
205214
method_map: method_map,
@@ -209,7 +218,7 @@ pub fn compute_moves(tcx: ty::ctxt,
209218
moved_variables_set: @mut HashSet::new()
210219
}
211220
};
212-
oldvisit::visit_crate(crate, (visit_cx, visitor));
221+
visit::walk_crate(&mut visitor, crate, visit_cx);
213222
return visit_cx.move_maps;
214223
}
215224

@@ -227,43 +236,44 @@ pub fn moved_variable_node_id_from_def(def: def) -> Option<NodeId> {
227236
///////////////////////////////////////////////////////////////////////////
228237
// Expressions
229238

230-
fn compute_modes_for_local<'a>(local: @Local,
231-
(cx, v): (VisitContext,
232-
vt<VisitContext>)) {
239+
fn compute_modes_for_local<'a>(v: ComputeModesVisitor,
240+
local: @Local,
241+
cx: VisitContext) {
233242
cx.use_pat(local.pat);
234243
for &init in local.init.iter() {
235244
cx.use_expr(init, Read, v);
236245
}
237246
}
238247

239-
fn compute_modes_for_fn(fk: &oldvisit::fn_kind,
248+
fn compute_modes_for_fn(v: ComputeModesVisitor,
249+
fk: &visit::fn_kind,
240250
decl: &fn_decl,
241251
body: &Block,
242252
span: span,
243253
id: NodeId,
244-
(cx, v): (VisitContext,
245-
vt<VisitContext>)) {
254+
cx: VisitContext) {
255+
let mut v = v;
246256
for a in decl.inputs.iter() {
247257
cx.use_pat(a.pat);
248258
}
249-
oldvisit::visit_fn(fk, decl, body, span, id, (cx, v));
259+
visit::walk_fn(&mut v, fk, decl, body, span, id, cx);
250260
}
251261

252-
fn compute_modes_for_expr(expr: @expr,
253-
(cx, v): (VisitContext,
254-
vt<VisitContext>))
262+
fn compute_modes_for_expr(v: ComputeModesVisitor,
263+
expr: @expr,
264+
cx: VisitContext)
255265
{
256266
cx.consume_expr(expr, v);
257267
}
258268

259269
impl VisitContext {
260-
pub fn consume_exprs(&self, exprs: &[@expr], visitor: vt<VisitContext>) {
270+
pub fn consume_exprs(&self, exprs: &[@expr], visitor: ComputeModesVisitor) {
261271
for expr in exprs.iter() {
262272
self.consume_expr(*expr, visitor);
263273
}
264274
}
265275

266-
pub fn consume_expr(&self, expr: @expr, visitor: vt<VisitContext>) {
276+
pub fn consume_expr(&self, expr: @expr, visitor: ComputeModesVisitor) {
267277
/*!
268278
* Indicates that the value of `expr` will be consumed,
269279
* meaning either copied or moved depending on its type.
@@ -281,7 +291,7 @@ impl VisitContext {
281291
};
282292
}
283293

284-
pub fn consume_block(&self, blk: &Block, visitor: vt<VisitContext>) {
294+
pub fn consume_block(&self, blk: &Block, visitor: ComputeModesVisitor) {
285295
/*!
286296
* Indicates that the value of `blk` will be consumed,
287297
* meaning either copied or moved depending on its type.
@@ -290,7 +300,8 @@ impl VisitContext {
290300
debug!("consume_block(blk.id=%?)", blk.id);
291301

292302
for stmt in blk.stmts.iter() {
293-
(visitor.visit_stmt)(*stmt, (*self, visitor));
303+
let mut v = visitor;
304+
v.visit_stmt(*stmt, *self);
294305
}
295306

296307
for tail_expr in blk.expr.iter() {
@@ -301,7 +312,7 @@ impl VisitContext {
301312
pub fn use_expr(&self,
302313
expr: @expr,
303314
expr_mode: UseMode,
304-
visitor: vt<VisitContext>) {
315+
visitor: ComputeModesVisitor) {
305316
/*!
306317
* Indicates that `expr` is used with a given mode. This will
307318
* in turn trigger calls to the subcomponents of `expr`.
@@ -570,7 +581,7 @@ impl VisitContext {
570581
expr: &expr,
571582
receiver_expr: @expr,
572583
arg_exprs: &[@expr],
573-
visitor: vt<VisitContext>)
584+
visitor: ComputeModesVisitor)
574585
-> bool {
575586
if !self.method_map.contains_key(&expr.id) {
576587
return false;
@@ -587,7 +598,7 @@ impl VisitContext {
587598
return true;
588599
}
589600

590-
pub fn consume_arm(&self, arm: &arm, visitor: vt<VisitContext>) {
601+
pub fn consume_arm(&self, arm: &arm, visitor: ComputeModesVisitor) {
591602
for pat in arm.pats.iter() {
592603
self.use_pat(*pat);
593604
}
@@ -630,21 +641,21 @@ impl VisitContext {
630641

631642
pub fn use_receiver(&self,
632643
receiver_expr: @expr,
633-
visitor: vt<VisitContext>) {
644+
visitor: ComputeModesVisitor) {
634645
self.use_fn_arg(receiver_expr, visitor);
635646
}
636647

637648
pub fn use_fn_args(&self,
638649
_: NodeId,
639650
arg_exprs: &[@expr],
640-
visitor: vt<VisitContext>) {
651+
visitor: ComputeModesVisitor) {
641652
//! Uses the argument expressions.
642653
for arg_expr in arg_exprs.iter() {
643654
self.use_fn_arg(*arg_expr, visitor);
644655
}
645656
}
646657

647-
pub fn use_fn_arg(&self, arg_expr: @expr, visitor: vt<VisitContext>) {
658+
pub fn use_fn_arg(&self, arg_expr: @expr, visitor: ComputeModesVisitor) {
648659
//! Uses the argument.
649660
self.consume_expr(arg_expr, visitor)
650661
}

0 commit comments

Comments
 (0)