Skip to content

Commit 54b7c7d

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#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.
2 parents ce81500 + 2c563c6 commit 54b7c7d

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
@@ -633,10 +633,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
633633
self.check_pat(&subpat, field_ty);
634634
}
635635
} else {
636-
span_err!(tcx.sess, pat.span, E0023,
637-
"this pattern has {} field{s}, but the corresponding {} has {} field{s}",
638-
subpats.len(), def.kind_name(), variant.fields.len(),
639-
s = if variant.fields.len() == 1 {""} else {"s"});
636+
let subpats_ending = if subpats.len() == 1 {
637+
""
638+
} else {
639+
"s"
640+
};
641+
let fields_ending = if variant.fields.len() == 1 {
642+
""
643+
} else {
644+
"s"
645+
};
646+
struct_span_err!(tcx.sess, pat.span, E0023,
647+
"this pattern has {} field{}, but the corresponding {} has {} field{}",
648+
subpats.len(), subpats_ending, def.kind_name(),
649+
variant.fields.len(), fields_ending)
650+
.span_label(pat.span, &format!("expected {} field{}, found {}",
651+
variant.fields.len(), fields_ending, subpats.len()))
652+
.emit();
640653
on_error();
641654
}
642655
}

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)