- {
- int j, nfields, first_field, is_tuple, start;
- struct type *variant_type;
- struct disr_info disr;
- struct value_print_options opts;
-
- /* Untagged unions are printed as if they are structs.
- Since the field bit positions overlap in the debuginfo,
- the code for printing a union is same as that for a struct,
- the only difference is that the input type will have overlapping
- fields. */
- if (rust_union_is_untagged (type))
- {
- val_print_struct (type, embedded_offset, address, stream,
- recurse, val, options);
- break;
- }
-
- opts = *options;
- opts.deref_ref = 0;
-
- disr = rust_get_disr_info (type, valaddr, embedded_offset, address,
- val);
-
- if (disr.is_encoded && disr.field_no == RUST_ENCODED_ENUM_HIDDEN)
- {
- fprintf_filtered (stream, "%s", disr.name.c_str ());
- break;
- }
-
- first_field = 1;
- variant_type = TYPE_FIELD_TYPE (type, disr.field_no);
- nfields = TYPE_NFIELDS (variant_type);
-
- is_tuple = (disr.is_encoded
- ? rust_tuple_struct_type_p (variant_type)
- : rust_tuple_variant_type_p (variant_type));
- start = disr.is_encoded ? 0 : 1;
-
- if (nfields > start)
- {
- /* In case of a non-nullary variant, we output 'Foo(x,y,z)'. */
- if (is_tuple)
- fprintf_filtered (stream, "%s(", disr.name.c_str ());
- else
- {
- /* struct variant. */
- fprintf_filtered (stream, "%s{", disr.name.c_str ());
- }
- }
- else
- {
- /* In case of a nullary variant like 'None', just output
- the name. */
- fprintf_filtered (stream, "%s", disr.name.c_str ());
- break;
- }
-
- for (j = start; j < TYPE_NFIELDS (variant_type); j++)
- {
- if (!first_field)
- fputs_filtered (", ", stream);
- first_field = 0;
-
- if (!is_tuple)
- fprintf_filtered (stream, "%s: ",
- TYPE_FIELD_NAME (variant_type, j));
-
- val_print (TYPE_FIELD_TYPE (variant_type, j),
- (embedded_offset
- + TYPE_FIELD_BITPOS (type, disr.field_no) / 8
- + TYPE_FIELD_BITPOS (variant_type, j) / 8),
- address,
- stream, recurse + 1, val, &opts,
- current_language);
- }
-
- if (is_tuple)
- fputs_filtered (")", stream);
- else
- fputs_filtered ("}", stream);
- }
+ /* Untagged unions are printed as if they are structs. Since
+ the field bit positions overlap in the debuginfo, the code
+ for printing a union is same as that for a struct, the only
+ difference is that the input type will have overlapping
+ fields. */
+ val_print_struct (type, embedded_offset, address, stream,
+ recurse, val, options);