Port typeck/check/vtable.rs from oldvisit to <V:Visitor> trait API.

This commit is contained in:
Felix S. Klock II 2013-08-26 11:49:24 +02:00
parent da88f69f06
commit df6644104e

View File

@ -29,7 +29,8 @@ use syntax::ast;
use syntax::ast_util; use syntax::ast_util;
use syntax::codemap::span; use syntax::codemap::span;
use syntax::print::pprust::expr_to_str; use syntax::print::pprust::expr_to_str;
use syntax::oldvisit; use syntax::visit;
use syntax::visit::Visitor;
// vtable resolution looks for places where trait bounds are // vtable resolution looks for places where trait bounds are
// substituted in and figures out which vtable is used. There is some // substituted in and figures out which vtable is used. There is some
@ -712,11 +713,11 @@ pub fn early_resolve_expr(ex: @ast::expr,
} }
} }
fn resolve_expr(ex: @ast::expr, fn resolve_expr(v: &mut VtableResolveVisitor,
(fcx, v): (@mut FnCtxt, ex: @ast::expr,
oldvisit::vt<@mut FnCtxt>)) { fcx: @mut FnCtxt) {
early_resolve_expr(ex, fcx, false); early_resolve_expr(ex, fcx, false);
oldvisit::visit_expr(ex, (fcx, v)); visit::walk_expr(v, ex, fcx);
} }
pub fn resolve_impl(ccx: @mut CrateCtxt, impl_item: @ast::item) { pub fn resolve_impl(ccx: @mut CrateCtxt, impl_item: @ast::item) {
@ -763,12 +764,20 @@ pub fn resolve_impl(ccx: @mut CrateCtxt, impl_item: @ast::item) {
} }
} }
struct VtableResolveVisitor;
impl visit::Visitor<@mut FnCtxt> for VtableResolveVisitor {
fn visit_expr(&mut self, ex:@ast::expr, e:@mut FnCtxt) {
resolve_expr(self, ex, e);
}
fn visit_item(&mut self, _:@ast::item, _:@mut FnCtxt) {
// no-op
}
}
// Detect points where a trait-bounded type parameter is // Detect points where a trait-bounded type parameter is
// instantiated, resolve the impls for the parameters. // instantiated, resolve the impls for the parameters.
pub fn resolve_in_block(fcx: @mut FnCtxt, bl: &ast::Block) { pub fn resolve_in_block(fcx: @mut FnCtxt, bl: &ast::Block) {
oldvisit::visit_block(bl, (fcx, oldvisit::mk_vt(@oldvisit::Visitor { let mut visitor = VtableResolveVisitor;
visit_expr: resolve_expr, visit::walk_block(&mut visitor, bl, fcx);
visit_item: |_,_| {},
.. *oldvisit::default_visitor()
})));
} }