diff options
| author | Ben Gamari <bgamari.foss@gmail.com> | 2014-07-08 19:45:36 -0400 |
|---|---|---|
| committer | Ben Gamari <bgamari.foss@gmail.com> | 2014-07-15 19:34:41 -0400 |
| commit | 741bb1a57e42c3a5e23ef9b01d4fc806b3fc56af (patch) | |
| tree | 9944687bc938b08bf2dacec00e352af920911820 | |
| parent | bdf5b6c3daa2797c704f1f1b335b1280b8d8fbdb (diff) | |
| download | rust-741bb1a57e42c3a5e23ef9b01d4fc806b3fc56af.tar.gz rust-741bb1a57e42c3a5e23ef9b01d4fc806b3fc56af.zip | |
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.
| -rw-r--r-- | src/librustc/middle/typeck/check/_match.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 170f850328e..be01643e22a 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -507,14 +507,20 @@ 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 { - span_err!(tcx.sess, pat.span, E0032, - "`{}` does not name the structure `{}`", - pprust::path_to_string(path), - fcx.infcx().ty_to_string(expected)); + match ty::ty_to_def_id(ty::lookup_item_type(tcx, item_did).ty) { + Some(struct_did) if struct_did != cid => { + span_err!(tcx.sess, path.span, E0032, + "`{}` does not name the structure `{}`", + pprust::path_to_string(path), + fcx.infcx().ty_to_string(expected)); + }, + 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, |
