Fix newer Clippy warnings for 1.80 (#301)

This commit is contained in:
Jarkko Sakkinen 2024-08-01 06:02:42 +03:00 committed by GitHub
parent d8d8e91295
commit 4fc71c9291
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 41 additions and 38 deletions

View file

@ -1346,9 +1346,7 @@ impl ChatStore {
/// Get a joined room. /// Get a joined room.
pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> { pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> {
let Some(room) = self.worker.client.get_room(room_id) else { let room = self.worker.client.get_room(room_id)?;
return None;
};
if room.state() == MatrixRoomState::Joined { if room.state() == MatrixRoomState::Joined {
Some(room) Some(room)

View file

@ -1173,7 +1173,7 @@ mod tests {
let j = "j".parse::<TerminalKey>().unwrap(); let j = "j".parse::<TerminalKey>().unwrap();
let esc = "<Esc>".parse::<TerminalKey>().unwrap(); let esc = "<Esc>".parse::<TerminalKey>().unwrap();
let jj = Keys(vec![j.clone(), j], "jj".into()); let jj = Keys(vec![j, j], "jj".into());
let run = mapped.get(&jj).unwrap(); let run = mapped.get(&jj).unwrap();
let exp = Keys(vec![esc], "<Esc>".into()); let exp = Keys(vec![esc], "<Esc>".into());
assert_eq!(run, &exp); assert_eq!(run, &exp);

View file

@ -260,6 +260,7 @@ pub enum StyleTreeNode {
Anchor(Box<StyleTreeNode>, char, Url), Anchor(Box<StyleTreeNode>, char, Url),
Blockquote(Box<StyleTreeNode>), Blockquote(Box<StyleTreeNode>),
Break, Break,
#[allow(dead_code)]
Code(Box<StyleTreeNode>, Option<String>), Code(Box<StyleTreeNode>, Option<String>),
Header(Box<StyleTreeNode>, usize), Header(Box<StyleTreeNode>, usize),
Image(Option<String>), Image(Option<String>),

View file

@ -5,6 +5,7 @@ use std::collections::hash_map::DefaultHasher;
use std::collections::hash_set; use std::collections::hash_set;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::fmt::{self, Display};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
@ -1144,9 +1145,9 @@ impl From<RoomMessageEvent> for Message {
} }
} }
impl ToString for Message { impl Display for Message {
fn to_string(&self) -> String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.event.body().into_owned() write!(f, "{}", self.event.body())
} }
} }
@ -1423,7 +1424,7 @@ pub mod tests {
"Alt text".to_string(), "Alt text".to_string(),
"mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into() "mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into()
) )
.info(Some(Box::new(ImageInfo::default()))) .info(Some(Box::default()))
))), ))),
"[Attached Image: Alt text]".to_string() "[Attached Image: Alt text]".to_string()
); );

View file

@ -7,6 +7,7 @@
//! example, [sending messages][crate::base::SendAction] delegate to the [room window][RoomState], //! example, [sending messages][crate::base::SendAction] delegate to the [room window][RoomState],
//! where we have the message bar and room ID easily accesible and resetable. //! where we have the message bar and room ID easily accesible and resetable.
use std::cmp::{Ord, Ordering, PartialOrd}; use std::cmp::{Ord, Ordering, PartialOrd};
use std::fmt::{self, Display};
use std::ops::Deref; use std::ops::Deref;
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -820,7 +821,7 @@ impl GenericChatItem {
let name = info.name.clone().unwrap_or_default(); let name = info.name.clone().unwrap_or_default();
let alias = room.canonical_alias(); let alias = room.canonical_alias();
let unread = info.unreads(&store.application.settings); let unread = info.unreads(&store.application.settings);
info.tags = room_info.deref().1.clone(); info.tags.clone_from(&room_info.deref().1);
if let Some(alias) = &alias { if let Some(alias) = &alias {
store.application.names.insert(alias.to_string(), room_id.to_owned()); store.application.names.insert(alias.to_string(), room_id.to_owned());
@ -870,9 +871,9 @@ impl RoomLikeItem for GenericChatItem {
} }
} }
impl ToString for GenericChatItem { impl Display for GenericChatItem {
fn to_string(&self) -> String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
return self.name.clone(); write!(f, "{}", self.name)
} }
} }
@ -930,7 +931,7 @@ impl RoomItem {
let name = info.name.clone().unwrap_or_default(); let name = info.name.clone().unwrap_or_default();
let alias = room.canonical_alias(); let alias = room.canonical_alias();
let unread = info.unreads(&store.application.settings); let unread = info.unreads(&store.application.settings);
info.tags = room_info.deref().1.clone(); info.tags.clone_from(&room_info.deref().1);
if let Some(alias) = &alias { if let Some(alias) = &alias {
store.application.names.insert(alias.to_string(), room_id.to_owned()); store.application.names.insert(alias.to_string(), room_id.to_owned());
@ -980,9 +981,9 @@ impl RoomLikeItem for RoomItem {
} }
} }
impl ToString for RoomItem { impl Display for RoomItem {
fn to_string(&self) -> String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
return self.name.clone(); write!(f, ":verify request {}", self.name)
} }
} }
@ -1034,7 +1035,7 @@ impl DirectItem {
let info = store.application.rooms.get_or_default(room_id); let info = store.application.rooms.get_or_default(room_id);
let name = info.name.clone().unwrap_or_default(); let name = info.name.clone().unwrap_or_default();
let unread = info.unreads(&store.application.settings); let unread = info.unreads(&store.application.settings);
info.tags = room_info.deref().1.clone(); info.tags.clone_from(&room_info.deref().1);
DirectItem { room_info, name, alias, unread } DirectItem { room_info, name, alias, unread }
} }
@ -1080,9 +1081,9 @@ impl RoomLikeItem for DirectItem {
} }
} }
impl ToString for DirectItem { impl Display for DirectItem {
fn to_string(&self) -> String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
return self.name.clone(); write!(f, ":verify request {}", self.name)
} }
} }
@ -1179,9 +1180,9 @@ impl RoomLikeItem for SpaceItem {
} }
} }
impl ToString for SpaceItem { impl Display for SpaceItem {
fn to_string(&self) -> String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
return self.room_id().to_string(); write!(f, ":verify request {}", self.room_id())
} }
} }
@ -1300,16 +1301,18 @@ impl From<(&String, &SasVerification)> for VerifyItem {
} }
} }
impl ToString for VerifyItem { impl Display for VerifyItem {
fn to_string(&self) -> String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.sasv1.is_done() { if self.sasv1.is_done() {
String::new() return Ok(());
} else if self.sasv1.is_cancelled() { }
format!(":verify request {}", self.sasv1.other_user_id())
if self.sasv1.is_cancelled() {
write!(f, ":verify request {}", self.sasv1.other_user_id())
} else if self.sasv1.emoji().is_some() { } else if self.sasv1.emoji().is_some() {
format!(":verify confirm {}", self.user_dev) write!(f, ":verify confirm {}", self.user_dev)
} else { } else {
format!(":verify accept {}", self.user_dev) write!(f, ":verify accept {}", self.user_dev)
} }
} }
} }
@ -1413,9 +1416,9 @@ impl MemberItem {
} }
} }
impl ToString for MemberItem { impl Display for MemberItem {
fn to_string(&self) -> String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.member.user_id().to_string() write!(f, "{}", self.member.user_id())
} }
} }

View file

@ -1457,11 +1457,11 @@ mod tests {
assert_eq!(scrollback.cursor, MessageCursor::latest()); assert_eq!(scrollback.cursor, MessageCursor::latest());
// Search backwards to MSG4. // Search backwards to MSG4.
scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap();
assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); assert_eq!(scrollback.cursor, MSG4_KEY.clone().into());
// Search backwards to MSG2. // Search backwards to MSG2.
scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap();
assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); assert_eq!(scrollback.cursor, MSG2_KEY.clone().into());
assert_eq!( assert_eq!(
std::mem::take(&mut store.application.need_load) std::mem::take(&mut store.application.need_load)
@ -1472,7 +1472,7 @@ mod tests {
); );
// Can't go any further; need_load now contains the room ID. // Can't go any further; need_load now contains the room ID.
scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap();
assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); assert_eq!(scrollback.cursor, MSG2_KEY.clone().into());
assert_eq!( assert_eq!(
std::mem::take(&mut store.application.need_load) std::mem::take(&mut store.application.need_load)
@ -1482,11 +1482,11 @@ mod tests {
); );
// Search forward twice to MSG1. // Search forward twice to MSG1.
scrollback.search(next.clone(), 2.into(), &ctx, &mut store).unwrap(); scrollback.search(next, 2.into(), &ctx, &mut store).unwrap();
assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); assert_eq!(scrollback.cursor, MSG1_KEY.clone().into());
// Can't go any further. // Can't go any further.
scrollback.search(next.clone(), 2.into(), &ctx, &mut store).unwrap(); scrollback.search(next, 2.into(), &ctx, &mut store).unwrap();
assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); assert_eq!(scrollback.cursor, MSG1_KEY.clone().into());
} }