Extend Typer interface to include expr_ty_adjusted so that we can

remove another direct dependency on tcx from euv.
This commit is contained in:
Niko Matsakis 2014-12-03 13:06:48 -05:00
parent f3ff084d01
commit 8f770f10b2
5 changed files with 16 additions and 4 deletions

View File

@ -647,7 +647,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
}
fn walk_callee(&mut self, call: &ast::Expr, callee: &ast::Expr) {
let callee_ty = ty::expr_ty_adjusted(self.tcx(), callee);
let callee_ty = return_if_err!(self.typer.expr_ty_adjusted(callee));
debug!("walk_callee: callee={} callee_ty={}",
callee.repr(self.tcx()), callee_ty.repr(self.tcx()));
let call_scope = region::CodeExtent::from_node_id(call.id);

View File

@ -285,6 +285,7 @@ pub type McResult<T> = Result<T, ()>;
pub trait Typer<'tcx> {
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>;
fn node_ty(&self, id: ast::NodeId) -> McResult<Ty<'tcx>>;
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult<Ty<'tcx>>;
fn node_method_ty(&self, method_call: ty::MethodCall) -> Option<Ty<'tcx>>;
fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment<'tcx>>>;
fn is_method_call(&self, id: ast::NodeId) -> bool;

View File

@ -6169,7 +6169,11 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> {
Ok(ty::node_id_to_type(self, id))
}
fn node_method_ty(&self, method_call: MethodCall) -> Option<Ty<'tcx>> {
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> mc::McResult<Ty<'tcx>> {
Ok(ty::expr_ty_adjusted(self, expr))
}
fn node_method_ty(&self, method_call: ty::MethodCall) -> Option<Ty<'tcx>> {
self.method_map.borrow().get(&method_call).map(|method| method.ty)
}

View File

@ -467,6 +467,10 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> {
Ok(node_id_type(self, id))
}
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> mc::McResult<Ty<'tcx>> {
Ok(expr_ty_adjusted(self, expr))
}
fn node_method_ty(&self, method_call: ty::MethodCall) -> Option<Ty<'tcx>> {
self.tcx()
.method_map
@ -752,11 +756,11 @@ pub fn node_id_type<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, id: ast::NodeId) -> Ty
monomorphize_type(bcx, t)
}
pub fn expr_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ex: &ast::Expr) -> Ty<'tcx> {
pub fn expr_ty<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, ex: &ast::Expr) -> Ty<'tcx> {
node_id_type(bcx, ex.id)
}
pub fn expr_ty_adjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ex: &ast::Expr) -> Ty<'tcx> {
pub fn expr_ty_adjusted<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, ex: &ast::Expr) -> Ty<'tcx> {
monomorphize_type(bcx, ty::expr_ty_adjusted(bcx.tcx(), ex))
}

View File

@ -290,6 +290,9 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> {
let ty = self.node_ty(id);
Ok(self.infcx().resolve_type_vars_if_possible(ty))
}
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult<Ty<'tcx>> {
let ty = self.expr_ty_adjusted(expr);
Ok(self.infcx().resolve_type_vars_if_possible(ty))
}
fn node_method_ty(&self, method_call: ty::MethodCall)
-> Option<Ty<'tcx>> {