]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ffi-polonius: Remove usage of extern types.
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 26 Jul 2024 09:04:46 +0000 (11:04 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:01 +0000 (15:32 +0100)
This will allow us to revert our dependency on extern types, which would
help our godbolt build as well as our various builders.

gcc/rust/ChangeLog:

* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs: Remove extern
type feature.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Define FFIVector
per the nomicon's recommendation
https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs

gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs

index 0cb85078158c386e493ee022eae89e4b61233f6e..7377e3aaf85e76ee832137ef32826ce72236d322 100644 (file)
 // ```
 include!("gccrs_ffi_generated.rs");
 
+use std::marker::{PhantomData, PhantomPinned};
+
 use crate::GccrsAtom;
 
-// Using opqaue types
-extern "C" {
-    pub type FFIVector;
+// We define an opaque C type per the nomicon's recommendation:
+// https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
+#[repr(C)]
+pub struct FFIVector {
+    _empty: [u8; 0],
+    marker: PhantomData<(*mut u8, PhantomPinned)>,
 }
 
 impl<T1, T2> Into<(GccrsAtom, GccrsAtom)> for Pair<T1, T2>
index 782a63f8078733be45009c64493d145a27a9bb38..c5c0ae9756e57b67ff7f6c4ba591335b7632a6b8 100644 (file)
@@ -16,8 +16,6 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-#![feature(extern_types)]
-
 mod gccrs_ffi;
 
 use gccrs_ffi::FFIVector;