about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2013-08-13 00:30:27 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2013-08-15 04:06:17 +0200
commitef854c9b04cf916241587ea1764b86027e380e8f (patch)
treecc847a1b80c2993e633ec4a14dea8703ca316354
parent0d85928e37dec4795cf288e9f0bbe23d7a100b7a (diff)
downloadrust-ef854c9b04cf916241587ea1764b86027e380e8f.tar.gz
rust-ef854c9b04cf916241587ea1764b86027e380e8f.zip
Switch main borrowck to <V:Visitor> trait API.
fix borrowck/mod.rs to deal with fn_kind enum fallout.
-rw-r--r--src/librustc/middle/borrowck/mod.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs
index d410021063c..95eae32922b 100644
--- a/src/librustc/middle/borrowck/mod.rs
+++ b/src/librustc/middle/borrowck/mod.rs
@@ -26,9 +26,11 @@ use std::ops::{BitOr, BitAnd};
 use std::result::{Result};
 use syntax::ast;
 use syntax::ast_map;
-use syntax::oldvisit;
 use syntax::codemap::span;
 use syntax::parse::token;
+use syntax::visit;
+use syntax::visit::{Visitor,fn_kind};
+use syntax::ast::{fn_decl,Block,NodeId};
 
 macro_rules! if_ok(
     ($inp: expr) => (
@@ -59,6 +61,15 @@ impl Clone for LoanDataFlowOperator {
 
 pub type LoanDataFlow = DataFlowContext<LoanDataFlowOperator>;
 
+struct BorrowckVisitor;
+
+impl Visitor<@BorrowckCtxt> for BorrowckVisitor {
+    fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl,
+                b:&Block, s:span, n:NodeId, e:@BorrowckCtxt) {
+        borrowck_fn(self, fk, fd, b, s, n, e);
+    }
+}
+
 pub fn check_crate(
     tcx: ty::ctxt,
     method_map: typeck::method_map,
@@ -86,9 +97,8 @@ pub fn check_crate(
         }
     };
 
-    let v = oldvisit::mk_vt(@oldvisit::Visitor {visit_fn: borrowck_fn,
-                                          ..*oldvisit::default_visitor()});
-    oldvisit::visit_crate(crate, (bccx, v));
+    let mut v = BorrowckVisitor;
+    visit::walk_crate(&mut v, crate, bccx);
 
     if tcx.sess.borrowck_stats() {
         io::println("--- borrowck stats ---");
@@ -113,21 +123,21 @@ pub fn check_crate(
     }
 }
 
-fn borrowck_fn(fk: &oldvisit::fn_kind,
+fn borrowck_fn(v: &mut BorrowckVisitor,
+               fk: &visit::fn_kind,
                decl: &ast::fn_decl,
                body: &ast::Block,
                sp: span,
                id: ast::NodeId,
-               (this, v): (@BorrowckCtxt,
-                           oldvisit::vt<@BorrowckCtxt>)) {
+               this: @BorrowckCtxt) {
     match fk {
-        &oldvisit::fk_anon(*) |
-        &oldvisit::fk_fn_block(*) => {
+        &visit::fk_anon(*) |
+        &visit::fk_fn_block(*) => {
             // Closures are checked as part of their containing fn item.
         }
 
-        &oldvisit::fk_item_fn(*) |
-        &oldvisit::fk_method(*) => {
+        &visit::fk_item_fn(*) |
+        &visit::fk_method(*) => {
             debug!("borrowck_fn(id=%?)", id);
 
             // Check the body of fn items.
@@ -156,7 +166,7 @@ fn borrowck_fn(fk: &oldvisit::fn_kind,
         }
     }
 
-    oldvisit::visit_fn(fk, decl, body, sp, id, (this, v));
+    visit::walk_fn(v, fk, decl, body, sp, id, this);
 }
 
 // ----------------------------------------------------------------------