From 21e4c90cfa435e039261adb6d48c9fe4110f4a53 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 21 Sep 2021 15:08:47 +0200 Subject: [PATCH] Revert "client-api: Allow testing sync_events structs for exhaustiveness" This reverts commit c816630058ab625d93ebab294e9e6c02dd9d866c. Checking match exhaustiveness can now be done through the new non_exhaustive_omitted_patterns lint. --- crates/ruma-api-macros/src/api/response.rs | 14 +- crates/ruma-client-api/src/lib.rs | 11 - .../src/r0/sync/sync_events.rs | 298 ++---------------- 3 files changed, 31 insertions(+), 292 deletions(-) diff --git a/crates/ruma-api-macros/src/api/response.rs b/crates/ruma-api-macros/src/api/response.rs index b3b8ebe2..e5fb2483 100644 --- a/crates/ruma-api-macros/src/api/response.rs +++ b/crates/ruma-api-macros/src/api/response.rs @@ -32,18 +32,6 @@ impl Response { format!("Data in the response from the `{}` API endpoint.", metadata.name.value()); let struct_attributes = &self.attributes; - let has_test_exhaustive_field = self - .fields - .iter() - .filter_map(|f| f.ident.as_ref()) - .any(|ident| ident == "__test_exhaustive"); - - let non_exhaustive_attr = if has_test_exhaustive_field { - quote! {} - } else { - quote! { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] } - }; - let response_ident = Ident::new("Response", self.response_kw.span()); let fields = &self.fields; quote! { @@ -55,7 +43,7 @@ impl Response { #ruma_serde::Outgoing, #ruma_serde::_FakeDeriveSerde, )] - #non_exhaustive_attr + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(!Deserialize, #ruma_api_macros::_FakeDeriveRumaApi)] #[ruma_api(error_ty = #error_ty)] #( #struct_attributes )* diff --git a/crates/ruma-client-api/src/lib.rs b/crates/ruma-client-api/src/lib.rs index 27333727..9ea6df52 100644 --- a/crates/ruma-client-api/src/lib.rs +++ b/crates/ruma-client-api/src/lib.rs @@ -13,14 +13,3 @@ pub mod r0; pub mod unversioned; pub use error::Error; - -#[derive(Clone, Debug)] -#[doc(hidden)] -pub struct Private { - _priv: (), -} - -#[allow(dead_code)] -fn private() -> Private { - Private { _priv: () } -} diff --git a/crates/ruma-client-api/src/r0/sync/sync_events.rs b/crates/ruma-client-api/src/r0/sync/sync_events.rs index 5a24efbf..03adca0f 100644 --- a/crates/ruma-client-api/src/r0/sync/sync_events.rs +++ b/crates/ruma-client-api/src/r0/sync/sync_events.rs @@ -1,9 +1,5 @@ //! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-sync) -// FIXME: once https://github.com/rust-lang/rust/issues/84332 is resolved -// the structs can just be non_exhaustive (remove __test_exhaustive) -#![allow(clippy::exhaustive_structs)] - use std::{collections::BTreeMap, time::Duration}; use js_int::UInt; @@ -97,11 +93,6 @@ ruma_api! { /// currently held on the server for a device. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] pub device_one_time_keys_count: BTreeMap, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } error: crate::Error @@ -125,8 +116,6 @@ impl Response { to_device: Default::default(), device_lists: Default::default(), device_one_time_keys_count: BTreeMap::new(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), } } } @@ -168,7 +157,8 @@ impl<'a> From<&'a str> for Filter<'a> { } /// Updates to rooms. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Rooms { /// The rooms that the user has left or been banned from. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] @@ -187,11 +177,6 @@ pub struct Rooms { #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] pub knock: BTreeMap, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl Rooms { @@ -206,22 +191,9 @@ impl Rooms { } } -impl Default for Rooms { - fn default() -> Self { - Self { - leave: BTreeMap::new(), - join: BTreeMap::new(), - invite: BTreeMap::new(), - #[cfg(feature = "unstable-pre-spec")] - knock: BTreeMap::new(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Historical updates to left rooms. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct LeftRoom { /// The timeline of messages and state changes in the room up to the point when the user /// left. @@ -235,11 +207,6 @@ pub struct LeftRoom { /// The private data that this user has attached to this room. #[serde(default, skip_serializing_if = "RoomAccountData::is_empty")] pub account_data: RoomAccountData, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl LeftRoom { @@ -254,20 +221,9 @@ impl LeftRoom { } } -impl Default for LeftRoom { - fn default() -> Self { - Self { - timeline: Default::default(), - state: Default::default(), - account_data: Default::default(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Updates to joined rooms. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct JoinedRoom { /// Information about the room which clients may need to correctly render it /// to users. @@ -296,11 +252,6 @@ pub struct JoinedRoom { /// room. e.g. typing. #[serde(default, skip_serializing_if = "Ephemeral::is_empty")] pub ephemeral: Ephemeral, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl JoinedRoom { @@ -320,21 +271,6 @@ impl JoinedRoom { } } -impl Default for JoinedRoom { - fn default() -> Self { - Self { - summary: Default::default(), - unread_notifications: Default::default(), - timeline: Default::default(), - state: Default::default(), - account_data: Default::default(), - ephemeral: Default::default(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Updates to knocked rooms. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg(feature = "unstable-pre-spec")] @@ -356,7 +292,8 @@ pub struct KnockState { } /// Unread notifications count. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct UnreadNotificationsCount { /// The number of unread notifications for this room with the highlight flag set. #[serde(skip_serializing_if = "Option::is_none")] @@ -365,11 +302,6 @@ pub struct UnreadNotificationsCount { /// The total number of unread notifications for this room. #[serde(skip_serializing_if = "Option::is_none")] pub notification_count: Option, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl UnreadNotificationsCount { @@ -384,19 +316,9 @@ impl UnreadNotificationsCount { } } -impl Default for UnreadNotificationsCount { - fn default() -> Self { - Self { - highlight_count: None, - notification_count: None, - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Events in the room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Timeline { /// True if the number of events returned was limited by the `limit` on the filter. /// @@ -412,11 +334,6 @@ pub struct Timeline { /// A list of events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events: Vec>, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl Timeline { @@ -431,29 +348,13 @@ impl Timeline { } } -impl Default for Timeline { - fn default() -> Self { - Self { - limited: false, - prev_batch: None, - events: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// State events in the room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct State { /// A list of state events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events: Vec>, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl State { @@ -468,27 +369,13 @@ impl State { } } -impl Default for State { - fn default() -> Self { - Self { - events: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// The global private data created by this user. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct GlobalAccountData { /// A list of events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events: Vec>, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl GlobalAccountData { @@ -503,27 +390,13 @@ impl GlobalAccountData { } } -impl Default for GlobalAccountData { - fn default() -> Self { - Self { - events: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// The private data that this user has attached to this room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct RoomAccountData { /// A list of events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events: Vec>, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl RoomAccountData { @@ -538,27 +411,13 @@ impl RoomAccountData { } } -impl Default for RoomAccountData { - fn default() -> Self { - Self { - events: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Ephemeral events not recorded in the timeline or state of the room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Ephemeral { /// A list of events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events: Vec>, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl Ephemeral { @@ -573,18 +432,9 @@ impl Ephemeral { } } -impl Default for Ephemeral { - fn default() -> Self { - Self { - events: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Information about room for rendering to clients. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct RoomSummary { /// Users which can be used to generate a room name if the room does not have /// one. Required if room name or canonical aliases are not set or empty. @@ -602,11 +452,6 @@ pub struct RoomSummary { /// omitted. #[serde(rename = "m.invited_member_count", skip_serializing_if = "Option::is_none")] pub invited_member_count: Option, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl RoomSummary { @@ -623,29 +468,13 @@ impl RoomSummary { } } -impl Default for RoomSummary { - fn default() -> Self { - Self { - heroes: vec![], - joined_member_count: None, - invited_member_count: None, - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Updates to the rooms that the user has been invited to. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct InvitedRoom { /// The state of a room that the user has been invited to. #[serde(default, skip_serializing_if = "InviteState::is_empty")] pub invite_state: InviteState, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl InvitedRoom { @@ -660,27 +489,13 @@ impl InvitedRoom { } } -impl Default for InvitedRoom { - fn default() -> Self { - Self { - invite_state: Default::default(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// The state of a room that the user has been invited to. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct InviteState { /// A list of state events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events: Vec>, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl InviteState { @@ -695,27 +510,13 @@ impl InviteState { } } -impl Default for InviteState { - fn default() -> Self { - Self { - events: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Updates to the presence status of other users. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Presence { /// A list of events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events: Vec>, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl Presence { @@ -730,27 +531,13 @@ impl Presence { } } -impl Default for Presence { - fn default() -> Self { - Self { - events: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Messages sent dirrectly between devices. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct ToDevice { /// A list of to-device events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events: Vec>, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl ToDevice { @@ -765,18 +552,9 @@ impl ToDevice { } } -impl Default for ToDevice { - fn default() -> Self { - Self { - events: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - /// Information on E2E device udpates. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct DeviceLists { /// List of users who have updated their device identity keys or who now /// share an encrypted room with the client since the previous sync @@ -787,11 +565,6 @@ pub struct DeviceLists { /// response. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub left: Vec, - - #[cfg(not(feature = "unstable-exhaustive-types"))] - #[doc(hidden)] - #[serde(skip, default = "crate::private")] - pub __test_exhaustive: crate::Private, } impl DeviceLists { @@ -806,17 +579,6 @@ impl DeviceLists { } } -impl Default for DeviceLists { - fn default() -> Self { - Self { - changed: vec![], - left: vec![], - #[cfg(not(feature = "unstable-exhaustive-types"))] - __test_exhaustive: crate::private(), - } - } -} - #[cfg(test)] mod tests { use assign::assign;