From e231cf903bbd7bdafcd8bb186c2c95795cf14104 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Sat, 27 May 2023 17:23:31 -0600 Subject: [PATCH] autofix cargo clippy lints --- src/discord.rs | 33 +++++++++++++-------------------- src/greendragon.rs | 6 +++--- src/lab.rs | 10 +++++----- src/storage.rs | 6 +++--- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/discord.rs b/src/discord.rs index dfd57e6..79f2200 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -277,7 +277,7 @@ impl BlamelistCache { // iteration of this loop. If that happens, eh. It's a race anyway. } Entry::Vacant(x) => { - x.insert(storage.find_userids_for(&email)?); + x.insert(storage.find_userids_for(email)?); } } } @@ -295,10 +295,10 @@ impl BlamelistCache { let mut emails: Vec<&Email> = Vec::new(); let mut user_ids: HashSet = HashSet::new(); for email in blamelist { - let users_to_ping = self.email_id_mappings.get(&email).unwrap(); + let users_to_ping = self.email_id_mappings.get(email).unwrap(); let mut pinged_anyone = false; for u in users_to_ping { - if guild_members.contains_key(&u) { + if guild_members.contains_key(u) { pinged_anyone = true; user_ids.insert(*u); } @@ -337,7 +337,7 @@ fn url_escape_bot_name(bot_name: &str) -> Cow<'_, str> { if !bot_name.contains(' ') { Cow::Borrowed(bot_name) } else { - Cow::Owned(bot_name.replace(" ", "%20")) + Cow::Owned(bot_name.replace(' ', "%20")) } } @@ -379,7 +379,7 @@ impl ChannelServer { } self.status_channel - .edit_message(http, prev_data.id, |m| m.content(&*data)) + .edit_message(http, prev_data.id, |m| m.content(data)) .await?; prev_data.last_value = data.to_owned(); @@ -388,7 +388,7 @@ impl ChannelServer { let discord_message = self .status_channel - .send_message(http, |m| m.content(&*data)) + .send_message(http, |m| m.content(data)) .await?; existing_messages.push(ServerUIMessage { last_value: data.to_owned(), @@ -457,7 +457,7 @@ impl ChannelServer { http, &next_breakage.build.blamelist, self.guild, - &*self.storage, + &self.storage, ) .await?; } @@ -821,7 +821,7 @@ impl serenity::client::EventHandler for MessageHandler { loop { info!("Setting up serving for guild #{}", guild_id); if let Err(x) = server - .serve(&*http, &mut pubsub_reader, &mut should_exit) + .serve(&http, &mut pubsub_reader, &mut should_exit) .await { error!("Failed serving guild #{}: {}", guild_id, x); @@ -1019,7 +1019,7 @@ fn duration_to_shorthand(dur: chrono::Duration) -> String { let d = dur.num_days(); return format!("{} {}", d, if d == 1 { "day" } else { "days" }); } - return format!("{} weeks", dur.num_weeks()); + format!("{} weeks", dur.num_weeks()) } // Eh. @@ -1184,10 +1184,7 @@ impl StatusUIUpdater { for (category_name, bots) in categorized { let mut failed_bots: Vec<_> = bots .iter() - .filter_map(|(name, bot)| match &bot.status.first_failing_build { - None => None, - Some(x) => Some((*name, x.id, x.completion_time)), - }) + .filter_map(|(name, bot)| bot.status.first_failing_build.as_ref().map(|x| (*name, x.id, x.completion_time))) .collect(); if failed_bots.is_empty() { @@ -1294,11 +1291,7 @@ impl UpdateUIUpdater { .bots .iter() .filter_map(|(id, bot)| { - if let Some(x) = &bot.status.first_failing_build { - Some((id, x)) - } else { - None - } + bot.status.first_failing_build.as_ref().map(|x| (id, x)) }) .collect(); @@ -1351,8 +1344,8 @@ async fn draw_ui( looped_before = true; pubsub.publish( - Arc::new(status_ui.draw_ui_with_snapshot(&*snapshot)), - &update_ui.get_updates(&*snapshot), + Arc::new(status_ui.draw_ui_with_snapshot(&snapshot)), + &update_ui.get_updates(&snapshot), ); } } diff --git a/src/greendragon.rs b/src/greendragon.rs index 63ee98a..93aeb28 100644 --- a/src/greendragon.rs +++ b/src/greendragon.rs @@ -36,10 +36,10 @@ where .and_then(|x| x.error_for_status()) .with_context(|| format!("requesting {}", path))?; - Ok(resp + resp .json() .await - .with_context(|| format!("parsing {}", path))?) + .with_context(|| format!("parsing {}", path)) } #[derive(Copy, Clone, Eq, PartialEq, Debug)] @@ -51,7 +51,7 @@ enum Color { Yellow { flashing: bool }, } -const VALID_COLOR_VALUES: &'static [(&'static str, Color)] = &[ +const VALID_COLOR_VALUES: &[(&str, Color)] = &[ // All of the aborted builds I can find are colored grey on the UI, so. ("aborted", Color::Disabled), ("aborted_anime", Color::Disabled), diff --git a/src/lab.rs b/src/lab.rs index ec9f4e5..0b134e8 100644 --- a/src/lab.rs +++ b/src/lab.rs @@ -112,10 +112,10 @@ where Ok(x) => x, }; - return Ok(resp + return resp .json() .await - .with_context(|| format!("parsing {}", url))?); + .with_context(|| format!("parsing {}", url)); } } @@ -257,7 +257,7 @@ impl<'de> serde::de::Deserialize<'de> for RawBuildbotTime { where E: serde::de::Error, { - let secs = value as i64; + let secs = value; match chrono::NaiveDateTime::from_timestamp_opt(secs, 0) { Some(x) => Ok(RawBuildbotTime(x)), None => Err(E::custom(format!("{} is an invalid timestamp", value))), @@ -632,7 +632,7 @@ async fn resolve_builder_build_info( let most_recent_build = resolve_completed_lab_build(client, &info.most_recent_build).await?; let first_failing_build = match &info.first_failing_build { None => None, - Some(x) => Some(resolve_completed_lab_build(client, &x).await?), + Some(x) => Some(resolve_completed_lab_build(client, x).await?), }; Ok(Bot { category: determine_bot_category(bot_info) @@ -840,7 +840,7 @@ async fn perform_incremental_builder_sync( .pending_builds .iter() .cloned() - .filter(|x| !fetched_ids.contains(&x)), + .filter(|x| !fetched_ids.contains(x)), move |id| fetch_build_by_id(client.clone(), id), ) .await? diff --git a/src/storage.rs b/src/storage.rs index fbf9774..b491aae 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -171,7 +171,7 @@ mod test { { let emails = storage.find_emails_for(id).expect("failed fetching emails"); - assert_eq!(&emails, &[email.clone()]); + assert_eq!(&emails, &[email]); } } @@ -230,7 +230,7 @@ mod test { { let emails = storage.find_emails_for(id).expect("failed fetching emails"); - assert_eq!(&emails, &[email.clone()]); + assert_eq!(&emails, &[email]); } } @@ -253,7 +253,7 @@ mod test { for email in &emails { let db_ids = storage - .find_userids_for(&email) + .find_userids_for(email) .expect("failed fetching userids"); assert_eq!(&db_ids, &ids); }