-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ffi struct produces warnings on Rust 1.79.0 or +nightly #270
Comments
Thanks for reporting this. Looks like a similar to issue was opened for Mind sharing a simple bridge module that reproduces this warning? I cannot reproduce this warning using the provided example. |
Also on nightly some of the Output
|
@chinedufn Took a bit longer than expected, but here's a gist you can clone and see the issue: |
This error occurs on Rust 1.79.0, which was just released yesterday. |
Ok, I just verified that this problem happens when bridging a function or method returning a I take advantage of the |
…pe>` (#278) In Rust 1.79.0, dead code warnings are emitted from enums where the compiler does not infer that wrapped data is used, even when the enum has been annotated with `#[repr(C]`. This warning triggers in `swift-bridge` when defining transparent structs or enums that will be returned in error results. This appears to be a regression in the `dead_code` rustc lint. Pending upstream fixes to rustc, this change to `swift-bridge` annotates generated result enums with `#[allow(unused)]`. Fixes #270 ``` error: field `0` is never read | 1 | #[swift_bridge::bridge] | ----------------------- field in this variant ... 3 | enum ResultTransparentEnum { | ^^^^^^^^^^^^^^^^^^^^^ | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 3 | enum () { | ~~ ``` ## Example bridge The following bridge code is the minimal reproduction case: ``` rust #[swift_bridge::bridge] mod ffi { #[swift_bridge(swift_repr = "struct")] struct TransparentErrorStruct(pub String); extern "Rust" { fn rust_func_returns_result_transparent_struct( succeed: bool ) -> Result<(), TransparentErrorStruct>; } } fn rust_func_returns_result_transparent_struct( succeed: bool ) -> Result<(), ffi::ResultTestTransparentStruct> { if succeed { Ok(()) } else { Err(ffi::ResultTestTransparentStruct("failed".to_string())) } } impl std::error::Error for ffi:: TransparentErrorStruct {} impl std::fmt::Debug for ffi:: TransparentErrorStruct { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self) } } impl std::fmt::Display for ffi:: TransparentErrorStruct { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } ```
I have a struct that I use to convert wrapped errors to strings that can be sent to Swift:
This compiles without any errors in Rust 1.77.2, but when I compile it with nightly it produces the following warning:
I'm starting to play around with cross-compiling to watchOS, tvOS, and eventually visionOS, but am finding these targets only seem to build on nightly.
The text was updated successfully, but these errors were encountered: