From 6439f2d54645915ce57f4c229811719e8e498151 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 11 Dec 2012 13:10:30 -0800 Subject: [PATCH] Avoid extra error for type mismatches in patterns When a type error has already occurred, don't call ty::subst, which may ICE due to the mismatch in the number of type params involved. I'm deeming this too small to review. Closes #3680 --- src/librustc/middle/typeck/check/alt.rs | 11 ++++++++++- src/test/compile-fail/issue-3680.rs | 3 +-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/librustc/middle/typeck/check/alt.rs b/src/librustc/middle/typeck/check/alt.rs index 19f3fad0710..ec39c659cf5 100644 --- a/src/librustc/middle/typeck/check/alt.rs +++ b/src/librustc/middle/typeck/check/alt.rs @@ -95,7 +95,16 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, let vinfo = ty::enum_variant_with_id( tcx, v_def_ids.enm, v_def_ids.var); - vinfo.args.map(|t| { ty::subst(tcx, expected_substs, *t) }) + let var_tpt = ty::lookup_item_type(tcx, v_def_ids.var); + vinfo.args.map(|t| { + if var_tpt.bounds.len() == expected_substs.tps.len() { + ty::subst(tcx, expected_substs, *t) + } + else { + *t // In this case, an error was already signaled + // anyway + } + }) }; kind_name = "variant"; diff --git a/src/test/compile-fail/issue-3680.rs b/src/test/compile-fail/issue-3680.rs index 1f212889100..9044c6b6d79 100644 --- a/src/test/compile-fail/issue-3680.rs +++ b/src/test/compile-fail/issue-3680.rs @@ -8,8 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test -fn f() { +fn main() { match None { Err(_) => () //~ ERROR expected `core::result }