You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppress dead_code warning when returning -> Result<*, TransparentType> (#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)
}
}
```
try { let val = __swift_bridge__$some_function(); switch val.tag { case __swift_bridge__$ResultVoidAndSomeErrStruct$ResultOk: return case __swift_bridge__$ResultVoidAndSomeErrStruct$ResultErr: throw val.payload.err.intoSwiftRepr() default: fatalError() } }()
0 commit comments