Skip to content

Commit 2c563c6

Browse files
committed
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.
1 parent 4c02363 commit 2c563c6

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/librustc_typeck/check/_match.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
634634
self.check_pat(&subpat, field_ty);
635635
}
636636
} else {
637-
span_err!(tcx.sess, pat.span, E0023,
638-
"this pattern has {} field{s}, but the corresponding {} has {} field{s}",
639-
subpats.len(), def.kind_name(), variant.fields.len(),
640-
s = if variant.fields.len() == 1 {""} else {"s"});
637+
let subpats_ending = if subpats.len() == 1 {
638+
""
639+
} else {
640+
"s"
641+
};
642+
let fields_ending = if variant.fields.len() == 1 {
643+
""
644+
} else {
645+
"s"
646+
};
647+
struct_span_err!(tcx.sess, pat.span, E0023,
648+
"this pattern has {} field{}, but the corresponding {} has {} field{}",
649+
subpats.len(), subpats_ending, def.kind_name(),
650+
variant.fields.len(), fields_ending)
651+
.span_label(pat.span, &format!("expected {} field{}, found {}",
652+
variant.fields.len(), fields_ending, subpats.len()))
653+
.emit();
641654
on_error();
642655
}
643656
}

src/test/compile-fail/E0023.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ enum Fruit {
1313
Pear(u32),
1414
}
1515

16+
1617
fn main() {
1718
let x = Fruit::Apple(String::new(), String::new());
1819
match x {
1920
Fruit::Apple(a) => {}, //~ ERROR E0023
21+
//~| NOTE expected 2 fields, found 1
2022
Fruit::Apple(a, b, c) => {}, //~ ERROR E0023
23+
//~| NOTE expected 2 fields, found 3
24+
Fruit::Pear(1, 2) => {}, //~ ERROR E0023
25+
//~| NOTE expected 1 field, found 2
2126
}
2227
}

0 commit comments

Comments
 (0)