From 58fee523cfe1e242cbf8776bb8513fb8325bc0ab Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 25 Mar 2020 06:57:00 +0100 Subject: [PATCH] is_union() instead of string comparsion --- src/librustc_typeck/check/pat.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 0d38fa98bd7f..d3b1ea8778d6 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -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 @@ -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, @@ -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")