Skip to content

Commit 859fd09

Browse files
committed
Add Sendable to all async return types in tests
Fixes #311.
1 parent 225380e commit 859fd09

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunner/Result.swift

+19-11
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@
66
//
77

88
func swift_func_takes_callback_with_result_arg(
9-
arg: (RustResult<CallbackTestOpaqueRustType, String>) -> ()
9+
arg: (RustResult<CallbackTestOpaqueRustType, String>) -> Void
1010
) {
11-
arg(.Ok(CallbackTestOpaqueRustType(555)))
11+
arg(.Ok(CallbackTestOpaqueRustType(555)))
1212
}
1313

1414
public class ResultTestOpaqueSwiftType {
15-
var num: UInt32
16-
17-
init(val: UInt32) {
18-
self.num = val
19-
}
20-
21-
func val() -> UInt32 {
22-
self.num
23-
}
15+
var num: UInt32
16+
17+
init(val: UInt32) {
18+
self.num = val
19+
}
20+
21+
func val() -> UInt32 {
22+
self.num
23+
}
2424
}
2525

26+
// TODO: we can delete these type assertions once we correctly generate Sendable
27+
// types. See the following issue:
28+
// https://github.com/chinedufn/swift-bridge/issues/150
29+
30+
extension AsyncRustFnReturnStruct: @unchecked Sendable {}
31+
2632
extension ResultTestOpaqueRustType: @unchecked Sendable {}
2733
extension ResultTestOpaqueRustType: Error {}
2834

@@ -41,5 +47,7 @@ extension ResultTransparentStruct: Error {}
4147
extension SameEnum: @unchecked Sendable {}
4248
extension SameEnum: Error {}
4349

50+
extension AsyncResultOkEnum: @unchecked Sendable {}
51+
4452
extension AsyncResultErrEnum: @unchecked Sendable {}
4553
extension AsyncResultErrEnum: Error {}

crates/swift-integration-tests/src/async_function.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ mod ffi {
1313
extern "Rust" {
1414
async fn rust_async_return_null();
1515
async fn rust_async_reflect_u8(arg: u8) -> u8;
16-
async fn rust_async_reflect_string(string: String) -> String;
16+
1717
async fn rust_async_return_struct() -> AsyncRustFnReturnStruct;
1818
async fn rust_async_func_reflect_result_opaque_rust(
1919
arg: Result<AsyncResultOpaqueRustType1, AsyncResultOpaqueRustType2>,
2020
) -> Result<AsyncResultOpaqueRustType1, AsyncResultOpaqueRustType2>;
2121
async fn rust_async_func_return_result_null_opaque_rust(
2222
succeed: bool,
2323
) -> Result<(), AsyncResultOpaqueRustType2>;
24+
25+
// TODO: this is broken because RustString is not Sendable.
26+
// Work around making String and other opaque types Sendable is tracked
27+
// here: https://github.com/chinedufn/swift-bridge/issues/150
28+
// async fn rust_async_reflect_string(string: String) -> String;
2429
}
2530

2631
extern "Rust" {
@@ -49,7 +54,7 @@ mod ffi {
4954

5055
enum AsyncResultOkEnum {
5156
NoFields,
52-
UnnamedFields(i32, String),
57+
UnnamedFields(i32, u32),
5358
NamedFields { value: u8 },
5459
}
5560

0 commit comments

Comments
 (0)