-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress dead_code warning when returning `-> Result<*, TransparentTy…
…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) } } ```
- Loading branch information
Showing
5 changed files
with
178 additions
and
4 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