about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-01-08 09:13:40 -0500
committerNiko Matsakis <niko@alum.mit.edu>2015-01-08 09:19:56 -0500
commit9b5fb6091a99dc7675c79bfc758ae2ecb3a8cc96 (patch)
tree8947d86048a7f5bbc26e08143e9479dc3f469f3e
parent92425496e525855fd772f771a35456a4b66c071f (diff)
downloadrust-9b5fb6091a99dc7675c79bfc758ae2ecb3a8cc96.tar.gz
rust-9b5fb6091a99dc7675c79bfc758ae2ecb3a8cc96.zip
Update regionck to discharge the binder safely (using
`assert_no_late_bound_regions`) and to give more helpful debug output.
-rw-r--r--src/librustc_typeck/check/regionck.rs38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs
index c74612d3aa8..3b5027dbb9e 100644
--- a/src/librustc_typeck/check/regionck.rs
+++ b/src/librustc_typeck/check/regionck.rs
@@ -936,29 +936,47 @@ fn constrain_call<'a, I: Iterator<Item=&'a ast::Expr>>(rcx: &mut Rcx,
 fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
                                   deref_expr: &ast::Expr,
                                   derefs: uint,
-                                  mut derefd_ty: Ty<'tcx>) {
+                                  mut derefd_ty: Ty<'tcx>)
+{
+    debug!("constrain_autoderefs(deref_expr={}, derefs={}, derefd_ty={})",
+           deref_expr.repr(rcx.tcx()),
+           derefs,
+           derefd_ty.repr(rcx.tcx()));
+
     let r_deref_expr = ty::ReScope(CodeExtent::from_node_id(deref_expr.id));
     for i in range(0u, derefs) {
-        debug!("constrain_autoderefs(deref_expr=?, derefd_ty={}, derefs={}/{}",
-               rcx.fcx.infcx().ty_to_string(derefd_ty),
-               i, derefs);
-
         let method_call = MethodCall::autoderef(deref_expr.id, i);
+        debug!("constrain_autoderefs: method_call={:?} (of {:?} total)", method_call, derefs);
+
         derefd_ty = match rcx.fcx.inh.method_map.borrow().get(&method_call) {
             Some(method) => {
+                debug!("constrain_autoderefs: #{} is overloaded, method={}",
+                       i, method.repr(rcx.tcx()));
+
                 // Treat overloaded autoderefs as if an AutoRef adjustment
                 // was applied on the base type, as that is always the case.
                 let fn_sig = ty::ty_fn_sig(method.ty);
-                let self_ty = fn_sig.0.inputs[0];
+                let fn_sig = // late-bound regions should have been instantiated
+                    ty::assert_no_late_bound_regions(rcx.tcx(), fn_sig);
+                let self_ty = fn_sig.inputs[0];
                 let (m, r) = match self_ty.sty {
                     ty::ty_rptr(r, ref m) => (m.mutbl, r),
-                    _ => rcx.tcx().sess.span_bug(deref_expr.span,
+                    _ => {
+                        rcx.tcx().sess.span_bug(
+                            deref_expr.span,
                             &format!("bad overloaded deref type {}",
-                                    method.ty.repr(rcx.tcx()))[])
+                                     method.ty.repr(rcx.tcx()))[])
+                    }
                 };
+
+                debug!("constrain_autoderefs: receiver r={:?} m={:?}",
+                       r.repr(rcx.tcx()), m);
+
                 {
                     let mc = mc::MemCategorizationContext::new(rcx.fcx);
                     let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
+                    debug!("constrain_autoderefs: self_cmt={:?}",
+                           self_cmt.repr(rcx.tcx()));
                     link_region(rcx, deref_expr.span, *r,
                                 ty::BorrowKind::from_mutbl(m), self_cmt);
                 }
@@ -966,7 +984,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
                 // Specialized version of constrain_call.
                 type_must_outlive(rcx, infer::CallRcvr(deref_expr.span),
                                   self_ty, r_deref_expr);
-                match fn_sig.0.output {
+                match fn_sig.output {
                     ty::FnConverging(return_type) => {
                         type_must_outlive(rcx, infer::CallReturn(deref_expr.span),
                                           return_type, r_deref_expr);
@@ -1185,7 +1203,7 @@ fn link_region_from_node_type<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
                                         id: ast::NodeId,
                                         mutbl: ast::Mutability,
                                         cmt_borrowed: mc::cmt<'tcx>) {
-    debug!("link_region_from_node_type(id={}, mutbl={}, cmt_borrowed={})",
+    debug!("link_region_from_node_type(id={:?}, mutbl={:?}, cmt_borrowed={})",
            id, mutbl, cmt_borrowed.repr(rcx.tcx()));
 
     let rptr_ty = rcx.resolve_node_type(id);