-
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
Swift warning when returning -> Result<*, *>
from a Rust method
#295
Comments
Thanks for the report. Please provide the following (can just edit your issue body):
I'm noticing that none of our tests test returning a swift-bridge/crates/swift-bridge-ir/src/codegen/codegen_tests/result_codegen_tests.rs Lines 1 to 783 in 34ce1ff
swift-bridge/crates/swift-integration-tests/src/result.rs Lines 1 to 273 in 1b547a5
|
There is an incomplete pull request that implements |
COMMENT EDITED BY chinedufn TO REMOVE MOST OF THE IRRELEVANT CODE I've used this code:
The generated code is the following:
|
afaik the codegen must just replace the
-->
|
-> Result<*, *>
from a Rust method
GuideFail tests on warningsMake the swift-bridge/test-swift-rust-integration.sh Lines 24 to 27 in 53b93f4
Not sure if Add integration testAdd an integration test that calls a Rust method that returns a Result: swift-bridge/crates/swift-integration-tests/src/result.rs Lines 1 to 273 in 1b547a5
swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/ResultTests.swift Lines 1 to 275 in 1b547a5
Add codegen testAdd a codegen test where we return a swift-bridge/crates/swift-bridge-ir/src/codegen/codegen_tests/result_codegen_tests.rs Lines 1 to 783 in 34ce1ff
|
@tmolitor-stud-tu can you update your issue body with the warning that you are seeing? This way anyone that works on this issue knows exactly what to look for. |
If you tell me where the code resides that generates the snippet with the missing |
I'm running into the same errors myself — and they're errors, not warnings. My package.swift targets swift 5.9 because I need to target visionOS and iOS 17 minimums.
|
You can remove the Other than that that branch looks great. Thanks. |
done! #296 |
how can we address the implicit self errors? i'd like to be able to reproduce them with your testing harness(es) |
I wrote a guide on addressing the implicit self errors here -> #295 (comment) If you have any questions please feel free to ask. Happy to answer. |
Support Rust returning `-> Result<_, String>`, e.g.: ```rust #[swift_bridge::bridge] mod ffi { extern "Rust" { fn do_fallible_work() -> Result<(), String>; } } ``` --- Incorporate the changes from #282 to implement swift's `Error` protocol for ruststring, & extend them with the tests requested in #295 (comment)
@chinedufn Thanks! re: upgrading warnings to errors — it seems that may not be fine-grained enough: As you suspected, there was no apparent # ./test-swift-rust-integration
Testing failed:
Declaration of 'struct __swift_bridge__$ResultAsyncResultOkEnumAndAsyncResultErrEnum' will not be visible outside of this function
Declaration of 'struct __swift_bridge__$ResultAsyncResultOpaqueRustType1AndAsyncResultErrEnum' will not be visible outside of this function
Declaration of 'struct __swift_bridge__$ResultAsyncResultOkEnumAndAsyncResultOpaqueRustType1' will not be visible outside of this function
Declaration of 'struct __swift_bridge__$ResultVoidAndAsyncResultErrEnum' will not be visible outside of this function
Failed to import bridging header '/Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/Headers/BridgingHeader.h'
Command SwiftCompile failed with a nonzero exit code
Testing cancelled because the build failed.
** TEST FAILED **
The following build commands failed:
SwiftEmitModule normal arm64 Emitting\ module\ for\ SwiftRustIntegrationTestRunnerTests (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/SingleRepresentationTypeElisionTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/RustFnUsesOpaqueSwiftTypeTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/PrimitiveTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 Compiling\ OpaqueSwiftStructTests.swift,\ SwiftFnUsesOpaqueRustTypeTests.swift /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/OpaqueSwiftStructTests.swift /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/SwiftFnUsesOpaqueRustTypeTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/OpaqueSwiftStructTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/SwiftFnUsesOpaqueRustTypeTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/CallbackTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/SharedEnumAttributeTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
SwiftCompile normal arm64 Compiling\ OptionTests.swift,\ SharedStructAttributeTests.swift,\ StringTests.swift /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/OptionTests.swift /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/SharedStructAttributeTests.swift /Users/tito/code/swift-bridge/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/StringTests.swift (in target 'SwiftRustIntegrationTestRunnerTests' from project 'SwiftRustIntegrationTestRunner')
(10 failures) Aside from upgrading all warnings to errors, do you have any other ideas for reproducing this? |
Reading thru the latest CI run logs, it would seem there are some material warnings being surfaced during tests — tho none of these match the error I am seeing:
&
|
When I apply these changes locally, my project compiles successfully and I can use my rust <> swift bridge without further modfication! |
Thanks for investigating this and finding the basis of a solution.
|
When returning a
Result
from a Rust struct method, the generated swift code will accessptr
in a closure and thus implicitly captureself
which creates either a compiler warning, or in stricter environments (like ours) a compiler error.Furthermore the swift compiler complains that the error returned does not conform to
Error
. MaybeRustString
and other builtin types should automatically conform toError
.The text was updated successfully, but these errors were encountered: