diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 35072e85db..55bdd14895 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-04-17 Tom Tromey + + * dwarf2read.c (quirk_rust_enum): Conditionally drop the + discriminant field. + 2018-04-17 Tom Tromey * dwarf2read.c (quirk_rust_enum): Handle unions correctly. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 0d3af00c46..4207e4c531 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10079,10 +10079,13 @@ quirk_rust_enum (struct type *type, struct objfile *objfile) if (iter != discriminant_map.end ()) disc->discriminants[i] = iter->second; - /* Remove the discriminant field. */ + /* Remove the discriminant field, if it exists. */ struct type *sub_type = TYPE_FIELD_TYPE (union_type, i); - --TYPE_NFIELDS (sub_type); - ++TYPE_FIELDS (sub_type); + if (TYPE_NFIELDS (sub_type) > 0) + { + --TYPE_NFIELDS (sub_type); + ++TYPE_FIELDS (sub_type); + } TYPE_FIELD_NAME (union_type, i) = variant_name; TYPE_NAME (sub_type) = rust_fully_qualify (&objfile->objfile_obstack,