Skip to content

Commit

Permalink
Fix bug in match checking
Browse files Browse the repository at this point in the history
When `specialize`ing struct-like enum patterns, compare struct fields to
pattern fields, not pattern fields to pattern fields.

Closes #8351.
  • Loading branch information
dim-an committed Oct 7, 2013
1 parent 822699e commit da7f411
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/librustc/middle/check_match.rs
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
Expand Down

5 comments on commit da7f411

@bors
Copy link
Contributor

@bors bors commented on da7f411 Oct 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on da7f411 Oct 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging dim-an/rust/fix-match = da7f411 into auto

@bors
Copy link
Contributor

@bors bors commented on da7f411 Oct 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dim-an/rust/fix-match = da7f411 merged ok, testing candidate = 1320999

@bors
Copy link
Contributor

@bors bors commented on da7f411 Oct 8, 2013

@bors
Copy link
Contributor

@bors bors commented on da7f411 Oct 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 1320999

Please sign in to comment.