diff --git a/examples/e13_parallel_loops/src/main.rs b/examples/e13_parallel_loops/src/main.rs index 8f0d0a1ca9c..7a51ebde029 100644 --- a/examples/e13_parallel_loops/src/main.rs +++ b/examples/e13_parallel_loops/src/main.rs @@ -52,9 +52,7 @@ impl EventHandler for Handler { // the application. tokio::spawn(async move { loop { - // We clone Context again here, because Arc is owned, so it moves to the - // new function. - log_system_load(Arc::clone(&ctx1)).await; + log_system_load(&ctx1).await; tokio::time::sleep(Duration::from_secs(120)).await; } }); @@ -63,7 +61,7 @@ impl EventHandler for Handler { let ctx2 = Arc::clone(&ctx); tokio::spawn(async move { loop { - set_activity_to_current_time(Arc::clone(&ctx2)).await; + set_activity_to_current_time(&ctx2); tokio::time::sleep(Duration::from_secs(60)).await; } }); @@ -74,7 +72,7 @@ impl EventHandler for Handler { } } -async fn log_system_load(ctx: Arc) { +async fn log_system_load(ctx: &Context) { let cpu_load = sys_info::loadavg().unwrap(); let mem_use = sys_info::mem_info().unwrap(); @@ -99,11 +97,11 @@ async fn log_system_load(ctx: Arc) { }; } -async fn set_activity_to_current_time(ctx: Arc) { +fn set_activity_to_current_time(ctx: &Context) { let current_time = Utc::now(); let formatted_time = current_time.to_rfc2822(); - ctx.set_activity(Some(ActivityData::playing(formatted_time))).await; + ctx.set_activity(Some(ActivityData::playing(formatted_time))); } #[tokio::main] diff --git a/src/client/context.rs b/src/client/context.rs index d10b5f0fdff..45cc5ad222c 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -107,7 +107,7 @@ impl Context { /// impl EventHandler for Handler { /// async fn message(&self, ctx: Context, msg: Message) { /// if msg.content == "!online" { - /// ctx.online().await; + /// ctx.online(); /// } /// } /// } @@ -123,9 +123,8 @@ impl Context { /// /// [`Online`]: OnlineStatus::Online #[cfg(feature = "gateway")] - #[allow(clippy::unused_async)] #[inline] - pub async fn online(&self) { + pub fn online(&self) { self.shard.set_status(OnlineStatus::Online); } @@ -146,7 +145,7 @@ impl Context { /// impl EventHandler for Handler { /// async fn message(&self, ctx: Context, msg: Message) { /// if msg.content == "!idle" { - /// ctx.idle().await; + /// ctx.idle(); /// } /// } /// } @@ -162,9 +161,8 @@ impl Context { /// /// [`Idle`]: OnlineStatus::Idle #[cfg(feature = "gateway")] - #[allow(clippy::unused_async)] #[inline] - pub async fn idle(&self) { + pub fn idle(&self) { self.shard.set_status(OnlineStatus::Idle); } @@ -185,7 +183,7 @@ impl Context { /// impl EventHandler for Handler { /// async fn message(&self, ctx: Context, msg: Message) { /// if msg.content == "!dnd" { - /// ctx.dnd().await; + /// ctx.dnd(); /// } /// } /// } @@ -201,9 +199,8 @@ impl Context { /// /// [`DoNotDisturb`]: OnlineStatus::DoNotDisturb #[cfg(feature = "gateway")] - #[allow(clippy::unused_async)] #[inline] - pub async fn dnd(&self) { + pub fn dnd(&self) { self.shard.set_status(OnlineStatus::DoNotDisturb); } @@ -224,7 +221,7 @@ impl Context { /// #[serenity::async_trait] /// impl EventHandler for Handler { /// async fn ready(&self, ctx: Context, _: Ready) { - /// ctx.invisible().await; + /// ctx.invisible(); /// } /// } /// @@ -240,9 +237,8 @@ impl Context { /// [`Event::Ready`]: crate::model::event::Event::Ready /// [`Invisible`]: OnlineStatus::Invisible #[cfg(feature = "gateway")] - #[allow(clippy::unused_async)] #[inline] - pub async fn invisible(&self) { + pub fn invisible(&self) { self.shard.set_status(OnlineStatus::Invisible); } @@ -264,7 +260,7 @@ impl Context { /// #[serenity::async_trait] /// impl EventHandler for Handler { /// async fn resume(&self, ctx: Context, _: ResumedEvent) { - /// ctx.reset_presence().await; + /// ctx.reset_presence(); /// } /// } /// @@ -280,9 +276,8 @@ impl Context { /// [`Event::Resumed`]: crate::model::event::Event::Resumed /// [`Online`]: OnlineStatus::Online #[cfg(feature = "gateway")] - #[allow(clippy::unused_async)] #[inline] - pub async fn reset_presence(&self) { + pub fn reset_presence(&self) { self.shard.set_presence(None, OnlineStatus::Online); } @@ -307,7 +302,7 @@ impl Context { /// let mut args = msg.content.splitn(2, ' '); /// /// if let (Some("~setgame"), Some(game)) = (args.next(), args.next()) { - /// ctx.set_activity(Some(ActivityData::playing(game))).await; + /// ctx.set_activity(Some(ActivityData::playing(game))); /// } /// } /// } @@ -321,9 +316,8 @@ impl Context { /// # } /// ``` #[cfg(feature = "gateway")] - #[allow(clippy::unused_async)] #[inline] - pub async fn set_activity(&self, activity: Option) { + pub fn set_activity(&self, activity: Option) { self.shard.set_activity(activity); } @@ -391,36 +385,32 @@ impl Context { /// [`DoNotDisturb`]: OnlineStatus::DoNotDisturb /// [`Idle`]: OnlineStatus::Idle #[cfg(feature = "gateway")] - #[allow(clippy::unused_async)] #[inline] - pub async fn set_presence(&self, activity: Option, status: OnlineStatus) { + pub fn set_presence(&self, activity: Option, status: OnlineStatus) { self.shard.set_presence(activity, status); } /// Sets a new `filter` for the shard to check if a message event shall be /// sent back to `filter`'s paired receiver. #[cfg(feature = "collector")] - #[allow(clippy::unused_async)] #[inline] - pub async fn set_message_filter(&self, filter: MessageFilter) { + pub fn set_message_filter(&self, filter: MessageFilter) { self.shard.set_message_filter(filter); } /// Sets a new `filter` for the shard to check if a reaction event shall be /// sent back to `filter`'s paired receiver. #[cfg(feature = "collector")] - #[allow(clippy::unused_async)] #[inline] - pub async fn set_reaction_filter(&self, filter: ReactionFilter) { + pub fn set_reaction_filter(&self, filter: ReactionFilter) { self.shard.set_reaction_filter(filter); } /// Sets a new `filter` for the shard to check if an interaction event shall be /// sent back to `filter`'s paired receiver. #[cfg(feature = "collector")] - #[allow(clippy::unused_async)] #[inline] - pub async fn set_component_interaction_filter(&self, filter: ComponentInteractionFilter) { + pub fn set_component_interaction_filter(&self, filter: ComponentInteractionFilter) { self.shard.set_component_interaction_filter(filter); } } diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index fb65d6e5763..f22f5a202ea 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -517,8 +517,7 @@ impl ChannelId { /// Returns the name of whatever channel this id holds. #[cfg(feature = "cache")] - #[allow(clippy::unused_async)] - pub async fn name(self, cache: impl AsRef) -> Option { + pub fn name(self, cache: impl AsRef) -> Option { let channel = self.to_channel_cached(cache)?; Some(match channel { diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index d7b99a9739f..49cabb076ac 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -371,8 +371,8 @@ impl Guild { /// Returns the "default" channel of the guild for the passed user id. /// (This returns the first channel that can be read by the user, if there isn't one, /// returns [`None`]) - #[allow(clippy::unused_async)] - pub async fn default_channel(&self, uid: UserId) -> Option<&GuildChannel> { + #[must_use] + pub fn default_channel(&self, uid: UserId) -> Option<&GuildChannel> { let member = self.members.get(&uid)?; for channel in self.channels.values() { if let Channel::Guild(channel) = channel { diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index 37277098b21..2ba730ebb0b 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -960,18 +960,17 @@ impl PartialGuild { /// [`position`]: Role::position #[cfg(feature = "cache")] #[inline] - pub async fn greater_member_hierarchy( + pub fn greater_member_hierarchy( &self, cache: impl AsRef, lhs_id: impl Into, rhs_id: impl Into, ) -> Option { - self._greater_member_hierarchy(&cache, lhs_id.into(), rhs_id.into()).await + self._greater_member_hierarchy(&cache, lhs_id.into(), rhs_id.into()) } #[cfg(feature = "cache")] - #[allow(clippy::unused_async)] - async fn _greater_member_hierarchy( + fn _greater_member_hierarchy( &self, cache: impl AsRef, lhs_id: UserId, diff --git a/src/model/user.rs b/src/model/user.rs index 68c82c303d5..41690f4f974 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -1073,9 +1073,8 @@ impl UserId { /// Attempts to find a [`User`] by its Id in the cache. #[cfg(feature = "cache")] - #[allow(clippy::unused_async)] #[inline] - pub async fn to_user_cached(self, cache: &impl AsRef) -> Option> { + pub fn to_user_cached(self, cache: &impl AsRef) -> Option> { cache.as_ref().user(self) }