]> Untitled Git - lemmy.git/commitdiff
Remove redundant calls to `Iterator::collect` (#3365)
authordullbananas <dull.bananas0@gmail.com>
Wed, 28 Jun 2023 09:19:26 +0000 (02:19 -0700)
committerGitHub <noreply@github.com>
Wed, 28 Jun 2023 09:19:26 +0000 (11:19 +0200)
* Remove redundant calls to `Iterator::collect`

* Update mentions.rs

* Add clippy lints and run fmt

* CI ran on the wrong commit again 

.woodpecker.yml
crates/api_common/src/build_response.rs
crates/api_crud/src/comment/create.rs
crates/apub/src/activities/community/mod.rs
crates/apub/src/mentions.rs
crates/db_schema/src/impls/comment.rs
scripts/fix-clippy.sh

index c2f6505c98fe02744ecbb70713f82a25d9103387..ec3436def1c195947b8000a61def1cb801ae192d 100644 (file)
@@ -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
index 374a74d9110359bf021ac06211eeb08a9f3d4890..328827b2ce99a720859e7cf7be23f7c5f4c77a3f 100644 (file)
@@ -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::<Vec<&MentionData>>()
   {
     let mention_name = mention.name.clone();
     let user_view = LocalUserView::read_from_name(context.pool(), &mention_name).await;
index b3b1efecd60d2cb025ca1c6204dc01234d05ed0e..1bcc78483c3b8659ab81c3df51164051446551ef 100644 (file)
@@ -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::<Vec<&str>>().len();
+  let length = path.split('.').count();
   if length > MAX_COMMENT_DEPTH_LIMIT {
     Err(LemmyError::from_message("max_comment_depth_reached"))
   } else {
index b770c47ac6a09c60fac83f7386b6b5774d28a11c..010bad4f4ee2db7ae914d8339478a4e9b41df553 100644 (file)
@@ -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()),
     );
   }
 
index 4de822cc78796d0aeb070ad881927979c6b1aead..088f84d0dd1da579c1555206398b5d54d0ed6667 100644 (file)
@@ -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::<Vec<MentionData>>();
+    .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::<LemmyContext, ApubPerson>(&identifier, context).await;
     if let Ok(person) = person {
index 8aa8c1793c6726ab3ca4c1fbe3a6101d984e1526..ea66347dba69fb85a7a4e9a55f9b3e3b82788d87 100644 (file)
@@ -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::<Vec<&str>>();
-        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);
index 25b4b22ca6fb9dea18dc7697abfc13d681ede50c..759de577376e431b8529cacd988960406d34c44c 100755 (executable)
@@ -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 \