mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Update regionck to discharge the binder safely (using
`assert_no_late_bound_regions`) and to give more helpful debug output.
This commit is contained in:
parent
92425496e5
commit
9b5fb6091a
@ -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>,
|
fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
|
||||||
deref_expr: &ast::Expr,
|
deref_expr: &ast::Expr,
|
||||||
derefs: uint,
|
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));
|
let r_deref_expr = ty::ReScope(CodeExtent::from_node_id(deref_expr.id));
|
||||||
for i in range(0u, derefs) {
|
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);
|
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) {
|
derefd_ty = match rcx.fcx.inh.method_map.borrow().get(&method_call) {
|
||||||
Some(method) => {
|
Some(method) => {
|
||||||
|
debug!("constrain_autoderefs: #{} is overloaded, method={}",
|
||||||
|
i, method.repr(rcx.tcx()));
|
||||||
|
|
||||||
// Treat overloaded autoderefs as if an AutoRef adjustment
|
// Treat overloaded autoderefs as if an AutoRef adjustment
|
||||||
// was applied on the base type, as that is always the case.
|
// was applied on the base type, as that is always the case.
|
||||||
let fn_sig = ty::ty_fn_sig(method.ty);
|
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 {
|
let (m, r) = match self_ty.sty {
|
||||||
ty::ty_rptr(r, ref m) => (m.mutbl, r),
|
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 {}",
|
&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 mc = mc::MemCategorizationContext::new(rcx.fcx);
|
||||||
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
|
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,
|
link_region(rcx, deref_expr.span, *r,
|
||||||
ty::BorrowKind::from_mutbl(m), self_cmt);
|
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.
|
// Specialized version of constrain_call.
|
||||||
type_must_outlive(rcx, infer::CallRcvr(deref_expr.span),
|
type_must_outlive(rcx, infer::CallRcvr(deref_expr.span),
|
||||||
self_ty, r_deref_expr);
|
self_ty, r_deref_expr);
|
||||||
match fn_sig.0.output {
|
match fn_sig.output {
|
||||||
ty::FnConverging(return_type) => {
|
ty::FnConverging(return_type) => {
|
||||||
type_must_outlive(rcx, infer::CallReturn(deref_expr.span),
|
type_must_outlive(rcx, infer::CallReturn(deref_expr.span),
|
||||||
return_type, r_deref_expr);
|
return_type, r_deref_expr);
|
||||||
@ -1185,7 +1203,7 @@ fn link_region_from_node_type<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
|
|||||||
id: ast::NodeId,
|
id: ast::NodeId,
|
||||||
mutbl: ast::Mutability,
|
mutbl: ast::Mutability,
|
||||||
cmt_borrowed: mc::cmt<'tcx>) {
|
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()));
|
id, mutbl, cmt_borrowed.repr(rcx.tcx()));
|
||||||
|
|
||||||
let rptr_ty = rcx.resolve_node_type(id);
|
let rptr_ty = rcx.resolve_node_type(id);
|
||||||
|
Loading…
Reference in New Issue
Block a user