Skip to content

Commit 4856456

Browse files
committed
Move mem-categorization more things to use TYPER for the method origin
1 parent a583ba2 commit 4856456

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

src/librustc/middle/expr_use_visitor.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -654,22 +654,19 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
654654
}
655655
_ => {
656656
let overloaded_call_type =
657-
match self.tcx()
658-
.method_map
659-
.borrow()
660-
.get(&MethodCall::expr(call.id)) {
661-
Some(ref method_callee) => {
662-
OverloadedCallType::from_method_origin(
663-
self.tcx(),
664-
&method_callee.origin)
665-
}
666-
None => {
667-
self.tcx().sess.span_bug(
668-
callee.span,
669-
format!("unexpected callee type {}",
670-
callee_ty.repr(self.tcx()))[])
671-
}
672-
};
657+
match self.typer.node_method_origin(MethodCall::expr(call.id)) {
658+
Some(method_origin) => {
659+
OverloadedCallType::from_method_origin(
660+
self.tcx(),
661+
&method_origin)
662+
}
663+
None => {
664+
self.tcx().sess.span_bug(
665+
callee.span,
666+
format!("unexpected callee type {}",
667+
callee_ty.repr(self.tcx())).as_slice())
668+
}
669+
};
673670
match overloaded_call_type {
674671
FnMutOverloadedCall => {
675672
self.borrow_expr(callee,

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ pub trait Typer<'tcx> {
285285
fn node_ty(&self, id: ast::NodeId) -> Ty<'tcx>;
286286
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> Ty<'tcx>;
287287
fn node_method_ty(&self, method_call: ty::MethodCall) -> Option<Ty<'tcx>>;
288+
fn node_method_origin(&self, method_call: ty::MethodCall)
289+
-> Option<ty::MethodOrigin<'tcx>>;
288290
fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment<'tcx>>>;
289291
fn is_method_call(&self, id: ast::NodeId) -> bool;
290292
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<region::CodeExtent>;

src/librustc/middle/ty.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,9 +3003,9 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
30033003
// FIXME(#14449): `borrowed_contents` below assumes `&mut`
30043004
// unboxed closure.
30053005
let upvars = unboxed_closure_upvars(cx, did, substs);
3006-
TypeContents::union(upvars[],
3007-
|f| tc_ty(cx, f.ty, cache)) |
3008-
borrowed_contents(r, MutMutable)
3006+
TypeContents::union(upvars.as_slice(),
3007+
|f| tc_ty(cx, f.ty, cache))
3008+
| borrowed_contents(r, MutMutable)
30093009
}
30103010

30113011
ty_tup(ref tys) => {
@@ -6177,6 +6177,12 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> {
61776177
self.method_map.borrow().get(&method_call).map(|method| method.ty)
61786178
}
61796179

6180+
fn node_method_origin(&self, method_call: ty::MethodCall)
6181+
-> Option<ty::MethodOrigin<'tcx>>
6182+
{
6183+
self.method_map.borrow().get(&method_call).map(|method| method.origin.clone())
6184+
}
6185+
61806186
fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment<'tcx>>> {
61816187
&self.adjustments
61826188
}

src/librustc_trans/trans/common.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,16 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> {
479479
.map(|method| monomorphize_type(self, method.ty))
480480
}
481481

482+
fn node_method_origin(&self, method_call: ty::MethodCall)
483+
-> Option<ty::MethodOrigin<'tcx>>
484+
{
485+
self.tcx()
486+
.method_map
487+
.borrow()
488+
.get(&method_call)
489+
.map(|method| method.origin.clone())
490+
}
491+
482492
fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment<'tcx>>> {
483493
&self.tcx().adjustments
484494
}

src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ impl<'a, 'tcx> mc::Typer<'tcx> for FnCtxt<'a, 'tcx> {
301301
.map(|method| method.ty)
302302
.map(|ty| self.infcx().resolve_type_vars_if_possible(&ty))
303303
}
304+
fn node_method_origin(&self, method_call: ty::MethodCall)
305+
-> Option<ty::MethodOrigin<'tcx>>
306+
{
307+
self.inh.method_map.borrow()
308+
.get(&method_call)
309+
.map(|method| method.origin.clone())
310+
}
304311
fn adjustments(&self) -> &RefCell<NodeMap<ty::AutoAdjustment<'tcx>>> {
305312
&self.inh.adjustments
306313
}

0 commit comments

Comments
 (0)