[gccrs COMMIT] codegen: Compile extern types as C void

gerris.rs@gmail.com gerris.rs@gmail.com
Thu Sep 10 14:34:42 GMT 2026


From: Arthur Cohen <arthur.cohen@opensrcsec.com>

Per Rust's RFC 1861 (https://rust-lang.github.io/rfcs/1861-extern-types.html), extern types
are FFI-safe types that are dynamically sized, and should thus compile down to regular empty
types like C's void type. They are to always be used with an indirection, which means they are
effectively always a regular pointer (not a pointer + metadata like a lot of pointers in Rust) to
C's void type.

Closes Rust-GCC/gccrs#1922. We eventually need to work on adding checks to external types, but as
they are currently implemented as types not implementing `Sized`, a lot of their typechecking
behavior is covered.

gcc/rust/ChangeLog:

	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Change extern type codegen from
	empty struct to the void type node.
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: https://github.com/Rust-GCC/gccrs/commit/930d05a0ec0e0b566bfabf7e931d7e4cff402158

The commit has been mentioned in the following issue(s):
 - Rust-GCC/gccrs#1922: https://github.com/Rust-GCC/gccrs/issues/1922

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4834

 gcc/rust/backend/rust-compile-type.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index 56f9e9424..4b39a44f1 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -344,7 +344,10 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
     }
   else if (type.get_adt_kind () == TyTy::ADTType::ADTKind::EXTERN)
     {
-      type_record = Backend::struct_type ({});
+      // Extern types are codegen'd as C's void type. They can only be used
+      // through indirection, so they're effectively always codegen'd as
+      // `void *` types.
+      type_record = void_type_node;
     }
   else if (!type.is_enum ())
     {

base-commit: 112b46e3f8e3b81f28e90a7c8ebd1789592d31cb
-- 
2.55.0



More information about the Gcc-rust mailing list