From: dullbananas Date: Wed, 28 Jun 2023 09:19:26 +0000 (-0700) Subject: Remove redundant calls to `Iterator::collect` (#3365) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%7B?a=commitdiff_plain;h=bef76630c5d74805ff367bfab787d72498b6927d;p=lemmy.git Remove redundant calls to `Iterator::collect` (#3365) * Remove redundant calls to `Iterator::collect` * Update mentions.rs * Add clippy lints and run fmt * CI ran on the wrong commit again  --- diff --git a/.woodpecker.yml b/.woodpecker.yml index c2f6505c..ec3436de 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -60,6 +60,9 @@ pipeline: -D clippy::unused_self -A clippy::uninlined_format_args -D clippy::get_first + -D clippy::explicit_into_iter_loop + -D clippy::explicit_iter_loop + -D clippy::needless_collect - cargo clippy --workspace --features console -- -D clippy::unwrap_used -D clippy::indexing_slicing diff --git a/crates/api_common/src/build_response.rs b/crates/api_common/src/build_response.rs index 374a74d9..328827b2 100644 --- a/crates/api_common/src/build_response.rs +++ b/crates/api_common/src/build_response.rs @@ -98,7 +98,6 @@ pub async fn send_local_notifs( for mention in mentions .iter() .filter(|m| m.is_local(&context.settings().hostname) && m.name.ne(&person.name)) - .collect::>() { let mention_name = mention.name.clone(); let user_view = LocalUserView::read_from_name(context.pool(), &mention_name).await; diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index b3b1efec..1bcc7848 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -191,7 +191,7 @@ impl PerformCrud for CreateComment { pub fn check_comment_depth(comment: &Comment) -> Result<(), LemmyError> { let path = &comment.path.0; - let length = path.split('.').collect::>().len(); + let length = path.split('.').count(); if length > MAX_COMMENT_DEPTH_LIMIT { Err(LemmyError::from_message("max_comment_depth_reached")) } else { diff --git a/crates/apub/src/activities/community/mod.rs b/crates/apub/src/activities/community/mod.rs index b770c47a..010bad4f 100644 --- a/crates/apub/src/activities/community/mod.rs +++ b/crates/apub/src/activities/community/mod.rs @@ -43,12 +43,11 @@ pub(crate) async fn send_activity_in_community( // send to user followers if !is_mod_action { - inboxes.append( + inboxes.extend( &mut PersonFollower::list_followers(context.pool(), actor.id) .await? .into_iter() - .map(|p| ApubPerson(p).shared_inbox_or_inbox()) - .collect(), + .map(|p| ApubPerson(p).shared_inbox_or_inbox()), ); } diff --git a/crates/apub/src/mentions.rs b/crates/apub/src/mentions.rs index 4de822cc..088f84d0 100644 --- a/crates/apub/src/mentions.rs +++ b/crates/apub/src/mentions.rs @@ -11,10 +11,7 @@ use lemmy_db_schema::{ traits::Crud, utils::DbPool, }; -use lemmy_utils::{ - error::LemmyError, - utils::mention::{scrape_text_for_mentions, MentionData}, -}; +use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions}; use serde::{Deserialize, Serialize}; use serde_json::Value; use url::Url; @@ -67,10 +64,9 @@ pub async fn collect_non_local_mentions( let mentions = scrape_text_for_mentions(&comment.content) .into_iter() // Filter only the non-local ones - .filter(|m| !m.is_local(&context.settings().hostname)) - .collect::>(); + .filter(|m| !m.is_local(&context.settings().hostname)); - for mention in &mentions { + for mention in mentions { let identifier = format!("{}@{}", mention.name, mention.domain); let person = webfinger_resolve_actor::(&identifier, context).await; if let Ok(person) = person { diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 8aa8c179..ea66347d 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -99,8 +99,7 @@ impl Comment { // left join comment c2 on c2.path <@ c.path and c2.path != c.path // group by c.id - let path_split = parent_path.0.split('.').collect::>(); - let parent_id = path_split.get(1); + let parent_id = parent_path.0.split('.').nth(1); if let Some(parent_id) = parent_id { let top_parent = format!("0.{}", parent_id); diff --git a/scripts/fix-clippy.sh b/scripts/fix-clippy.sh index 25b4b22c..759de577 100755 --- a/scripts/fix-clippy.sh +++ b/scripts/fix-clippy.sh @@ -14,7 +14,10 @@ cargo clippy --workspace --fix --allow-staged --allow-dirty --tests --all-target -D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls \ -D clippy::unused_self \ -A clippy::uninlined_format_args \ - -D clippy::get_first + -D clippy::get_first \ + -D clippy::explicit_into_iter_loop \ + -D clippy::explicit_iter_loop \ + -D clippy::needless_collect cargo clippy --workspace --features console -- \ -D clippy::unwrap_used \