[fractal/fractal-next] Fix some issue pointed out by clippy



commit d9b9d009bdc8a2a06be0e391b85d31e9d6ecde3b
Author: Julian Sparber <julian sparber net>
Date:   Mon Oct 11 13:18:55 2021 +0200

    Fix some issue pointed out by clippy

 src/components/auth_dialog.rs                      | 10 ++++-----
 src/components/loading_listbox_row.rs              |  6 +++++
 .../account_settings/devices_page/device.rs        | 23 ++++++++-----------
 .../account_settings/devices_page/device_row.rs    | 26 ++++++++++------------
 src/session/account_settings/devices_page/mod.rs   |  8 +++----
 src/session/mod.rs                                 |  4 ++--
 src/session/room/mod.rs                            |  2 +-
 src/session/room/timeline.rs                       |  2 +-
 .../sidebar/account_switcher/add_account.rs        |  6 +++++
 src/session/sidebar/account_switcher/item.rs       |  2 +-
 src/session/sidebar/account_switcher/mod.rs        | 19 ++++++++--------
 src/session/sidebar/row.rs                         |  2 +-
 12 files changed, 56 insertions(+), 54 deletions(-)
---
diff --git a/src/components/auth_dialog.rs b/src/components/auth_dialog.rs
index 00dbd0c6..3928857d 100644
--- a/src/components/auth_dialog.rs
+++ b/src/components/auth_dialog.rs
@@ -59,13 +59,11 @@ impl AuthData {
                 password,
                 session,
             }) => MatrixAuthData::Password(assign!(MatrixPassword::new(
-                                UserIdentifier::MatrixId(&user_id),
-                                &password,
+                                UserIdentifier::MatrixId(user_id),
+                                password,
                             ), { session: session.as_deref() })),
             AuthData::FallbackAcknowledgement(FallbackAcknowledgement { session }) => {
-                MatrixAuthData::FallbackAcknowledgement(MatrixFallbackAcknowledgement::new(
-                    &session,
-                ))
+                MatrixAuthData::FallbackAcknowledgement(MatrixFallbackAcknowledgement::new(session))
             }
         }
     }
@@ -283,7 +281,7 @@ impl AuthDialog {
                         let homeserver = receiver.await.unwrap();
                         self.setup_fallback_page(
                             homeserver.as_str(),
-                            &flow.stages.first()?,
+                            flow.stages.first()?,
                             &session,
                         );
                         if self.show_and_wait_for_response().await {
diff --git a/src/components/loading_listbox_row.rs b/src/components/loading_listbox_row.rs
index ae997750..712383ba 100644
--- a/src/components/loading_listbox_row.rs
+++ b/src/components/loading_listbox_row.rs
@@ -116,6 +116,12 @@ glib::wrapper! {
         @extends gtk::Widget, gtk::ListBoxRow, @implements gtk::Accessible;
 }
 
+impl Default for LoadingListBoxRow {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl LoadingListBoxRow {
     pub fn new() -> Self {
         glib::Object::new(&[]).expect("Failed to create LoadingListBoxRow")
diff --git a/src/session/account_settings/devices_page/device.rs 
b/src/session/account_settings/devices_page/device.rs
index 9c470b0f..acd16b84 100644
--- a/src/session/account_settings/devices_page/device.rs
+++ b/src/session/account_settings/devices_page/device.rs
@@ -162,26 +162,21 @@ impl Device {
         let priv_ = imp::Device::from_instance(self);
         // TODO: Would be nice to also show the location
         // See: https://gitlab.gnome.org/GNOME/fractal/-/issues/700
-        priv_
-            .device
-            .get()
-            .unwrap()
-            .last_seen_ip
-            .as_ref()
-            .map(String::as_str)
+        priv_.device.get().unwrap().last_seen_ip.as_deref()
     }
 
     pub fn last_seen_ts(&self) -> Option<glib::DateTime> {
         let priv_ = imp::Device::from_instance(self);
-        if let Some(last_seen_ts) = priv_.device.get().unwrap().last_seen_ts {
-            Some(
+        priv_
+            .device
+            .get()
+            .unwrap()
+            .last_seen_ts
+            .map(|last_seen_ts| {
                 glib::DateTime::from_unix_utc(last_seen_ts.as_secs().into())
                     .and_then(|t| t.to_local())
-                    .unwrap(),
-            )
-        } else {
-            None
-        }
+                    .unwrap()
+            })
     }
 
     /// Delete the `Device`
diff --git a/src/session/account_settings/devices_page/device_row.rs 
b/src/session/account_settings/devices_page/device_row.rs
index 19fe9b4c..a1a4a68a 100644
--- a/src/session/account_settings/devices_page/device_row.rs
+++ b/src/session/account_settings/devices_page/device_row.rs
@@ -124,7 +124,7 @@ impl DeviceRow {
         }
 
         if let Some(ref device) = device {
-            priv_.display_name.set_label(&device.display_name());
+            priv_.display_name.set_label(device.display_name());
             self.set_tooltip_text(Some(device.device_id().as_str()));
 
             priv_.verified_icon.set_visible(device.is_verified());
@@ -250,20 +250,18 @@ pub fn format_date_time_as_string(datetime: glib::DateTime) -> glib::GString {
             // xgettext:no-c-format
             format = gettext("Last seen %B %-e at %l:%M %p");
         }
+    } else if use_24 {
+        // Translators: this is the day number followed
+        // by the abbreviated month name followed by the year followed
+        // by a time in 24h format i.e. "Last seen February 3 2015 at 23:04"
+        // xgettext:no-c-format
+        format = gettext("Last seen %B %-e %Y at %H:%M");
     } else {
-        if use_24 {
-            // Translators: this is the day number followed
-            // by the abbreviated month name followed by the year followed
-            // by a time in 24h format i.e. "Last seen February 3 2015 at 23:04"
-            // xgettext:no-c-format
-            format = gettext("Last seen %B %-e %Y at %H:%M");
-        } else {
-            // Translators: this is the day number followed
-            // by the abbreviated month name followed by the year followed
-            // by a time in 12h format i.e. "Last seen February 3 2015 at 9:04 PM"
-            // xgettext:no-c-format
-            format = gettext("Last seen %B %-e %Y at %l:%M %p");
-        }
+        // Translators: this is the day number followed
+        // by the abbreviated month name followed by the year followed
+        // by a time in 12h format i.e. "Last seen February 3 2015 at 9:04 PM"
+        // xgettext:no-c-format
+        format = gettext("Last seen %B %-e %Y at %l:%M %p");
     }
 
     datetime.format(&format).unwrap()
diff --git a/src/session/account_settings/devices_page/mod.rs 
b/src/session/account_settings/devices_page/mod.rs
index 111774a2..168fc119 100644
--- a/src/session/account_settings/devices_page/mod.rs
+++ b/src/session/account_settings/devices_page/mod.rs
@@ -119,7 +119,7 @@ impl DevicesPage {
                 clone!(@weak device_list => @default-panic, move |item| {
                     match item.downcast_ref::<DeviceItem>().unwrap().type_() {
                         device_item::ItemType::Device(device) => {
-                            DeviceRow::new(&device).upcast::<gtk::Widget>()
+                            DeviceRow::new(device).upcast::<gtk::Widget>()
                         }
                         device_item::ItemType::Error(error) => {
                             let row = LoadingListBoxRow::new();
@@ -147,7 +147,7 @@ impl DevicesPage {
             device_list.connect_notify_local(
                 Some("current-device"),
                 clone!(@weak self as obj => move |device_list, _| {
-                    obj.set_current_device(&device_list);
+                    obj.set_current_device(device_list);
                 }),
             );
 
@@ -175,9 +175,7 @@ impl DevicesPage {
             priv_.current_session.remove(&child);
         }
         let row = match device_list.current_device().type_() {
-            device_item::ItemType::Device(device) => {
-                DeviceRow::new(&device).upcast::<gtk::Widget>()
-            }
+            device_item::ItemType::Device(device) => DeviceRow::new(device).upcast::<gtk::Widget>(),
             device_item::ItemType::Error(error) => {
                 let row = LoadingListBoxRow::new();
                 row.set_error(Some(error));
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 409be32b..3c4ffe00 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -495,13 +495,13 @@ impl Session {
 
     fn open_account_settings(&self) {
         if let Some(user) = self.user() {
-            let window = AccountSettings::new(self.parent_window().as_ref(), &user);
+            let window = AccountSettings::new(self.parent_window().as_ref(), user);
             window.show();
         }
     }
 
     fn show_room_creation_dialog(&self) {
-        let window = RoomCreation::new(self.parent_window().as_ref(), &self);
+        let window = RoomCreation::new(self.parent_window().as_ref(), self);
         window.show();
     }
 }
diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs
index 91f285f6..4600c79d 100644
--- a/src/session/room/mod.rs
+++ b/src/session/room/mod.rs
@@ -425,7 +425,7 @@ impl Room {
                                                     category.to_string()
                                                 );
                                                 let room_pill = Pill::new();
-                                                room_pill.set_room(Some(obj.clone()));
+                                                room_pill.set_room(Some(obj));
                                                 let label = LabelWithWidgets::new(&error_message, 
vec![room_pill]);
 
                                                 Some(label.upcast())
diff --git a/src/session/room/timeline.rs b/src/session/room/timeline.rs
index f9d16f2c..6e2a0755 100644
--- a/src/session/room/timeline.rs
+++ b/src/session/room/timeline.rs
@@ -300,7 +300,7 @@ impl Timeline {
                 // Store the new event if the `related_to` event isn't known, we will update the 
`relates_to` once
                 // the `related_to` event is is added to the list
                 let relates_to_event = relates_to_events.entry(relates_to_event_id).or_default();
-                relates_to_event.push(event.matrix_event_id().to_owned());
+                relates_to_event.push(event.matrix_event_id());
             }
         }
 
diff --git a/src/session/sidebar/account_switcher/add_account.rs 
b/src/session/sidebar/account_switcher/add_account.rs
index abf9ccff..25a31f23 100644
--- a/src/session/sidebar/account_switcher/add_account.rs
+++ b/src/session/sidebar/account_switcher/add_account.rs
@@ -41,3 +41,9 @@ impl AddAccountRow {
         glib::Object::new(&[]).expect("Failed to create AddAccountRow")
     }
 }
+
+impl Default for AddAccountRow {
+    fn default() -> Self {
+        Self::new()
+    }
+}
diff --git a/src/session/sidebar/account_switcher/item.rs b/src/session/sidebar/account_switcher/item.rs
index 987fa82e..3506c8a2 100644
--- a/src/session/sidebar/account_switcher/item.rs
+++ b/src/session/sidebar/account_switcher/item.rs
@@ -153,7 +153,7 @@ impl Item {
         match self {
             Self::User(ref session_page, hinted) => {
                 let user_entry = UserEntryRow::new(session_page);
-                user_entry.set_hint(hinted.clone());
+                user_entry.set_hint(*hinted);
                 user_entry.upcast()
             }
             Self::Separator => gtk::Separator::new(gtk::Orientation::Vertical).upcast(),
diff --git a/src/session/sidebar/account_switcher/mod.rs b/src/session/sidebar/account_switcher/mod.rs
index 82765f3d..4df8d414 100644
--- a/src/session/sidebar/account_switcher/mod.rs
+++ b/src/session/sidebar/account_switcher/mod.rs
@@ -47,12 +47,12 @@ mod imp {
             self.parent_constructed(obj);
 
             self.entries.connect_activate(|list_view, index| {
-                list_view
+                if let Some(Ok(item)) = list_view
                     .model()
                     .and_then(|model| model.item(index))
                     .map(AccountSwitcherItem::try_from)
-                    .and_then(Result::ok)
-                    .map(|item| match item {
+                {
+                    match item {
                         AccountSwitcherItem::User(session_page, _) => {
                             let session_widget = session_page.child();
                             session_widget
@@ -66,7 +66,8 @@ mod imp {
                             list_view.activate_action("app.new-login", None);
                         }
                         _ => {}
-                    });
+                    }
+                }
             });
         }
     }
@@ -90,7 +91,7 @@ impl AccountSwitcher {
 
         // There is no permanent stuff to take care of,
         // so only bind and unbind are connected.
-        let ref factory = gtk::SignalListItemFactory::new();
+        let factory = &gtk::SignalListItemFactory::new();
         factory.connect_bind(clone!(@weak session_root => move |_, list_item| {
             list_item.set_selectable(false);
             let child = list_item
@@ -122,12 +123,12 @@ impl AccountSwitcher {
 
         entries.set_factory(Some(factory));
 
-        let ref end_items = ExtraItemObj::list_store();
-        let ref items_split = ListStore::new(ListModel::static_type());
+        let end_items = &ExtraItemObj::list_store();
+        let items_split = &ListStore::new(ListModel::static_type());
         items_split.append(sessions_stack_pages);
         items_split.append(end_items);
-        let ref items = gtk::FlattenListModel::new(Some(items_split));
-        let ref selectable_items = gtk::NoSelection::new(Some(items));
+        let items = &gtk::FlattenListModel::new(Some(items_split));
+        let selectable_items = &gtk::NoSelection::new(Some(items));
 
         entries.set_model(Some(selectable_items));
     }
diff --git a/src/session/sidebar/row.rs b/src/session/sidebar/row.rs
index f5a9e920..2bf7f87f 100644
--- a/src/session/sidebar/row.rs
+++ b/src/session/sidebar/row.rs
@@ -108,7 +108,7 @@ impl Row {
         }
 
         let row = if let Some(row) = list_row.clone() {
-            priv_.list_row.replace(list_row.clone());
+            priv_.list_row.replace(list_row);
             row
         } else {
             return;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]