diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 4684bd3532ec1..27e1381735e43 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -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 diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 2232cc4965785..91515352576b4 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -517,10 +517,8 @@ 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 \ @@ -528,6 +526,17 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { 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,