ci: update to Rust 1.75.0 and fix clippy

This commit is contained in:
link2xt
2024-01-08 20:01:40 +00:00
parent b9a58bf625
commit 2f8a8f9f50
13 changed files with 31 additions and 27 deletions

View File

@@ -24,7 +24,7 @@ jobs:
name: Lint Rust name: Lint Rust
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
RUSTUP_TOOLCHAIN: 1.74.1 RUSTUP_TOOLCHAIN: 1.75.0
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Install rustfmt and clippy - name: Install rustfmt and clippy
@@ -76,11 +76,11 @@ jobs:
matrix: matrix:
include: include:
- os: ubuntu-latest - os: ubuntu-latest
rust: 1.74.1 rust: 1.75.0
- os: windows-latest - os: windows-latest
rust: 1.74.1 rust: 1.75.0
- os: macos-latest - os: macos-latest
rust: 1.74.1 rust: 1.75.0
# Minimum Supported Rust Version = 1.70.0 # Minimum Supported Rust Version = 1.70.0
- os: ubuntu-latest - os: ubuntu-latest

View File

@@ -85,7 +85,7 @@ impl FullChat {
let can_send = chat.can_send(context).await?; let can_send = chat.can_send(context).await?;
let was_seen_recently = if chat.get_type() == Chattype::Single { let was_seen_recently = if chat.get_type() == Chattype::Single {
match contact_ids.get(0) { match contact_ids.first() {
Some(contact) => Contact::get_by_id(context, *contact) Some(contact) => Contact::get_by_id(context, *contact)
.await .await
.context("failed to load contact for was_seen_recently")? .context("failed to load contact for was_seen_recently")?

View File

@@ -102,7 +102,7 @@ pub(crate) async fn get_chat_list_item_by_id(
let self_in_group = chat_contacts.contains(&ContactId::SELF); let self_in_group = chat_contacts.contains(&ContactId::SELF);
let (dm_chat_contact, was_seen_recently) = if chat.get_type() == Chattype::Single { let (dm_chat_contact, was_seen_recently) = if chat.get_type() == Chattype::Single {
let contact = chat_contacts.get(0); let contact = chat_contacts.first();
let was_seen_recently = match contact { let was_seen_recently = match contact {
Some(contact) => Contact::get_by_id(ctx, *contact) Some(contact) => Contact::get_by_id(ctx, *contact)
.await .await

View File

@@ -546,8 +546,12 @@ impl Config {
} }
if self.inner.selected_account == id { if self.inner.selected_account == id {
// reset selected account // reset selected account
self.inner.selected_account = self.inner.selected_account = self
self.inner.accounts.get(0).map(|e| e.id).unwrap_or_default(); .inner
.accounts
.first()
.map(|e| e.id)
.unwrap_or_default();
} }
} }

View File

@@ -1885,12 +1885,12 @@ mod tests {
// Search by name. // Search by name.
let contacts = Contact::get_all(&context.ctx, 0, Some("bob")).await?; let contacts = Contact::get_all(&context.ctx, 0, Some("bob")).await?;
assert_eq!(contacts.len(), 1); assert_eq!(contacts.len(), 1);
assert_eq!(contacts.get(0), Some(&id)); assert_eq!(contacts.first(), Some(&id));
// Search by address. // Search by address.
let contacts = Contact::get_all(&context.ctx, 0, Some("user")).await?; let contacts = Contact::get_all(&context.ctx, 0, Some("user")).await?;
assert_eq!(contacts.len(), 1); assert_eq!(contacts.len(), 1);
assert_eq!(contacts.get(0), Some(&id)); assert_eq!(contacts.first(), Some(&id));
let contacts = Contact::get_all(&context.ctx, 0, Some("alice")).await?; let contacts = Contact::get_all(&context.ctx, 0, Some("alice")).await?;
assert_eq!(contacts.len(), 0); assert_eq!(contacts.len(), 0);
@@ -1917,7 +1917,7 @@ mod tests {
// Search by display name (same as manually set name). // Search by display name (same as manually set name).
let contacts = Contact::get_all(&context.ctx, 0, Some("someone")).await?; let contacts = Contact::get_all(&context.ctx, 0, Some("someone")).await?;
assert_eq!(contacts.len(), 1); assert_eq!(contacts.len(), 1);
assert_eq!(contacts.get(0), Some(&id)); assert_eq!(contacts.first(), Some(&id));
Ok(()) Ok(())
} }

View File

@@ -1370,7 +1370,7 @@ mod tests {
assert_eq!(res.len(), 2); assert_eq!(res.len(), 2);
// Message added later is returned first. // Message added later is returned first.
assert_eq!(res.get(0), Some(&msg2.id)); assert_eq!(res.first(), Some(&msg2.id));
assert_eq!(res.get(1), Some(&msg1.id)); assert_eq!(res.get(1), Some(&msg1.id));
// Global search with longer text does not find any message. // Global search with longer text does not find any message.
@@ -1587,7 +1587,7 @@ mod tests {
let bob_next_msg_ids = bob.get_next_msgs().await?; let bob_next_msg_ids = bob.get_next_msgs().await?;
assert_eq!(bob_next_msg_ids.len(), 1); assert_eq!(bob_next_msg_ids.len(), 1);
assert_eq!(bob_next_msg_ids.get(0), Some(&received_msg.id)); assert_eq!(bob_next_msg_ids.first(), Some(&received_msg.id));
bob.set_config_u32(Config::LastMsgId, received_msg.id.to_u32()) bob.set_config_u32(Config::LastMsgId, received_msg.id.to_u32())
.await?; .await?;
@@ -1596,7 +1596,7 @@ mod tests {
// Next messages include self-sent messages. // Next messages include self-sent messages.
let alice_next_msg_ids = alice.get_next_msgs().await?; let alice_next_msg_ids = alice.get_next_msgs().await?;
assert_eq!(alice_next_msg_ids.len(), 1); assert_eq!(alice_next_msg_ids.len(), 1);
assert_eq!(alice_next_msg_ids.get(0), Some(&sent_msg.sender_msg_id)); assert_eq!(alice_next_msg_ids.first(), Some(&sent_msg.sender_msg_id));
alice alice
.set_config_u32(Config::LastMsgId, sent_msg.sender_msg_id.to_u32()) .set_config_u32(Config::LastMsgId, sent_msg.sender_msg_id.to_u32())

View File

@@ -638,7 +638,7 @@ mod tests {
let self_chat = ctx1.get_self_chat().await; let self_chat = ctx1.get_self_chat().await;
let msgs = get_chat_msgs(&ctx1, self_chat.id).await.unwrap(); let msgs = get_chat_msgs(&ctx1, self_chat.id).await.unwrap();
assert_eq!(msgs.len(), 2); assert_eq!(msgs.len(), 2);
let msgid = match msgs.get(0).unwrap() { let msgid = match msgs.first().unwrap() {
ChatItem::Message { msg_id } => msg_id, ChatItem::Message { msg_id } => msg_id,
_ => panic!("wrong chat item"), _ => panic!("wrong chat item"),
}; };

View File

@@ -954,7 +954,7 @@ Content-Disposition: attachment; filename="location.kml"
assert!(msg.chat_id == bob_chat_id); assert!(msg.chat_id == bob_chat_id);
assert_eq!(msg.msg_ids.len(), 1); assert_eq!(msg.msg_ids.len(), 1);
let bob_msg = Message::load_from_db(&bob, *msg.msg_ids.get(0).unwrap()).await?; let bob_msg = Message::load_from_db(&bob, *msg.msg_ids.first().unwrap()).await?;
assert_eq!(bob_msg.chat_id, bob_chat_id); assert_eq!(bob_msg.chat_id, bob_chat_id);
assert_eq!(bob_msg.viewtype, Viewtype::Image); assert_eq!(bob_msg.viewtype, Viewtype::Image);

View File

@@ -914,7 +914,7 @@ impl MimeMessage {
skip the rest. (see skip the rest. (see
<https://k9mail.app/2016/11/24/OpenPGP-Considerations-Part-I.html> <https://k9mail.app/2016/11/24/OpenPGP-Considerations-Part-I.html>
for background information why we use encrypted+signed) */ for background information why we use encrypted+signed) */
if let Some(first) = mail.subparts.get(0) { if let Some(first) = mail.subparts.first() {
any_part_added = self any_part_added = self
.parse_mime_recursive(context, first, is_related) .parse_mime_recursive(context, first, is_related)
.await?; .await?;
@@ -970,7 +970,7 @@ impl MimeMessage {
} }
} }
Some(_) => { Some(_) => {
if let Some(first) = mail.subparts.get(0) { if let Some(first) = mail.subparts.first() {
any_part_added = self any_part_added = self
.parse_mime_recursive(context, first, is_related) .parse_mime_recursive(context, first, is_related)
.await?; .await?;

View File

@@ -425,7 +425,7 @@ Content-Disposition: reaction\n\
let contacts = reactions.contacts(); let contacts = reactions.contacts();
assert_eq!(contacts.len(), 1); assert_eq!(contacts.len(), 1);
assert_eq!(contacts.get(0), Some(&bob_id)); assert_eq!(contacts.first(), Some(&bob_id));
let bob_reaction = reactions.get(bob_id); let bob_reaction = reactions.get(bob_id);
assert_eq!(bob_reaction.is_empty(), false); assert_eq!(bob_reaction.is_empty(), false);
assert_eq!(bob_reaction.emojis(), vec!["👍"]); assert_eq!(bob_reaction.emojis(), vec!["👍"]);
@@ -526,7 +526,7 @@ Here's my footer -- bob@example.net"
assert_eq!(reactions.to_string(), "👍1"); assert_eq!(reactions.to_string(), "👍1");
let contacts = reactions.contacts(); let contacts = reactions.contacts();
assert_eq!(contacts.len(), 1); assert_eq!(contacts.len(), 1);
let bob_id = contacts.get(0).unwrap(); let bob_id = contacts.first().unwrap();
let bob_reaction = reactions.get(*bob_id); let bob_reaction = reactions.get(*bob_id);
assert_eq!(bob_reaction.is_empty(), false); assert_eq!(bob_reaction.is_empty(), false);
assert_eq!(bob_reaction.emojis(), vec!["👍"]); assert_eq!(bob_reaction.emojis(), vec!["👍"]);
@@ -578,13 +578,13 @@ Here's my footer -- bob@example.net"
) )
.await? .await?
.unwrap(); .unwrap();
let alice_msg_id = *alice_received_message.msg_ids.get(0).unwrap(); let alice_msg_id = *alice_received_message.msg_ids.first().unwrap();
// Bob downloads own message on the other device. // Bob downloads own message on the other device.
let bob_received_message = receive_imf(&bob, msg_full.as_bytes(), false) let bob_received_message = receive_imf(&bob, msg_full.as_bytes(), false)
.await? .await?
.unwrap(); .unwrap();
let bob_msg_id = *bob_received_message.msg_ids.get(0).unwrap(); let bob_msg_id = *bob_received_message.msg_ids.first().unwrap();
// Bob reacts to own message. // Bob reacts to own message.
send_reaction(&bob, bob_msg_id, "👍").await.unwrap(); send_reaction(&bob, bob_msg_id, "👍").await.unwrap();

View File

@@ -315,7 +315,7 @@ pub(crate) async fn receive_imf_inner(
mime_parser.decryption_info.peerstate = mime_parser.decryption_info.peerstate =
Peerstate::from_addr(context, contact.get_addr()).await?; Peerstate::from_addr(context, contact.get_addr()).await?;
} else { } else {
let to_id = to_ids.get(0).copied().unwrap_or_default(); let to_id = to_ids.first().copied().unwrap_or_default();
// handshake may mark contacts as verified and must be processed before chats are created // handshake may mark contacts as verified and must be processed before chats are created
res = observe_securejoin_on_other_device(context, &mime_parser, to_id) res = observe_securejoin_on_other_device(context, &mime_parser, to_id)
.await .await
@@ -919,7 +919,7 @@ async fn add_parts(
// the mail is on the IMAP server, probably it is also delivered. // the mail is on the IMAP server, probably it is also delivered.
// We cannot recreate other states (read, error). // We cannot recreate other states (read, error).
state = MessageState::OutDelivered; state = MessageState::OutDelivered;
to_id = to_ids.get(0).copied().unwrap_or_default(); to_id = to_ids.first().copied().unwrap_or_default();
let self_sent = let self_sent =
from_id == ContactId::SELF && to_ids.len() == 1 && to_ids.contains(&ContactId::SELF); from_id == ContactId::SELF && to_ids.len() == 1 && to_ids.contains(&ContactId::SELF);

View File

@@ -447,7 +447,7 @@ mod tests {
)?; )?;
assert_eq!(sync_items.items.len(), 1); assert_eq!(sync_items.items.len(), 1);
let SyncDataOrUnknown::SyncData(AlterChat { id, action }) = let SyncDataOrUnknown::SyncData(AlterChat { id, action }) =
&sync_items.items.get(0).unwrap().data &sync_items.items.first().unwrap().data
else { else {
bail!("bad item"); bail!("bad item");
}; };
@@ -491,7 +491,7 @@ mod tests {
assert_eq!(sync_items.items.len(), 1); assert_eq!(sync_items.items.len(), 1);
if let SyncDataOrUnknown::SyncData(AddQrToken(token)) = if let SyncDataOrUnknown::SyncData(AddQrToken(token)) =
&sync_items.items.get(0).unwrap().data &sync_items.items.first().unwrap().data
{ {
assert_eq!(token.invitenumber, "in"); assert_eq!(token.invitenumber, "in");
assert_eq!(token.auth, "yip"); assert_eq!(token.auth, "yip");

View File

@@ -1241,7 +1241,7 @@ mod tests {
) )
.await? .await?
.unwrap(); .unwrap();
assert_eq!(*received_msg.msg_ids.get(0).unwrap(), bob_instance.id); assert_eq!(*received_msg.msg_ids.first().unwrap(), bob_instance.id);
let bob_instance = bob.get_last_msg().await; let bob_instance = bob.get_last_msg().await;
assert_eq!(bob_instance.viewtype, Viewtype::Webxdc); assert_eq!(bob_instance.viewtype, Viewtype::Webxdc);
assert_eq!(bob_instance.download_state, DownloadState::Done); assert_eq!(bob_instance.download_state, DownloadState::Done);