diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-12-03 13:06:48 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-12-25 07:04:07 -0500 |
| commit | 8f770f10b2740ff1fb2be938f37ef4f35f8bf4ca (patch) | |
| tree | f4524ee5c5735b329d8bb3816447018a01caf8c6 | |
| parent | f3ff084d0166b72d9ad9cf11ad1ec21d5d4b2158 (diff) | |
| download | rust-8f770f10b2740ff1fb2be938f37ef4f35f8bf4ca.tar.gz rust-8f770f10b2740ff1fb2be938f37ef4f35f8bf4ca.zip | |
Extend Typer interface to include `expr_ty_adjusted` so that we can
remove another direct dependency on tcx from euv.
| -rw-r--r-- | src/librustc/middle/expr_use_visitor.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/mem_categorization.rs | 1 | ||||
| -rw-r--r-- | src/librustc/middle/ty.rs | 6 | ||||
| -rw-r--r-- | src/librustc_trans/trans/common.rs | 8 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 3 |
5 files changed, 16 insertions, 4 deletions
diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index a55ef23ddad..6ec9171057b 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -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); diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 932a124ed33..7dadd832ca2 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -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; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 9c1259f4120..659cf85937e 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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) } diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index 9a3e39ff10b..883205765f2 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -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)) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 835e4860198..ca8c901b6fd 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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>> { |
