Rollup merge of #35446 - pcn:update-E0023-to-new-format, r=jonathandturner
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.
This commit is contained in:
commit
7979da0783
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user