Skip to content

Commit

Permalink
sdk-common: hack to avoid over-recursion when evaluating Send/Sync bo…
Browse files Browse the repository at this point in the history
…unds in rustc

See
#3749 (comment)
for the gory details.
  • Loading branch information
bnjbvr committed Aug 27, 2024
1 parent 4289d0d commit 3fc561d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/matrix-sdk-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
js = ["wasm-bindgen-futures"]
uniffi = ["dep:uniffi"]

# Used internally to make sure that some types are actually really send and sync.
# See also https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823.
test-send-sync = []

[dependencies]
async-trait = { workspace = true }
futures-core = { workspace = true }
Expand Down
17 changes: 17 additions & 0 deletions crates/matrix-sdk-common/src/deserialized_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,23 @@ pub struct SyncTimelineEvent {
pub unsigned_encryption_info: Option<BTreeMap<UnsignedEventLocation, UnsignedDecryptionResult>>,
}

/// See https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823.
#[cfg(not(feature = "test-send-sync"))]
unsafe impl Send for SyncTimelineEvent {}

/// See https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823.
#[cfg(not(feature = "test-send-sync"))]
unsafe impl Sync for SyncTimelineEvent {}

#[cfg(feature = "test-send-sync")]
#[test]
/// See https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823.
fn test_send_sync_for_sync_timeline_event() {
fn assert_send_sync<T: Send + Sync>() {}

assert_send_sync::<SyncTimelineEvent>();
}

impl SyncTimelineEvent {
/// Create a new `SyncTimelineEvent` from the given raw event.
///
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ fn run_wasm_checks(cmd: Option<WasmFeatureSet>) -> Result<()> {
"-p matrix-sdk --no-default-features --features js,rustls-tls",
),
(WasmFeatureSet::MatrixSdkBase, "-p matrix-sdk-base --features js"),
(WasmFeatureSet::MatrixSdkCommon, "-p matrix-sdk-common --features js"),
(WasmFeatureSet::MatrixSdkCommon, "-p matrix-sdk-common --features js,test-send-sync"),
(
WasmFeatureSet::MatrixSdkIndexeddbStoresNoCrypto,
"-p matrix-sdk --no-default-features --features js,indexeddb,rustls-tls",
Expand Down

0 comments on commit 3fc561d

Please sign in to comment.