Skip to content

Commit 5052911

Browse files
Stop using string equality to check if ADT is a union
1 parent d9ddaf0 commit 5052911

File tree

1 file changed

+11
-6
lines changed
  • compiler/rustc_typeck/src/check

1 file changed

+11
-6
lines changed

compiler/rustc_typeck/src/check/expr.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1479,10 +1479,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14791479
// re-link the regions that EIfEO can erase.
14801480
self.demand_eqtype(span, adt_ty_hint, adt_ty);
14811481

1482-
let (substs, adt_kind, kind_name) = match adt_ty.kind() {
1483-
ty::Adt(adt, substs) => (substs, adt.adt_kind(), adt.variant_descr()),
1484-
_ => span_bug!(span, "non-ADT passed to check_expr_struct_fields"),
1482+
let ty::Adt(adt, substs) = adt_ty.kind() else {
1483+
span_bug!(span, "non-ADT passed to check_expr_struct_fields");
14851484
};
1485+
let adt_kind = adt.adt_kind();
14861486

14871487
let mut remaining_fields = variant
14881488
.fields
@@ -1520,7 +1520,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15201520
});
15211521
} else {
15221522
self.report_unknown_field(
1523-
adt_ty, variant, field, ast_fields, kind_name, expr_span,
1523+
adt_ty,
1524+
variant,
1525+
field,
1526+
ast_fields,
1527+
adt.variant_descr(),
1528+
expr_span,
15241529
);
15251530
}
15261531

@@ -1533,7 +1538,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15331538
}
15341539

15351540
// Make sure the programmer specified correct number of fields.
1536-
if kind_name == "union" {
1541+
if adt_kind == AdtKind::Union {
15371542
if ast_fields.len() != 1 {
15381543
struct_span_err!(
15391544
tcx.sess,
@@ -1666,7 +1671,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16661671
}
16671672
};
16681673
self.typeck_results.borrow_mut().fru_field_types_mut().insert(expr_id, fru_tys);
1669-
} else if kind_name != "union" && !remaining_fields.is_empty() {
1674+
} else if adt_kind != AdtKind::Union && !remaining_fields.is_empty() {
16701675
let inaccessible_remaining_fields = remaining_fields.iter().any(|(_, (_, field))| {
16711676
!field.vis.is_accessible_from(tcx.parent_module(expr_id).to_def_id(), tcx)
16721677
});

0 commit comments

Comments
 (0)