Skip to content

Commit 4fc71c9

Browse files
authored
Fix newer Clippy warnings for 1.80 (#301)
1 parent d8d8e91 commit 4fc71c9

File tree

6 files changed

+41
-38
lines changed

6 files changed

+41
-38
lines changed

src/base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1346,9 +1346,7 @@ impl ChatStore {
13461346

13471347
/// Get a joined room.
13481348
pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> {
1349-
let Some(room) = self.worker.client.get_room(room_id) else {
1350-
return None;
1351-
};
1349+
let room = self.worker.client.get_room(room_id)?;
13521350

13531351
if room.state() == MatrixRoomState::Joined {
13541352
Some(room)

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ mod tests {
11731173
let j = "j".parse::<TerminalKey>().unwrap();
11741174
let esc = "<Esc>".parse::<TerminalKey>().unwrap();
11751175

1176-
let jj = Keys(vec![j.clone(), j], "jj".into());
1176+
let jj = Keys(vec![j, j], "jj".into());
11771177
let run = mapped.get(&jj).unwrap();
11781178
let exp = Keys(vec![esc], "<Esc>".into());
11791179
assert_eq!(run, &exp);

src/message/html.rs

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ pub enum StyleTreeNode {
260260
Anchor(Box<StyleTreeNode>, char, Url),
261261
Blockquote(Box<StyleTreeNode>),
262262
Break,
263+
#[allow(dead_code)]
263264
Code(Box<StyleTreeNode>, Option<String>),
264265
Header(Box<StyleTreeNode>, usize),
265266
Image(Option<String>),

src/message/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::collections::hash_map::DefaultHasher;
55
use std::collections::hash_set;
66
use std::collections::BTreeMap;
77
use std::convert::TryFrom;
8+
use std::fmt::{self, Display};
89
use std::hash::{Hash, Hasher};
910
use std::ops::{Deref, DerefMut};
1011

@@ -1144,9 +1145,9 @@ impl From<RoomMessageEvent> for Message {
11441145
}
11451146
}
11461147

1147-
impl ToString for Message {
1148-
fn to_string(&self) -> String {
1149-
self.event.body().into_owned()
1148+
impl Display for Message {
1149+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1150+
write!(f, "{}", self.event.body())
11501151
}
11511152
}
11521153

@@ -1423,7 +1424,7 @@ pub mod tests {
14231424
"Alt text".to_string(),
14241425
"mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into()
14251426
)
1426-
.info(Some(Box::new(ImageInfo::default())))
1427+
.info(Some(Box::default()))
14271428
))),
14281429
"[Attached Image: Alt text]".to_string()
14291430
);

src/windows/mod.rs

+28-25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! example, [sending messages][crate::base::SendAction] delegate to the [room window][RoomState],
88
//! where we have the message bar and room ID easily accesible and resetable.
99
use std::cmp::{Ord, Ordering, PartialOrd};
10+
use std::fmt::{self, Display};
1011
use std::ops::Deref;
1112
use std::sync::Arc;
1213
use std::time::{Duration, Instant};
@@ -820,7 +821,7 @@ impl GenericChatItem {
820821
let name = info.name.clone().unwrap_or_default();
821822
let alias = room.canonical_alias();
822823
let unread = info.unreads(&store.application.settings);
823-
info.tags = room_info.deref().1.clone();
824+
info.tags.clone_from(&room_info.deref().1);
824825

825826
if let Some(alias) = &alias {
826827
store.application.names.insert(alias.to_string(), room_id.to_owned());
@@ -870,9 +871,9 @@ impl RoomLikeItem for GenericChatItem {
870871
}
871872
}
872873

873-
impl ToString for GenericChatItem {
874-
fn to_string(&self) -> String {
875-
return self.name.clone();
874+
impl Display for GenericChatItem {
875+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
876+
write!(f, "{}", self.name)
876877
}
877878
}
878879

@@ -930,7 +931,7 @@ impl RoomItem {
930931
let name = info.name.clone().unwrap_or_default();
931932
let alias = room.canonical_alias();
932933
let unread = info.unreads(&store.application.settings);
933-
info.tags = room_info.deref().1.clone();
934+
info.tags.clone_from(&room_info.deref().1);
934935

935936
if let Some(alias) = &alias {
936937
store.application.names.insert(alias.to_string(), room_id.to_owned());
@@ -980,9 +981,9 @@ impl RoomLikeItem for RoomItem {
980981
}
981982
}
982983

983-
impl ToString for RoomItem {
984-
fn to_string(&self) -> String {
985-
return self.name.clone();
984+
impl Display for RoomItem {
985+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
986+
write!(f, ":verify request {}", self.name)
986987
}
987988
}
988989

@@ -1034,7 +1035,7 @@ impl DirectItem {
10341035
let info = store.application.rooms.get_or_default(room_id);
10351036
let name = info.name.clone().unwrap_or_default();
10361037
let unread = info.unreads(&store.application.settings);
1037-
info.tags = room_info.deref().1.clone();
1038+
info.tags.clone_from(&room_info.deref().1);
10381039

10391040
DirectItem { room_info, name, alias, unread }
10401041
}
@@ -1080,9 +1081,9 @@ impl RoomLikeItem for DirectItem {
10801081
}
10811082
}
10821083

1083-
impl ToString for DirectItem {
1084-
fn to_string(&self) -> String {
1085-
return self.name.clone();
1084+
impl Display for DirectItem {
1085+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1086+
write!(f, ":verify request {}", self.name)
10861087
}
10871088
}
10881089

@@ -1179,9 +1180,9 @@ impl RoomLikeItem for SpaceItem {
11791180
}
11801181
}
11811182

1182-
impl ToString for SpaceItem {
1183-
fn to_string(&self) -> String {
1184-
return self.room_id().to_string();
1183+
impl Display for SpaceItem {
1184+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1185+
write!(f, ":verify request {}", self.room_id())
11851186
}
11861187
}
11871188

@@ -1300,16 +1301,18 @@ impl From<(&String, &SasVerification)> for VerifyItem {
13001301
}
13011302
}
13021303

1303-
impl ToString for VerifyItem {
1304-
fn to_string(&self) -> String {
1304+
impl Display for VerifyItem {
1305+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
13051306
if self.sasv1.is_done() {
1306-
String::new()
1307-
} else if self.sasv1.is_cancelled() {
1308-
format!(":verify request {}", self.sasv1.other_user_id())
1307+
return Ok(());
1308+
}
1309+
1310+
if self.sasv1.is_cancelled() {
1311+
write!(f, ":verify request {}", self.sasv1.other_user_id())
13091312
} else if self.sasv1.emoji().is_some() {
1310-
format!(":verify confirm {}", self.user_dev)
1313+
write!(f, ":verify confirm {}", self.user_dev)
13111314
} else {
1312-
format!(":verify accept {}", self.user_dev)
1315+
write!(f, ":verify accept {}", self.user_dev)
13131316
}
13141317
}
13151318
}
@@ -1413,9 +1416,9 @@ impl MemberItem {
14131416
}
14141417
}
14151418

1416-
impl ToString for MemberItem {
1417-
fn to_string(&self) -> String {
1418-
self.member.user_id().to_string()
1419+
impl Display for MemberItem {
1420+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1421+
write!(f, "{}", self.member.user_id())
14191422
}
14201423
}
14211424

src/windows/room/scrollback.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1457,11 +1457,11 @@ mod tests {
14571457
assert_eq!(scrollback.cursor, MessageCursor::latest());
14581458

14591459
// Search backwards to MSG4.
1460-
scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap();
1460+
scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap();
14611461
assert_eq!(scrollback.cursor, MSG4_KEY.clone().into());
14621462

14631463
// Search backwards to MSG2.
1464-
scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap();
1464+
scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap();
14651465
assert_eq!(scrollback.cursor, MSG2_KEY.clone().into());
14661466
assert_eq!(
14671467
std::mem::take(&mut store.application.need_load)
@@ -1472,7 +1472,7 @@ mod tests {
14721472
);
14731473

14741474
// Can't go any further; need_load now contains the room ID.
1475-
scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap();
1475+
scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap();
14761476
assert_eq!(scrollback.cursor, MSG2_KEY.clone().into());
14771477
assert_eq!(
14781478
std::mem::take(&mut store.application.need_load)
@@ -1482,11 +1482,11 @@ mod tests {
14821482
);
14831483

14841484
// Search forward twice to MSG1.
1485-
scrollback.search(next.clone(), 2.into(), &ctx, &mut store).unwrap();
1485+
scrollback.search(next, 2.into(), &ctx, &mut store).unwrap();
14861486
assert_eq!(scrollback.cursor, MSG1_KEY.clone().into());
14871487

14881488
// Can't go any further.
1489-
scrollback.search(next.clone(), 2.into(), &ctx, &mut store).unwrap();
1489+
scrollback.search(next, 2.into(), &ctx, &mut store).unwrap();
14901490
assert_eq!(scrollback.cursor, MSG1_KEY.clone().into());
14911491
}
14921492

0 commit comments

Comments
 (0)