Skip to content

Commit

Permalink
make ty_region give a useful span when it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Mar 25, 2013
1 parent 6d4499c commit 057c40d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/librustc/middle/borrowck/gather_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn req_loans_in_expr(ex: @ast::expr,

// make sure that the thing we are pointing out stays valid
// for the lifetime `scope_r` of the resulting ptr:
let scope_r = ty_region(tcx.ty(ex));
let scope_r = ty_region(tcx, ex.span, tcx.ty(ex));
self.guarantee_valid(base_cmt, mutbl, scope_r);
visit::visit_expr(ex, self, vt);
}
Expand Down Expand Up @@ -599,7 +599,8 @@ pub impl GatherLoanCtxt {
// find the region of the resulting pointer (note that
// the type of such a pattern will *always* be a
// region pointer)
let scope_r = ty_region(self.tcx().ty(pat));
let scope_r = ty_region(self.tcx(), pat.span,
self.tcx().ty(pat));

// if the scope of the region ptr turns out to be
// specific to this arm, wrap the categorization with
Expand Down
17 changes: 11 additions & 6 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2794,13 +2794,18 @@ pub fn ty_vstore(ty: t) -> vstore {
}
}

pub fn ty_region(ty: t) -> Region {
pub fn ty_region(tcx: ctxt,
span: span,
ty: t) -> Region {
match get(ty).sty {
ty_rptr(r, _) => r,
ty_evec(_, vstore_slice(r)) => r,
ty_estr(vstore_slice(r)) => r,
ref s => fail!(fmt!("ty_region() invoked on in appropriate ty: %?",
(*s)))
ty_rptr(r, _) => r,
ty_evec(_, vstore_slice(r)) => r,
ty_estr(vstore_slice(r)) => r,
ref s => {
tcx.sess.span_bug(
span,
fmt!("ty_region() invoked on in appropriate ty: %?", s));
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,9 @@ pub mod guarantor {
// mk_subr should never fail.
let rptr_ty = rcx.resolve_node_type(id);
if !ty::type_is_error(rptr_ty) {
debug!("rptr_ty=%s", ty_to_str(rcx.fcx.ccx.tcx, rptr_ty));
let r = ty::ty_region(rptr_ty);
let tcx = rcx.fcx.ccx.tcx;
debug!("rptr_ty=%s", ty_to_str(tcx, rptr_ty));
let r = ty::ty_region(tcx, span, rptr_ty);
infallibly_mk_subr(rcx, true, span, r, bound);
}
}
Expand Down Expand Up @@ -890,7 +891,7 @@ pub mod guarantor {
ast::pat_region(p) => {
let rptr_ty = rcx.resolve_node_type(pat.id);
if !ty::type_is_error(rptr_ty) {
let r = ty::ty_region(rptr_ty);
let r = ty::ty_region(rcx.fcx.tcx(), pat.span, rptr_ty);
link_ref_bindings_in_pat(rcx, p, Some(r));
}
}
Expand Down

5 comments on commit 057c40d

@bors
Copy link
Contributor

@bors bors commented on 057c40d Mar 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from catamorphism
at nikomatsakis@057c40d

@bors
Copy link
Contributor

@bors bors commented on 057c40d Mar 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nikomatsakis/rust/ty_region-useful-span = 057c40d into auto

@bors
Copy link
Contributor

@bors bors commented on 057c40d Mar 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nikomatsakis/rust/ty_region-useful-span = 057c40d merged ok, testing candidate = 74fb263

@bors
Copy link
Contributor

@bors bors commented on 057c40d Mar 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 057c40d Mar 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 74fb263

Please sign in to comment.