-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes an `improper_ctypes` warning when bridging transparent structs that contain non FFI safe types. While transparent structs that contained non FFI safe types were being passed in an FFI safe way before this commit, the Rust compiler could not know that what we were doing was FFI safe. This commit uses `#[allow(improper_ctypes)]` to silence the lint. ## Illustration Before this commit the following bridge module: ```rust #[swift_bridge::bridge] mod ffi { struct SharedStruct { field: String } extern "Swift" { fn swift_func() -> SharedStruct; } } ``` would lead to the following warning: ```console warning: `extern` block uses type `RustString`, which is not FFI-safe --> my_file.rs:4:12 | 4 | struct SharedStruct { | ^^^^^^^^^^^^ not FFI-safe | = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout = note: `#[warn(improper_ctypes)]` on by default ``` This warning was a bit misleading since the generated code has its `Span` set to the `SharedStruct`'s span. The real issue was that the generated FFI representation type: ```rust #[repr(C)] struct __swift_bridge__SharedStruct { field: *mut std::string::RustString } ``` was triggering a warning because the Rust compiler can't know that the non-FFI safe `std::string::RustString` is not being dereferenced on the Swift side.
- Loading branch information
Showing
9 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
crates/swift-integration-tests/src/expose_opaque_rust_type.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters