Skip to content

Commit

Permalink
is_union() instead of string comparsion
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Mar 25, 2020
1 parent 02046a5 commit 58fee52
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/librustc_typeck/check/pat.rs
Expand Up @@ -1020,7 +1020,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Adt(adt, substs) => (substs, adt),
_ => span_bug!(pat.span, "struct pattern is not an ADT"),
};
let kind_name = adt.variant_descr();

// Index the struct fields' types.
let field_map = variant
Expand Down Expand Up @@ -1074,7 +1073,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if !inexistent_fields.is_empty() && !variant.recovered {
self.error_inexistent_fields(
kind_name,
adt.variant_descr(),
&inexistent_fields,
&mut unmentioned_fields,
variant,
Expand All @@ -1088,13 +1087,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pat.span,
E0638,
"`..` required with {} marked as non-exhaustive",
kind_name
adt.variant_descr()
)
.emit();
}

// Report an error if incorrect number of the fields were specified.
if kind_name == "union" {
if adt.is_union() {
if fields.len() != 1 {
tcx.sess
.struct_span_err(pat.span, "union patterns should have exactly one field")
Expand Down

0 comments on commit 58fee52

Please sign in to comment.