From da7f41104dda48ac3a03cfa039cb3e9570f91a35 Mon Sep 17 00:00:00 2001 From: Dmitry Ermolov Date: Mon, 7 Oct 2013 10:23:22 +0400 Subject: [PATCH] Fix bug in match checking When `specialize`ing struct-like enum patterns, compare struct fields to pattern fields, not pattern fields to pattern fields. Closes #8351. --- src/librustc/middle/check_match.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index e8282368c89..663108ee9b8 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -662,15 +662,14 @@ fn specialize(cx: &MatchCheckCtxt, _ => None } } - PatStruct(_, ref flds, _) => { + PatStruct(_, ref pattern_fields, _) => { // Is this a struct or an enum variant? match cx.tcx.def_map.get_copy(&pat_id) { DefVariant(_, variant_id, _) => { if variant(variant_id) == *ctor_id { - // FIXME #4731: Is this right? --pcw - let args = flds.map(|ty_field| { - match flds.iter().find(|f| - f.ident == ty_field.ident) { + let struct_fields = ty::lookup_struct_fields(cx.tcx, variant_id); + let args = struct_fields.map(|sf| { + match pattern_fields.iter().find(|f| f.ident.name == sf.name) { Some(f) => f.pat, _ => wild() } @@ -700,7 +699,7 @@ fn specialize(cx: &MatchCheckCtxt, } } let args = class_fields.iter().map(|class_field| { - match flds.iter().find(|f| + match pattern_fields.iter().find(|f| f.ident.name == class_field.name) { Some(f) => f.pat, _ => wild()