From de23971ee468be6de0cfd376d7ae5b46d78c22b6 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 19 Jul 2019 15:47:14 -0700 Subject: [PATCH] Deny and address all warnings. --- src/collections/all.rs | 10 ++++++---- src/collections/only.rs | 5 +++-- src/key/verification/start.rs | 10 ++++------ src/lib.rs | 2 +- src/push_rules.rs | 10 ++++------ src/room/canonical_alias.rs | 6 ++---- src/room/encrypted.rs | 4 ++-- src/room/member.rs | 1 - src/room/message.rs | 4 ++-- src/room/message/feedback.rs | 1 - src/room/power_levels.rs | 4 +--- src/stripped.rs | 4 ++-- 12 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/collections/all.rs b/src/collections/all.rs index 60e3fc25..c26d3e06 100644 --- a/src/collections/all.rs +++ b/src/collections/all.rs @@ -1,7 +1,10 @@ //! Enums for heterogeneous collections of events, inclusive for every event type that implements //! the trait of the same name. -use std::{convert::TryFrom, str::FromStr}; +use std::str::FromStr; + +use serde::{Serialize, Serializer}; +use serde_json::{from_value, Value}; use crate::{ call::{ @@ -48,9 +51,6 @@ use crate::{ CustomEvent, CustomRoomEvent, CustomStateEvent, EventType, InnerInvalidEvent, InvalidEvent, }; -use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; -use serde_json::{from_value, Value}; - /// A basic event, room event, or state event. #[derive(Clone, Debug)] #[allow(clippy::large_enum_variant)] @@ -396,6 +396,7 @@ impl FromStr for Event { type Err = InvalidEvent; /// Attempt to create `Self` from parsing a string of JSON data. + #[allow(clippy::cognitive_complexity)] fn from_str(json: &str) -> Result { let value: Value = serde_json::from_str(json)?; @@ -799,6 +800,7 @@ impl FromStr for RoomEvent { type Err = InvalidEvent; /// Attempt to create `Self` from parsing a string of JSON data. + #[allow(clippy::cognitive_complexity)] fn from_str(json: &str) -> Result { let value: Value = serde_json::from_str(json)?; diff --git a/src/collections/only.rs b/src/collections/only.rs index 089a8dfc..b9a39355 100644 --- a/src/collections/only.rs +++ b/src/collections/only.rs @@ -1,9 +1,9 @@ //! Enums for heterogeneous collections of events, exclusive to event types that implement "at //! most" the trait of the same name. -use std::{convert::TryFrom, str::FromStr}; +use std::str::FromStr; -use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; +use serde::{Serialize, Serializer}; use serde_json::{from_value, Value}; pub use super::all::StateEvent; @@ -38,6 +38,7 @@ use crate::{ /// A basic event. #[derive(Clone, Debug)] +#[allow(clippy::large_enum_variant)] pub enum Event { /// m.direct Direct(DirectEvent), diff --git a/src/key/verification/start.rs b/src/key/verification/start.rs index eba24638..505cff8a 100644 --- a/src/key/verification/start.rs +++ b/src/key/verification/start.rs @@ -2,8 +2,7 @@ use std::{convert::TryFrom, str::FromStr}; -use js_int::UInt; -use ruma_identifiers::{DeviceId, EventId, RoomId, UserId}; +use ruma_identifiers::DeviceId; use serde::{de::Error, ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; @@ -11,7 +10,7 @@ use super::{ HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString, VerificationMethod, }; -use crate::{Algorithm, Event, EventType, InnerInvalidEvent, InvalidEvent, InvalidInput}; +use crate::{Event, EventType, InnerInvalidEvent, InvalidEvent, InvalidInput}; /// Begins an SAS key verification process. /// @@ -61,7 +60,7 @@ impl FromStr for StartEvent { } }; - Ok(Self { content: content }) + Ok(Self { content }) } } @@ -388,12 +387,11 @@ impl Serialize for MSasV1Content { #[cfg(test)] mod tests { - use serde_json::{from_str, to_string}; + use serde_json::to_string; use super::{ HashAlgorithm, KeyAgreementProtocol, MSasV1Content, MSasV1ContentOptions, MessageAuthenticationCode, ShortAuthenticationString, StartEvent, StartEventContent, - VerificationMethod, }; #[test] diff --git a/src/lib.rs b/src/lib.rs index 073fb5a3..287b9390 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,7 +97,7 @@ #![deny(missing_debug_implementations)] #![deny(missing_docs)] -#![allow(warnings)] +#![deny(warnings)] use std::{ error::Error, diff --git a/src/push_rules.rs b/src/push_rules.rs index 5bd29292..d965712e 100644 --- a/src/push_rules.rs +++ b/src/push_rules.rs @@ -331,12 +331,10 @@ impl<'de> Deserialize<'de> for PushCondition { Ok(PushCondition::SenderNotificationPermission(condition)) } - unknown_kind => { - return Err(D::Error::custom(&format!( - "unknown condition kind `{}`", - unknown_kind - ))) - } + unknown_kind => Err(D::Error::custom(&format!( + "unknown condition kind `{}`", + unknown_kind + ))), } } } diff --git a/src/room/canonical_alias.rs b/src/room/canonical_alias.rs index 1e5530ee..f16b341e 100644 --- a/src/room/canonical_alias.rs +++ b/src/room/canonical_alias.rs @@ -8,8 +8,7 @@ use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; use serde_json::Value; use crate::{ - empty_string_as_none, Event, EventType, InnerInvalidEvent, InvalidEvent, InvalidInput, - RoomEvent, StateEvent, + empty_string_as_none, Event, EventType, InnerInvalidEvent, InvalidEvent, RoomEvent, StateEvent, }; /// Informs the room as to which alias is the canonical one. @@ -231,8 +230,7 @@ mod tests { use std::convert::TryFrom; use js_int::UInt; - use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId}; - use serde_json::Value; + use ruma_identifiers::{EventId, RoomAliasId, UserId}; use super::{CanonicalAliasEvent, CanonicalAliasEventContent}; diff --git a/src/room/encrypted.rs b/src/room/encrypted.rs index 8ca4609d..f05da06c 100644 --- a/src/room/encrypted.rs +++ b/src/room/encrypted.rs @@ -7,7 +7,7 @@ use ruma_identifiers::{DeviceId, EventId, RoomId, UserId}; use serde::{de::Error, ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; -use crate::{Algorithm, Event, EventType, InnerInvalidEvent, InvalidEvent, RoomEvent, StateEvent}; +use crate::{Algorithm, Event, EventType, InnerInvalidEvent, InvalidEvent, RoomEvent}; /// This event type is used when sending encrypted events. /// @@ -83,7 +83,7 @@ impl FromStr for EncryptedEvent { }; Ok(Self { - content: content, + content, event_id: raw.event_id, origin_server_ts: raw.origin_server_ts, room_id: raw.room_id, diff --git a/src/room/member.rs b/src/room/member.rs index 5fc83b31..a1134aa4 100644 --- a/src/room/member.rs +++ b/src/room/member.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; -use js_int::UInt; use ruma_events_macros::ruma_event; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; diff --git a/src/room/message.rs b/src/room/message.rs index 6a72bb55..40622554 100644 --- a/src/room/message.rs +++ b/src/room/message.rs @@ -12,7 +12,7 @@ use serde::{ use serde_json::{from_value, Value}; use super::{EncryptedFile, ImageInfo, ThumbnailInfo}; -use crate::{Event, EventType, InnerInvalidEvent, InvalidEvent, InvalidInput, RoomEvent}; +use crate::{Event, EventType, InnerInvalidEvent, InvalidEvent, RoomEvent}; pub mod feedback; @@ -1107,7 +1107,7 @@ impl Serialize for VideoMessageEventContent { mod tests { use serde_json::to_string; - use super::{AudioMessageEventContent, MessageEventContent, MessageType}; + use super::{AudioMessageEventContent, MessageEventContent}; #[test] fn serialization() { diff --git a/src/room/message/feedback.rs b/src/room/message/feedback.rs index 03541b84..ac7a01c3 100644 --- a/src/room/message/feedback.rs +++ b/src/room/message/feedback.rs @@ -1,6 +1,5 @@ //! Types for the *m.room.message.feedback* event. -use js_int::UInt; use ruma_events_macros::ruma_event; use ruma_identifiers::EventId; use serde::{Deserialize, Serialize}; diff --git a/src/room/power_levels.rs b/src/room/power_levels.rs index 04df2eea..0ddba824 100644 --- a/src/room/power_levels.rs +++ b/src/room/power_levels.rs @@ -7,9 +7,7 @@ use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; use serde_json::Value; -use crate::{ - Event, EventType, InnerInvalidEvent, InvalidEvent, InvalidInput, RoomEvent, StateEvent, -}; +use crate::{Event, EventType, InnerInvalidEvent, InvalidEvent, RoomEvent, StateEvent}; /// Defines the power levels (privileges) of users in the room. #[derive(Clone, Debug, PartialEq)] diff --git a/src/stripped.rs b/src/stripped.rs index 76c257f7..ba9d6117 100644 --- a/src/stripped.rs +++ b/src/stripped.rs @@ -8,7 +8,7 @@ use std::{convert::TryFrom, str::FromStr}; use ruma_identifiers::UserId; -use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; +use serde::{Serialize, Serializer}; use serde_json::{from_value, to_string, Value}; use crate::{ @@ -393,7 +393,7 @@ mod tests { use js_int::UInt; use ruma_identifiers::UserId; - use serde_json::{from_str, to_string}; + use serde_json::to_string; use super::{StrippedRoomName, StrippedRoomTopic, StrippedState}; use crate::{