[fractal/fractal-next] clippy: Fix warnings
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] clippy: Fix warnings
- Date: Tue, 10 Aug 2021 07:40:53 +0000 (UTC)
commit f5cb220e8cb1357b78f1496fd8fedd86c927c025
Author: Kai A. Hiller <V02460 gmail com>
Date: Mon Aug 9 15:04:21 2021 +0200
clippy: Fix warnings
src/components/label_with_widgets.rs | 3 +-
src/error.rs | 5 +-
src/login.rs | 1 -
src/main.rs | 2 -
src/secret.rs | 7 +-
src/session/avatar.rs | 2 +-
src/session/content/explore/public_room.rs | 10 +-
src/session/content/explore/public_room_list.rs | 2 +-
src/session/content/explore/public_room_row.rs | 18 +--
src/session/content/room_history.rs | 2 +-
src/session/content/state_row.rs | 2 +-
src/session/mod.rs | 7 +-
src/session/room/event.rs | 187 ++++++++++++------------
src/session/room/item.rs | 7 +-
src/session/room/room.rs | 11 +-
src/session/sidebar/category_row.rs | 1 -
src/session/sidebar/entry_row.rs | 1 -
17 files changed, 129 insertions(+), 139 deletions(-)
---
diff --git a/src/components/label_with_widgets.rs b/src/components/label_with_widgets.rs
index 7c8e694d..e1ab5037 100644
--- a/src/components/label_with_widgets.rs
+++ b/src/components/label_with_widgets.rs
@@ -333,8 +333,7 @@ impl LabelWithWidgets {
.analysis()
.extra_attrs()
.iter()
- .find(|attr| attr.type_() == pango::AttrType::Shape)
- .is_some()
+ .any(|attr| attr.type_() == pango::AttrType::Shape)
{
if let Some(widget) = widgets.get(i) {
let (width, height) = widgets_sizes[i];
diff --git a/src/error.rs b/src/error.rs
index 4a3ccf6f..f56e2c56 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -2,6 +2,8 @@ use gtk::{glib, subclass::prelude::*};
use matrix_sdk::Error as MatrixError;
+type WidgetBuilderFn = Box<dyn Fn(&super::Error) -> Option<gtk::Widget> + 'static>;
+
mod imp {
use super::*;
use once_cell::sync::OnceCell;
@@ -10,8 +12,7 @@ mod imp {
#[derive(Default)]
pub struct Error {
pub matrix_error: OnceCell<MatrixError>,
- pub widget_builder:
- RefCell<Option<Box<dyn Fn(&super::Error) -> Option<gtk::Widget> + 'static>>>,
+ pub widget_builder: RefCell<Option<WidgetBuilderFn>>,
}
#[glib::object_subclass]
diff --git a/src/login.rs b/src/login.rs
index b226bb97..384cd30e 100644
--- a/src/login.rs
+++ b/src/login.rs
@@ -1,6 +1,5 @@
use crate::Session;
-use adw;
use adw::subclass::prelude::BinImpl;
use gettextrs::gettext;
use gtk::subclass::prelude::*;
diff --git a/src/main.rs b/src/main.rs
index f714ef3d..586880d8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,14 +20,12 @@ use self::login::Login;
use self::session::Session;
use self::window::Window;
-use adw;
use config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
use gettextrs::*;
use gtk::gdk::Display;
use gtk::gio;
use gtk::IconTheme;
use once_cell::sync::Lazy;
-use tokio;
/// The default tokio runtime to be used for async tasks
pub static RUNTIME: Lazy<tokio::runtime::Runtime> =
diff --git a/src/secret.rs b/src/secret.rs
index 9ec0563f..e4021382 100644
--- a/src/secret.rs
+++ b/src/secret.rs
@@ -23,11 +23,14 @@ pub fn restore_sessions() -> Result<Vec<StoredSession>, secret_service::Error> {
// Sessions that contain or produce errors are ignored.
// TODO: Return error for corrupt sessions
+ type TmpKey = (String, String, String);
+ type TmpValue = (String, Option<String>);
+
let res = collection
.get_all_items()?
.iter()
.fold(HashMap::new(), |mut acc, item| {
- let finder = move || -> Option<((String, String, String), (String, Option<String>))> {
+ let finder = move || -> Option<(TmpKey, TmpValue)> {
let attr = item.get_attributes().ok()?;
let homeserver = attr.get("homeserver")?.to_string();
@@ -39,7 +42,7 @@ pub fn restore_sessions() -> Result<Vec<StoredSession>, secret_service::Error> {
};
if let Some((key, value)) = finder() {
- acc.entry(key).or_insert(vec![]).push(value);
+ acc.entry(key).or_insert_with(Vec::new).push(value);
}
acc
diff --git a/src/session/avatar.rs b/src/session/avatar.rs
index 63b4331c..1a5198b1 100644
--- a/src/session/avatar.rs
+++ b/src/session/avatar.rs
@@ -143,7 +143,7 @@ impl Avatar {
let stream = gio::MemoryInputStream::from_bytes(&glib::Bytes::from(&data));
Pixbuf::from_stream(&stream, gio::NONE_CANCELLABLE)
.ok()
- .and_then(|pixbuf| Some(gdk::Texture::for_pixbuf(&pixbuf).upcast()))
+ .map(|pixbuf| gdk::Texture::for_pixbuf(&pixbuf).upcast())
} else {
None
};
diff --git a/src/session/content/explore/public_room.rs b/src/session/content/explore/public_room.rs
index 884307e1..a7cee821 100644
--- a/src/session/content/explore/public_room.rs
+++ b/src/session/content/explore/public_room.rs
@@ -201,12 +201,10 @@ impl PublicRoom {
let session = self.session();
if let Some(room) = self.room() {
session.set_selected_room(Some(room.clone()));
- } else {
- if let Some(matrix_public_room) = self.matrix_public_room() {
- session
- .room_list()
- .join_by_id_or_alias(matrix_public_room.room_id.clone().into());
- }
+ } else if let Some(matrix_public_room) = self.matrix_public_room() {
+ session
+ .room_list()
+ .join_by_id_or_alias(matrix_public_room.room_id.clone().into());
}
}
}
diff --git a/src/session/content/explore/public_room_list.rs b/src/session/content/explore/public_room_list.rs
index 614acb58..f285d1ec 100644
--- a/src/session/content/explore/public_room_list.rs
+++ b/src/session/content/explore/public_room_list.rs
@@ -212,7 +212,7 @@ impl PublicRoomList {
})
.collect();
- let empty_row = list.pop().unwrap_or(PublicRoom::new(session));
+ let empty_row = list.pop().unwrap_or_else(|| PublicRoom::new(session));
list.append(&mut new_rooms);
if !self.complete() {
diff --git a/src/session/content/explore/public_room_row.rs b/src/session/content/explore/public_room_row.rs
index 2027b1ad..31ae061e 100644
--- a/src/session/content/explore/public_room_row.rs
+++ b/src/session/content/explore/public_room_row.rs
@@ -199,16 +199,14 @@ impl PublicRoomRow {
priv_.room_handler.replace(Some(room_handler));
self.update_button(public_room);
- } else {
- if priv_.original_child.borrow().is_none() {
- let spinner = gtk::SpinnerBuilder::new()
- .spinning(true)
- .margin_top(12)
- .margin_bottom(12)
- .build();
- priv_.original_child.replace(self.child());
- self.set_child(Some(&spinner));
- }
+ } else if priv_.original_child.borrow().is_none() {
+ let spinner = gtk::SpinnerBuilder::new()
+ .spinning(true)
+ .margin_top(12)
+ .margin_bottom(12)
+ .build();
+ priv_.original_child.replace(self.child());
+ self.set_child(Some(&spinner));
}
}
priv_
diff --git a/src/session/content/room_history.rs b/src/session/content/room_history.rs
index 570cc3e0..29b42dad 100644
--- a/src/session/content/room_history.rs
+++ b/src/session/content/room_history.rs
@@ -254,7 +254,7 @@ impl RoomHistory {
// TODO: use gtk::MultiSelection to allow selection
let model = room
.as_ref()
- .and_then(|room| Some(gtk::NoSelection::new(Some(room.timeline()))));
+ .map(|room| gtk::NoSelection::new(Some(room.timeline())));
priv_.listview.set_model(model.as_ref());
priv_.room.replace(room);
diff --git a/src/session/content/state_row.rs b/src/session/content/state_row.rs
index 7f4b4aff..f214ba5d 100644
--- a/src/session/content/state_row.rs
+++ b/src/session/content/state_row.rs
@@ -63,7 +63,7 @@ impl StateRow {
let display_name = event
.displayname
.clone()
- .unwrap_or(state.state_key().into());
+ .unwrap_or_else(|| state.state_key().into());
match event.membership {
MembershipState::Join => {
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 311bb445..20954be5 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -22,7 +22,6 @@ use crate::RUNTIME;
use crate::login::LoginError;
use crate::session::content::ContentType;
-use adw;
use adw::subclass::prelude::BinImpl;
use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
@@ -247,9 +246,9 @@ impl Session {
Ok(response) => Ok((
client,
StoredSession {
- homeserver: homeserver,
- path: path,
- passphrase: passphrase,
+ homeserver,
+ path,
+ passphrase,
access_token: response.access_token,
user_id: response.user_id,
device_id: response.device_id,
diff --git a/src/session/room/event.rs b/src/session/room/event.rs
index a7fef543..9bcf19b3 100644
--- a/src/session/room/event.rs
+++ b/src/session/room/event.rs
@@ -311,79 +311,79 @@ impl Event {
return true;
}
- if let Some(event) = priv_.event.borrow().as_ref() {
- match event {
- AnySyncRoomEvent::Message(message) => match message {
- AnySyncMessageEvent::CallAnswer(_) => true,
- AnySyncMessageEvent::CallInvite(_) => true,
- AnySyncMessageEvent::CallHangup(_) => true,
- AnySyncMessageEvent::CallCandidates(_) => true,
- AnySyncMessageEvent::KeyVerificationReady(_) => true,
- AnySyncMessageEvent::KeyVerificationStart(_) => true,
- AnySyncMessageEvent::KeyVerificationCancel(_) => true,
- AnySyncMessageEvent::KeyVerificationAccept(_) => true,
- AnySyncMessageEvent::KeyVerificationKey(_) => true,
- AnySyncMessageEvent::KeyVerificationMac(_) => true,
- AnySyncMessageEvent::KeyVerificationDone(_) => true,
- AnySyncMessageEvent::RoomEncrypted(_) => true,
- AnySyncMessageEvent::RoomMessageFeedback(_) => true,
- AnySyncMessageEvent::RoomRedaction(_) => true,
- AnySyncMessageEvent::Sticker(_) => true,
- _ => false,
- },
- AnySyncRoomEvent::State(state) => match state {
- AnySyncStateEvent::PolicyRuleRoom(_) => true,
- AnySyncStateEvent::PolicyRuleServer(_) => true,
- AnySyncStateEvent::PolicyRuleUser(_) => true,
- AnySyncStateEvent::RoomAliases(_) => true,
- AnySyncStateEvent::RoomAvatar(_) => true,
- AnySyncStateEvent::RoomCanonicalAlias(_) => true,
- AnySyncStateEvent::RoomEncryption(_) => true,
- AnySyncStateEvent::RoomJoinRules(_) => true,
- AnySyncStateEvent::RoomName(_) => true,
- AnySyncStateEvent::RoomPinnedEvents(_) => true,
- AnySyncStateEvent::RoomPowerLevels(_) => true,
- AnySyncStateEvent::RoomServerAcl(_) => true,
- AnySyncStateEvent::RoomTopic(_) => true,
- _ => false,
- },
- AnySyncRoomEvent::RedactedMessage(message) => match message {
- AnyRedactedSyncMessageEvent::CallAnswer(_) => true,
- AnyRedactedSyncMessageEvent::CallInvite(_) => true,
- AnyRedactedSyncMessageEvent::CallHangup(_) => true,
- AnyRedactedSyncMessageEvent::CallCandidates(_) => true,
- AnyRedactedSyncMessageEvent::KeyVerificationReady(_) => true,
- AnyRedactedSyncMessageEvent::KeyVerificationStart(_) => true,
- AnyRedactedSyncMessageEvent::KeyVerificationCancel(_) => true,
- AnyRedactedSyncMessageEvent::KeyVerificationAccept(_) => true,
- AnyRedactedSyncMessageEvent::KeyVerificationKey(_) => true,
- AnyRedactedSyncMessageEvent::KeyVerificationMac(_) => true,
- AnyRedactedSyncMessageEvent::KeyVerificationDone(_) => true,
- AnyRedactedSyncMessageEvent::RoomEncrypted(_) => true,
- AnyRedactedSyncMessageEvent::RoomMessageFeedback(_) => true,
- AnyRedactedSyncMessageEvent::RoomRedaction(_) => true,
- AnyRedactedSyncMessageEvent::Sticker(_) => true,
- _ => false,
- },
- AnySyncRoomEvent::RedactedState(state) => match state {
- AnyRedactedSyncStateEvent::PolicyRuleRoom(_) => true,
- AnyRedactedSyncStateEvent::PolicyRuleServer(_) => true,
- AnyRedactedSyncStateEvent::PolicyRuleUser(_) => true,
- AnyRedactedSyncStateEvent::RoomAliases(_) => true,
- AnyRedactedSyncStateEvent::RoomAvatar(_) => true,
- AnyRedactedSyncStateEvent::RoomCanonicalAlias(_) => true,
- AnyRedactedSyncStateEvent::RoomEncryption(_) => true,
- AnyRedactedSyncStateEvent::RoomJoinRules(_) => true,
- AnyRedactedSyncStateEvent::RoomName(_) => true,
- AnyRedactedSyncStateEvent::RoomPinnedEvents(_) => true,
- AnyRedactedSyncStateEvent::RoomPowerLevels(_) => true,
- AnyRedactedSyncStateEvent::RoomServerAcl(_) => true,
- AnyRedactedSyncStateEvent::RoomTopic(_) => true,
- _ => false,
- },
- }
- } else {
- false
+ let event = priv_.event.borrow();
+
+ // List of all events to be hidden.
+ match event.as_ref() {
+ Some(AnySyncRoomEvent::Message(message)) => matches!(
+ message,
+ AnySyncMessageEvent::CallAnswer(_)
+ | AnySyncMessageEvent::CallInvite(_)
+ | AnySyncMessageEvent::CallHangup(_)
+ | AnySyncMessageEvent::CallCandidates(_)
+ | AnySyncMessageEvent::KeyVerificationReady(_)
+ | AnySyncMessageEvent::KeyVerificationStart(_)
+ | AnySyncMessageEvent::KeyVerificationCancel(_)
+ | AnySyncMessageEvent::KeyVerificationAccept(_)
+ | AnySyncMessageEvent::KeyVerificationKey(_)
+ | AnySyncMessageEvent::KeyVerificationMac(_)
+ | AnySyncMessageEvent::KeyVerificationDone(_)
+ | AnySyncMessageEvent::RoomEncrypted(_)
+ | AnySyncMessageEvent::RoomMessageFeedback(_)
+ | AnySyncMessageEvent::RoomRedaction(_)
+ | AnySyncMessageEvent::Sticker(_)
+ ),
+ Some(AnySyncRoomEvent::State(state)) => matches!(
+ state,
+ AnySyncStateEvent::PolicyRuleRoom(_)
+ | AnySyncStateEvent::PolicyRuleServer(_)
+ | AnySyncStateEvent::PolicyRuleUser(_)
+ | AnySyncStateEvent::RoomAliases(_)
+ | AnySyncStateEvent::RoomAvatar(_)
+ | AnySyncStateEvent::RoomCanonicalAlias(_)
+ | AnySyncStateEvent::RoomEncryption(_)
+ | AnySyncStateEvent::RoomJoinRules(_)
+ | AnySyncStateEvent::RoomName(_)
+ | AnySyncStateEvent::RoomPinnedEvents(_)
+ | AnySyncStateEvent::RoomPowerLevels(_)
+ | AnySyncStateEvent::RoomServerAcl(_)
+ | AnySyncStateEvent::RoomTopic(_)
+ ),
+ Some(AnySyncRoomEvent::RedactedMessage(message)) => matches!(
+ message,
+ AnyRedactedSyncMessageEvent::CallAnswer(_)
+ | AnyRedactedSyncMessageEvent::CallInvite(_)
+ | AnyRedactedSyncMessageEvent::CallHangup(_)
+ | AnyRedactedSyncMessageEvent::CallCandidates(_)
+ | AnyRedactedSyncMessageEvent::KeyVerificationReady(_)
+ | AnyRedactedSyncMessageEvent::KeyVerificationStart(_)
+ | AnyRedactedSyncMessageEvent::KeyVerificationCancel(_)
+ | AnyRedactedSyncMessageEvent::KeyVerificationAccept(_)
+ | AnyRedactedSyncMessageEvent::KeyVerificationKey(_)
+ | AnyRedactedSyncMessageEvent::KeyVerificationMac(_)
+ | AnyRedactedSyncMessageEvent::KeyVerificationDone(_)
+ | AnyRedactedSyncMessageEvent::RoomEncrypted(_)
+ | AnyRedactedSyncMessageEvent::RoomMessageFeedback(_)
+ | AnyRedactedSyncMessageEvent::RoomRedaction(_)
+ | AnyRedactedSyncMessageEvent::Sticker(_)
+ ),
+ Some(AnySyncRoomEvent::RedactedState(state)) => matches!(
+ state,
+ AnyRedactedSyncStateEvent::PolicyRuleRoom(_)
+ | AnyRedactedSyncStateEvent::PolicyRuleServer(_)
+ | AnyRedactedSyncStateEvent::PolicyRuleUser(_)
+ | AnyRedactedSyncStateEvent::RoomAliases(_)
+ | AnyRedactedSyncStateEvent::RoomAvatar(_)
+ | AnyRedactedSyncStateEvent::RoomCanonicalAlias(_)
+ | AnyRedactedSyncStateEvent::RoomEncryption(_)
+ | AnyRedactedSyncStateEvent::RoomJoinRules(_)
+ | AnyRedactedSyncStateEvent::RoomName(_)
+ | AnyRedactedSyncStateEvent::RoomPinnedEvents(_)
+ | AnyRedactedSyncStateEvent::RoomPowerLevels(_)
+ | AnyRedactedSyncStateEvent::RoomServerAcl(_)
+ | AnyRedactedSyncStateEvent::RoomTopic(_)
+ ),
+ _ => false,
}
}
@@ -402,29 +402,30 @@ impl Event {
priv_.show_header.get()
}
- pub fn can_hide_header(&self) -> bool {
- if let Some(event) = self.matrix_event() {
- match event {
- AnySyncRoomEvent::Message(ref message) => match message.content() {
- AnyMessageEventContent::RoomMessage(message) => match message.msgtype {
- MessageType::Audio(_) => true,
- MessageType::File(_) => true,
- MessageType::Image(_) => true,
- MessageType::Location(_) => true,
- MessageType::Notice(_) => true,
- MessageType::Text(_) => true,
- MessageType::Video(_) => true,
- _ => false,
- },
- _ => false,
- },
- _ => false,
- }
- } else {
- false
+ fn message_content(&self) -> Option<AnyMessageEventContent> {
+ match self.matrix_event() {
+ Some(AnySyncRoomEvent::Message(message)) => Some(message.content()),
+ _ => None,
}
}
+ pub fn can_hide_header(&self) -> bool {
+ let msgtype = match self.message_content() {
+ Some(AnyMessageEventContent::RoomMessage(message)) => message.msgtype,
+ _ => return false,
+ };
+ matches!(
+ msgtype,
+ MessageType::Audio(_)
+ | MessageType::File(_)
+ | MessageType::Image(_)
+ | MessageType::Location(_)
+ | MessageType::Notice(_)
+ | MessageType::Text(_)
+ | MessageType::Video(_)
+ )
+ }
+
pub fn add_relates_to(&self, events: Vec<Event>) {
let priv_ = imp::Event::from_instance(&self);
priv_.relates_to.borrow_mut().extend(events);
diff --git a/src/session/room/item.rs b/src/session/room/item.rs
index 446daa5e..eefa8e31 100644
--- a/src/session/room/item.rs
+++ b/src/session/room/item.rs
@@ -134,12 +134,7 @@ impl Item {
}
pub fn selectable(&self) -> bool {
- let priv_ = imp::Item::from_instance(&self);
- if let ItemType::Event(_event) = priv_.type_.get().unwrap() {
- true
- } else {
- false
- }
+ matches!(self.type_(), ItemType::Event(_event))
}
pub fn matrix_event(&self) -> Option<AnySyncRoomEvent> {
diff --git a/src/session/room/room.rs b/src/session/room/room.rs
index bc85befe..430ac110 100644
--- a/src/session/room/room.rs
+++ b/src/session/room/room.rs
@@ -236,7 +236,7 @@ impl Room {
pub fn room_id(&self) -> &RoomId {
let priv_ = imp::Room::from_instance(self);
- priv_.room_id.get().unwrap().into()
+ priv_.room_id.get().unwrap()
}
fn matrix_room(&self) -> MatrixRoom {
@@ -446,7 +446,8 @@ impl Room {
pub fn display_name(&self) -> String {
let priv_ = imp::Room::from_instance(&self);
- priv_.name.borrow().to_owned().unwrap_or(gettext("Unknown"))
+ let display_name = priv_.name.borrow().clone();
+ display_name.unwrap_or_else(|| gettext("Unknown"))
}
fn set_display_name(&self, display_name: Option<String>) {
@@ -500,7 +501,7 @@ impl Room {
room_members
.entry(user_id.clone())
- .or_insert(User::new(self.session(), &user_id))
+ .or_insert_with(|| User::new(self.session(), &user_id))
.clone()
}
@@ -581,7 +582,7 @@ impl Room {
let user_id = member.user_id();
let user = room_members
.entry(user_id.clone())
- .or_insert(User::new(self.session(), user_id));
+ .or_insert_with(|| User::new(self.session(), user_id));
user.update_from_room_member(&member);
}
}
@@ -593,7 +594,7 @@ impl Room {
let user_id = &event.sender;
let user = room_members
.entry(user_id.clone())
- .or_insert(User::new(self.session(), user_id));
+ .or_insert_with(|| User::new(self.session(), user_id));
user.update_from_member_event(event);
}
diff --git a/src/session/sidebar/category_row.rs b/src/session/sidebar/category_row.rs
index c7953a85..c578be74 100644
--- a/src/session/sidebar/category_row.rs
+++ b/src/session/sidebar/category_row.rs
@@ -1,4 +1,3 @@
-use adw;
use adw::subclass::prelude::BinImpl;
use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
diff --git a/src/session/sidebar/entry_row.rs b/src/session/sidebar/entry_row.rs
index bf7faa0c..b56b1711 100644
--- a/src/session/sidebar/entry_row.rs
+++ b/src/session/sidebar/entry_row.rs
@@ -1,4 +1,3 @@
-use adw;
use adw::subclass::prelude::BinImpl;
use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]