Skip to content

make ty_region give a useful span when it fails #5546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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