From: Arthur Cohen Date: Fri, 26 Jul 2024 09:04:46 +0000 (+0200) Subject: ffi-polonius: Remove usage of extern types. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9de294a6848ede43833b9e225e3df56b4b3e5194;p=thirdparty%2Fgcc.git ffi-polonius: Remove usage of extern types. 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 --- diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs index 5740271de622..7e839f035819 100644 --- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs +++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs @@ -30,11 +30,16 @@ // ``` 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 Into<(GccrsAtom, GccrsAtom)> for Pair diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs index 1bcb89c326b1..e254238bc4c5 100644 --- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs +++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs @@ -16,8 +16,6 @@ // along with GCC; see the file COPYING3. If not see // . -#![feature(extern_types)] - mod gccrs_ffi; use gccrs_ffi::FFIVector;