Skip to content

typeck::check::_match: Better error handling #15538

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
wants to merge 3 commits into from
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
13 changes: 12 additions & 1 deletion src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,18 @@ impl<'a> TypeFolder for SubstFolder<'a> {
ty::ReEarlyBound(_, space, i, _) => {
match self.substs.regions {
ErasedRegions => ty::ReStatic,
NonerasedRegions(ref regions) => *regions.get(space, i),
NonerasedRegions(ref regions) =>
match regions.opt_get(space, i) {
Some(t) => *t,
None => {
let span = self.span.unwrap_or(DUMMY_SP);
self.tcx().sess.span_bug(
span,
format!("Type parameter out of range \
when substituting (root type={})",
self.root_ty.repr(self.tcx())).as_slice());
}
}
}
}
_ => r
Expand Down
17 changes: 13 additions & 4 deletions src/librustc/middle/typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,26 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
ty::ty_struct(cid, ref substs) => {
// Verify that the pattern named the right structure.
let item_did = tcx.def_map.borrow().get(&pat.id).def_id();
let struct_did =
ty::ty_to_def_id(
ty::lookup_item_type(tcx, item_did).ty).unwrap();
if struct_did != cid {
match ty::ty_to_def_id(ty::lookup_item_type(tcx, item_did).ty) {
Some(struct_did) if struct_did != cid => {
tcx.sess
.span_err(path.span,
format!("`{}` does not name the \
structure `{}`",
pprust::path_to_string(path),
fcx.infcx()
.ty_to_string(expected)).as_slice())
},
Some(_) => {},
None => {
tcx.sess.span_bug(
path.span,
format!("This shouldn't happen: failed to lookup structure. \
item_did = {}",
item_did
).as_slice()
)
},
}

check_struct_pat(pcx, pat.id, pat.span, expected, path,
Expand Down