From f4c783cba5b3363508b8b0bc1c042f6dc835a8d6 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 12 Oct 2021 16:46:26 +0000 Subject: [PATCH] Fix clippy warnings added in nightly (#1833) --- crates/api/src/comment.rs | 2 +- crates/api/src/community.rs | 2 +- crates/api/src/local_user.rs | 2 +- crates/api/src/site.rs | 6 +++--- crates/api_crud/src/comment/create.rs | 2 +- crates/api_crud/src/site/create.rs | 2 +- crates/api_crud/src/site/read.rs | 8 ++++---- crates/api_crud/src/site/update.rs | 2 +- crates/apub/src/activities/voting/undo_vote.rs | 2 +- crates/apub/src/activities/voting/vote.rs | 2 +- crates/apub/src/fetcher/post_or_comment.rs | 16 +++++++--------- crates/routes/src/feeds.rs | 2 +- 12 files changed, 23 insertions(+), 25 deletions(-) diff --git a/crates/api/src/comment.rs b/crates/api/src/comment.rs index 1d1d3088f..951bd395f 100644 --- a/crates/api/src/comment.rs +++ b/crates/api/src/comment.rs @@ -188,7 +188,7 @@ impl Perform for CreateCommentLike { // Only add the like if the score isnt 0 let comment = orig_comment.comment; - let object = PostOrComment::Comment(Box::new(comment)); + let object = PostOrComment::Comment(comment); let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1); if do_add { let like_form2 = like_form.clone(); diff --git a/crates/api/src/community.rs b/crates/api/src/community.rs index 28a79c701..f4548be6d 100644 --- a/crates/api/src/community.rs +++ b/crates/api/src/community.rs @@ -409,7 +409,7 @@ impl Perform for TransferCommunity { }) .await??; - let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??; + let mut admins = blocking(context.pool(), PersonViewSafe::admins).await??; // Making sure the site creator, if an admin, is at the top let creator_index = admins diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index 930be955d..ff732e6bb 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -375,7 +375,7 @@ impl Perform for AddAdmin { }) .await??; - let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??; + let mut admins = blocking(context.pool(), PersonViewSafe::admins).await??; let creator_index = admins .iter() .position(|r| r.person.id == site_creator_id) diff --git a/crates/api/src/site.rs b/crates/api/src/site.rs index 01f7b45f1..a8d2e7338 100644 --- a/crates/api/src/site.rs +++ b/crates/api/src/site.rs @@ -472,9 +472,9 @@ impl Perform for TransferSite { blocking(context.pool(), move |conn| ModAdd::create(conn, &form)).await??; - let site_view = blocking(context.pool(), move |conn| SiteView::read(conn)).await??; + let site_view = blocking(context.pool(), SiteView::read).await??; - let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??; + let mut admins = blocking(context.pool(), PersonViewSafe::admins).await??; let creator_index = admins .iter() .position(|r| r.person.id == site_view.creator.id) @@ -482,7 +482,7 @@ impl Perform for TransferSite { let creator_person = admins.remove(creator_index); admins.insert(0, creator_person); - let banned = blocking(context.pool(), move |conn| PersonViewSafe::banned(conn)).await??; + let banned = blocking(context.pool(), PersonViewSafe::banned).await??; let federated_instances = build_federated_instances( context.pool(), &context.settings().federation, diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index 7d49fe134..c357e6047 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -146,7 +146,7 @@ impl PerformCrud for CreateComment { return Err(ApiError::err("couldnt_like_comment").into()); } - let object = PostOrComment::Comment(Box::new(updated_comment)); + let object = PostOrComment::Comment(updated_comment); Vote::send( &object, &local_user_view.person, diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index 8038f62cb..658d4cf8f 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -76,7 +76,7 @@ impl PerformCrud for CreateSite { return Err(ApiError::err("site_already_exists").into()); } - let site_view = blocking(context.pool(), move |conn| SiteView::read(conn)).await??; + let site_view = blocking(context.pool(), SiteView::read).await??; Ok(SiteResponse { site_view }) } diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index 2668939ef..88c6e6ea3 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -30,7 +30,7 @@ impl PerformCrud for GetSite { ) -> Result { let data: &GetSite = self; - let site_view = match blocking(context.pool(), move |conn| SiteView::read(conn)).await? { + let site_view = match blocking(context.pool(), SiteView::read).await? { Ok(site_view) => Some(site_view), // If the site isn't created yet, check the setup Err(_) => { @@ -62,14 +62,14 @@ impl PerformCrud for GetSite { }; create_site.perform(context, websocket_id).await?; info!("Site {} created", setup.site_name); - Some(blocking(context.pool(), move |conn| SiteView::read(conn)).await??) + Some(blocking(context.pool(), SiteView::read).await??) } else { None } } }; - let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??; + let mut admins = blocking(context.pool(), PersonViewSafe::admins).await??; // Make sure the site creator is the top admin if let Some(site_view) = site_view.to_owned() { @@ -82,7 +82,7 @@ impl PerformCrud for GetSite { } } - let banned = blocking(context.pool(), move |conn| PersonViewSafe::banned(conn)).await??; + let banned = blocking(context.pool(), PersonViewSafe::banned).await??; let online = context .chat_server() diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index b92cfd4a1..2190d02c3 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -69,7 +69,7 @@ impl PerformCrud for EditSite { return Err(ApiError::err("couldnt_update_site").into()); } - let site_view = blocking(context.pool(), move |conn| SiteView::read(conn)).await??; + let site_view = blocking(context.pool(), SiteView::read).await??; let res = SiteResponse { site_view }; diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index d59db4a4d..bfb74371d 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -115,7 +115,7 @@ impl ActivityHandler for UndoVote { .await?; match object { PostOrComment::Post(p) => undo_vote_post(actor, p.deref(), context).await, - PostOrComment::Comment(c) => undo_vote_comment(actor, c.deref(), context).await, + PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await, } } } diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index a68631759..4d8537546 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -134,7 +134,7 @@ impl ActivityHandler for Vote { let object = self.object.dereference(context, request_counter).await?; match object { PostOrComment::Post(p) => vote_post(&self.kind, actor, p.deref(), context).await, - PostOrComment::Comment(c) => vote_comment(&self.kind, actor, c.deref(), context).await, + PostOrComment::Comment(c) => vote_comment(&self.kind, actor, &c, context).await, } } } diff --git a/crates/apub/src/fetcher/post_or_comment.rs b/crates/apub/src/fetcher/post_or_comment.rs index 7971cedba..ff07024fc 100644 --- a/crates/apub/src/fetcher/post_or_comment.rs +++ b/crates/apub/src/fetcher/post_or_comment.rs @@ -13,19 +13,19 @@ use url::Url; #[derive(Clone, Debug)] pub enum PostOrComment { - Comment(Box), Post(Box), + Comment(Comment), } pub enum PostOrCommentForm { - PostForm(PostForm), + PostForm(Box), CommentForm(CommentForm), } #[derive(Deserialize)] pub enum PageOrNote { - Page(Page), - Note(Note), + Page(Box), + Note(Box), } #[async_trait::async_trait(?Send)] @@ -44,9 +44,7 @@ impl ApubObject for PostOrComment { let post = Post::read_from_apub_id(conn, object_id.clone())?; Ok(match post { Some(o) => Some(PostOrComment::Post(Box::new(o))), - None => { - Comment::read_from_apub_id(conn, object_id)?.map(|c| PostOrComment::Comment(Box::new(c))) - } + None => Comment::read_from_apub_id(conn, object_id)?.map(PostOrComment::Comment), }) } } @@ -68,9 +66,9 @@ impl FromApub for PostOrComment { PageOrNote::Page(p) => PostOrComment::Post(Box::new( Post::from_apub(p, context, expected_domain, request_counter).await?, )), - PageOrNote::Note(n) => PostOrComment::Comment(Box::new( + PageOrNote::Note(n) => PostOrComment::Comment( Comment::from_apub(n, context, expected_domain, request_counter).await?, - )), + ), }) } } diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 66e23ee3e..a02b5fe33 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -83,7 +83,7 @@ async fn get_feed_data( listing_type: ListingType, sort_type: SortType, ) -> Result { - let site_view = blocking(context.pool(), move |conn| SiteView::read(conn)).await??; + let site_view = blocking(context.pool(), SiteView::read).await??; let posts = blocking(context.pool(), move |conn| { PostQueryBuilder::create(conn)