This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Print void types correctly in Rust


>>>>> "Manish" == Manish Goregaokar <manish@mozilla.com> writes:

Manish> Rust prefers to not specify the return type of a function when it is unit
Manish> (`()`). The type is also referred to as "void" in debuginfo but not in actual
Manish> usage, so we should never be printing "void" when the language is Rust.

Thanks for finding and fixing this.

The patch looks good overall but I have a few questions and some nits.

Manish>     * rust-lang.c: Print unit types as "()"
Manish>     * rust-lang.c: Omit return type for functions returning unit

A ChangeLog entry is supposed to refer to function and variable names,
so more like:

	* rust-lang.c (rust_decorations): Spell "void" as "()".
	(rust_print_type): Likewise.
	...

Manish> +      /* Rust calls the unit type "void" in its debuginfo,
Manish> +         but we don't want to print it as that.  */
Manish> +      if (TYPE_CODE (type) == TYPE_CODE_VOID)
Manish> +        fputs_filtered ("()", stream);
Manish> +      else
Manish> +        fputs_filtered (TYPE_NAME (type), stream);

This is fine but there is another case in rust_val_print:

    case TYPE_CODE_INT:
      /* Recognize the unit type.  */
      if (TYPE_UNSIGNED (type) && TYPE_LENGTH (type) == 0
	  && TYPE_NAME (type) != NULL && strcmp (TYPE_NAME (type), "()") == 0)
	{
	  fputs_filtered ("()", stream);
	  break;
	}
      goto generic_print;


... I wonder if that is something that changed after 1.8, or if it's the
case that the unit type can be represented in multiple ways.  (Or maybe
this only handles the unit type constructed by rust_language_arch_info?)

Anyway I wonder if a case like this is needed in rust_print_type, or if
the one in rust_val_print can be removed or changed.

Manish> +      if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
Manish> +      {
Manish> +        fputs_filtered (" -> ", stream);
Manish> +        rust_print_type (TYPE_TARGET_TYPE (type), "", stream, -1, 0, flags);

This should be formatted like:

+      if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
+        {
+          fputs_filtered (" -> ", stream);
+          rust_print_type (TYPE_TARGET_TYPE (type), "", stream, -1, 0, flags);

Manish> +// Empty function, should not have "void"
Manish> +// or "()" in its return type
Manish> +fn empty() {

I'm curious what happens if it does say "-> ()"?

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]