https://gcc.gnu.org/g:40e543b940e012b43217b6776c166f4970aa75c8
commit r17-4347-g40e543b940e012b43217b6776c166f4970aa75c8 Author: Arthur Cohen <[email protected]> Date: Wed Sep 2 17:47:21 2026 +0200 gccrs: codegen: Compile extern types as C void 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. Diff: --- 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 56f9e9424342..4b39a44f11cf 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 ()) {
