field is zero. */
while ((token = strsep (&tail, "$")) != NULL)
{
- if (sscanf (token, "%lu", &fieldno) != 1)
- {
- /* We have reached the enum name,
- which cannot start with a digit. */
- break;
- }
+ if (sscanf (token, "%lu", &fieldno) != 1)
+ {
+ /* We have reached the enum name, which cannot start
+ with a digit. */
+ break;
+ }
if (fieldno >= TYPE_NFIELDS (member_type))
- error (_("%s refers to field after end of member type"),
- RUST_ENUM_PREFIX);
+ error (_("%s refers to field after end of member type"),
+ RUST_ENUM_PREFIX);
embedded_offset += TYPE_FIELD_BITPOS (member_type, fieldno) / 8;
member_type = TYPE_FIELD_TYPE (member_type, fieldno);
if (token >= name + strlen (TYPE_FIELD_NAME (type, 0)))
error (_("Invalid form for %s"), RUST_ENUM_PREFIX);
- value = unpack_long (member_type,
- valaddr + embedded_offset);
-
-
+ value = unpack_long (member_type, valaddr + embedded_offset);
if (value == 0)
{
" * I",
"true",
"false",
- "void",
+ "()",
"[",
"]"
};
if (show <= 0
&& TYPE_NAME (type) != NULL)
{
- fputs_filtered (TYPE_NAME (type), stream);
+ /* Rust calls the unit type "void" in its debuginfo,
+ but we don't want to print it as that. */
+ if (TYPE_CODE (type) == TYPE_CODE_VOID)
+ fputs_filtered ("()", stream);
+ else
+ fputs_filtered (TYPE_NAME (type), stream);
return;
}
type = check_typedef (type);
switch (TYPE_CODE (type))
{
+ case TYPE_CODE_VOID:
+ fputs_filtered ("()", stream);
+ break;
+
case TYPE_CODE_FUNC:
/* Delegate varargs to the C printer. */
if (TYPE_VARARGS (type))
rust_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0,
flags);
}
- fputs_filtered (") -> ", stream);
- rust_print_type (TYPE_TARGET_TYPE (type), "", stream, -1, 0, flags);
+ fputs_filtered (")", stream);
+ /* If it returns unit, we can omit the return type. */
+ if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
+ {
+ fputs_filtered (" -> ", stream);
+ rust_print_type (TYPE_TARGET_TYPE (type), "", stream, -1, 0, flags);
+ }
break;
case TYPE_CODE_ARRAY:
}
fputs_filtered ("{\n", stream);
- if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX,
- strlen (RUST_ENUM_PREFIX)) == 0) {
- const char *zero_field = strrchr (TYPE_FIELD_NAME (type, 0), '$');
- if (zero_field != NULL && strlen (zero_field) > 1)
- {
- fprintfi_filtered (level + 2, stream, "%s,\n", zero_field+1);
- /* There is no explicit discriminant field, skip nothing. */
- skip_to = 0;
- }
- }
+ if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX,
+ strlen (RUST_ENUM_PREFIX)) == 0)
+ {
+ const char *zero_field = strrchr (TYPE_FIELD_NAME (type, 0), '$');
+ if (zero_field != NULL && strlen (zero_field) > 1)
+ {
+ fprintfi_filtered (level + 2, stream, "%s,\n", zero_field + 1);
+ /* There is no explicit discriminant field, skip nothing. */
+ skip_to = 0;
+ }
+ }
for (i = 0; i < TYPE_NFIELDS (type); ++i)
{