Minor cleanups in rust-lang.c

This patch is a few minor cleanups to rust-lang.c: renaming a
badly-named local variable, moving a couple of declarations into 'for'
headers, and using 'bool' in one spot.
This commit is contained in:
Tom Tromey
2024-12-20 13:36:37 -07:00
parent 9edd0af148
commit db7e13a9a2

View File

@@ -121,13 +121,11 @@ rust_tuple_type_p (struct type *type)
static bool static bool
rust_underscore_fields (struct type *type) rust_underscore_fields (struct type *type)
{ {
int i, field_number; int field_number = 0;
field_number = 0;
if (type->code () != TYPE_CODE_STRUCT) if (type->code () != TYPE_CODE_STRUCT)
return false; return false;
for (i = 0; i < type->num_fields (); ++i) for (int i = 0; i < type->num_fields (); ++i)
{ {
if (!type->field (i).is_static ()) if (!type->field (i).is_static ())
{ {
@@ -178,8 +176,6 @@ rust_slice_type_p (const struct type *type)
static bool static bool
rust_range_type_p (struct type *type) rust_range_type_p (struct type *type)
{ {
int i;
if (type->code () != TYPE_CODE_STRUCT if (type->code () != TYPE_CODE_STRUCT
|| type->num_fields () > 2 || type->num_fields () > 2
|| type->name () == NULL || type->name () == NULL
@@ -189,12 +185,12 @@ rust_range_type_p (struct type *type)
if (type->num_fields () == 0) if (type->num_fields () == 0)
return true; return true;
i = 0; int field_num = 0;
if (strcmp (type->field (0).name (), "start") == 0) if (strcmp (type->field (0).name (), "start") == 0)
{ {
if (type->num_fields () == 1) if (type->num_fields () == 1)
return true; return true;
i = 1; field_num = 1;
} }
else if (type->num_fields () == 2) else if (type->num_fields () == 2)
{ {
@@ -202,7 +198,7 @@ rust_range_type_p (struct type *type)
return false; return false;
} }
return strcmp (type->field (i).name (), "end") == 0; return strcmp (type->field (field_num).name (), "end") == 0;
} }
/* Return true if TYPE is an inclusive range type, otherwise false. /* Return true if TYPE is an inclusive range type, otherwise false.
@@ -497,7 +493,6 @@ rust_language::val_print_struct
(struct value *val, struct ui_file *stream, int recurse, (struct value *val, struct ui_file *stream, int recurse,
const struct value_print_options *options) const const struct value_print_options *options) const
{ {
int i;
int first_field; int first_field;
struct type *type = check_typedef (val->type ()); struct type *type = check_typedef (val->type ());
@@ -532,7 +527,7 @@ rust_language::val_print_struct
opts.deref_ref = false; opts.deref_ref = false;
first_field = 1; first_field = 1;
for (i = 0; i < type->num_fields (); ++i) for (int i = 0; i < type->num_fields (); ++i)
{ {
if (type->field (i).is_static ()) if (type->field (i).is_static ())
continue; continue;
@@ -1279,7 +1274,7 @@ rust_subscript (struct type *expect_type, struct expression *exp,
/* Initialized to appease the compiler. */ /* Initialized to appease the compiler. */
range_flags kind = RANGE_LOW_BOUND_DEFAULT | RANGE_HIGH_BOUND_DEFAULT; range_flags kind = RANGE_LOW_BOUND_DEFAULT | RANGE_HIGH_BOUND_DEFAULT;
LONGEST high = 0; LONGEST high = 0;
int want_slice = 0; bool want_slice = false;
rhstype = check_typedef (rhs->type ()); rhstype = check_typedef (rhs->type ());
if (rust_range_type_p (rhstype)) if (rust_range_type_p (rhstype))
@@ -1287,7 +1282,7 @@ rust_subscript (struct type *expect_type, struct expression *exp,
if (!for_addr) if (!for_addr)
error (_("Can't take slice of array without '&'")); error (_("Can't take slice of array without '&'"));
rust_compute_range (rhstype, rhs, &low, &high, &kind); rust_compute_range (rhstype, rhs, &low, &high, &kind);
want_slice = 1; want_slice = true;
} }
else else
low = value_as_long (rhs); low = value_as_long (rhs);