Skip to content

Commit

Permalink
Rollup merge of rust-lang#35446 - pcn:update-E0023-to-new-format, r=j…
Browse files Browse the repository at this point in the history
…onathandturner

Update E0023 to the new format

Added some extra code to check for the appropriate ending for numbers ==
1 vs. not 1 in error messages.

Added an extra test so that the plural suffix is seen and exercised.
  • Loading branch information
Jonathan Turner authored Aug 8, 2016
2 parents dd38172 + 2c563c6 commit 7979da0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.check_pat(&subpat, field_ty);
}
} else {
span_err!(tcx.sess, pat.span, E0023,
"this pattern has {} field{s}, but the corresponding {} has {} field{s}",
subpats.len(), def.kind_name(), variant.fields.len(),
s = if variant.fields.len() == 1 {""} else {"s"});
let subpats_ending = if subpats.len() == 1 {
""
} else {
"s"
};
let fields_ending = if variant.fields.len() == 1 {
""
} else {
"s"
};
struct_span_err!(tcx.sess, pat.span, E0023,
"this pattern has {} field{}, but the corresponding {} has {} field{}",
subpats.len(), subpats_ending, def.kind_name(),
variant.fields.len(), fields_ending)
.span_label(pat.span, &format!("expected {} field{}, found {}",
variant.fields.len(), fields_ending, subpats.len()))
.emit();
on_error();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/E0023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ enum Fruit {
Pear(u32),
}


fn main() {
let x = Fruit::Apple(String::new(), String::new());
match x {
Fruit::Apple(a) => {}, //~ ERROR E0023
//~| NOTE expected 2 fields, found 1
Fruit::Apple(a, b, c) => {}, //~ ERROR E0023
//~| NOTE expected 2 fields, found 3
Fruit::Pear(1, 2) => {}, //~ ERROR E0023
//~| NOTE expected 1 field, found 2
}
}

0 comments on commit 7979da0

Please sign in to comment.