From bfc4f645c128fce2c4a7e0a22500b2130c51ba6c Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Tue, 8 Jul 2014 19:45:36 -0400 Subject: [PATCH 1/2] typeck::check::_match: Better error handling Previously this was an Option::unwrap() which failed for me. Unfortunately I've since inadvertently worked around the bug and have been unable to reproduce it. With this patch hopefully the next person to encounter this will be in a slightly better position to debug it. --- src/librustc/middle/typeck/check/_match.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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, From b9f9ab5273422919727c3c6d5044aec0c1b202ff Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Wed, 9 Jul 2014 15:47:55 -0400 Subject: [PATCH 2/2] Better handling on parameter lookup failure --- src/librustc/middle/subst.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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