Skip to content

Commit 33caa0e

Browse files
mkrasnitskiGnomedDev
authored andcommitted
Fix unused warnings when compiling without certain features (#2970)
This is mostly just clean up, moving things around and gating things behind features so that unused warnings in CI go away.
1 parent 25b9a4e commit 33caa0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+122
-211
lines changed

src/builder/create_attachment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ impl<'a> EditAttachments<'a> {
250250
/// Clones all new attachments into a new Vec, keeping only data and filename, because those
251251
/// are needed for the multipart form data. The data is taken out of `self` in the process, so
252252
/// this method can only be called once.
253+
#[cfg(feature = "http")]
253254
pub(crate) fn take_files(&mut self) -> Vec<CreateAttachment<'a>> {
254255
let mut files = Vec::new();
255256
for attachment in &mut self.new_and_existing_attachments {

src/builder/create_command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::borrow::Cow;
2+
use std::collections::HashMap;
23

34
#[cfg(feature = "http")]
45
use crate::http::Http;

src/builder/create_interaction_response.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::borrow::Cow;
2+
use std::collections::HashMap;
23

34
use serde_json::json;
45

src/builder/edit_message.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ impl<'a> EditMessage<'a> {
201201
self
202202
}
203203

204+
#[cfg(feature = "cache")]
204205
fn is_only_suppress_embeds(&self) -> bool {
205206
self.flags == Some(MessageFlags::SUPPRESS_EMBEDS)
206207
&& self.content.is_none()
@@ -234,6 +235,7 @@ impl<'a> EditMessage<'a> {
234235
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
235236
/// [`From<Embed>`]: CreateEmbed#impl-From<Embed>
236237
#[cfg(feature = "http")]
238+
#[cfg_attr(not(feature = "cache"), allow(unused_variables))]
237239
pub async fn execute(
238240
mut self,
239241
cache_http: impl CacheHttp,

src/builder/edit_role.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::borrow::Cow;
33
use super::CreateAttachment;
44
#[cfg(feature = "http")]
55
use crate::http::Http;
6-
use crate::internal::prelude::*;
76
use crate::model::prelude::*;
87

98
/// A builder to create or edit a [`Role`] for use via a number of model methods.

src/builder/get_messages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl GetMessages {
121121
}
122122
}
123123

124+
#[cfg_attr(not(feature = "http"), allow(dead_code))]
124125
#[derive(Clone, Copy, Debug)]
125126
enum SearchFilter {
126127
After(MessageId),

src/cache/event.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::{HashSet, VecDeque};
2-
use std::num::NonZeroU16;
32

43
use super::{Cache, CacheUpdate};
54
use crate::internal::prelude::*;
@@ -32,9 +31,8 @@ use crate::model::event::{
3231
VoiceChannelStatusUpdateEvent,
3332
VoiceStateUpdateEvent,
3433
};
35-
use crate::model::gateway::{Presence, ShardInfo};
34+
use crate::model::gateway::Presence;
3635
use crate::model::guild::{Guild, GuildMemberFlags, Member, MemberGeneratedFlags, Role};
37-
use crate::model::id::ShardId;
3836
use crate::model::user::{CurrentUser, OnlineStatus};
3937
use crate::model::voice::VoiceState;
4038

@@ -449,8 +447,7 @@ impl CacheUpdate for ReadyEvent {
449447
let mut guilds_to_remove = vec![];
450448
let ready_guilds_hashset =
451449
self.ready.guilds.iter().map(|status| status.id).collect::<HashSet<_>>();
452-
let shard_data =
453-
self.ready.shard.unwrap_or_else(|| ShardInfo::new(ShardId(1), NonZeroU16::MIN));
450+
let shard_data = self.ready.shard.unwrap_or_default();
454451

455452
for guild_entry in cache.guilds.iter() {
456453
let guild = guild_entry.key();

src/gateway/client/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use std::sync::OnceLock;
3535
use futures::channel::mpsc::UnboundedReceiver as Receiver;
3636
use futures::future::BoxFuture;
3737
use futures::StreamExt as _;
38-
use tracing::debug;
38+
use tracing::{debug, warn};
3939

4040
pub use self::context::Context;
4141
pub use self::event_handler::{EventHandler, FullEvent, RawEventHandler};
@@ -55,7 +55,6 @@ use crate::model::gateway::GatewayIntents;
5555
#[cfg(feature = "voice")]
5656
use crate::model::id::UserId;
5757
use crate::model::user::OnlineStatus;
58-
use crate::utils::check_shard_total;
5958

6059
/// A builder implementing [`IntoFuture`] building a [`Client`] to interact with Discord.
6160
#[must_use = "Builders do nothing unless they are awaited"]
@@ -762,3 +761,10 @@ impl Client {
762761
Ok(())
763762
}
764763
}
764+
765+
fn check_shard_total(total_shards: u16) -> NonZeroU16 {
766+
NonZeroU16::new(total_shards).unwrap_or_else(|| {
767+
warn!("Invalid shard total provided ({total_shards}), defaulting to 1");
768+
NonZeroU16::MIN
769+
})
770+
}

src/gateway/sharding/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use std::fmt;
4242
use std::sync::Arc;
4343
use std::time::{Duration as StdDuration, Instant};
4444

45+
use aformat::{aformat, CapStr};
4546
use secrecy::{ExposeSecret as _, Secret};
4647
use tokio_tungstenite::tungstenite::error::Error as TungsteniteError;
4748
use tokio_tungstenite::tungstenite::protocol::frame::CloseFrame;

src/gateway/sharding/shard_queuer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,14 @@ impl ShardQueuer {
207207

208208
#[cfg_attr(feature = "tracing_instrument", instrument(skip(self)))]
209209
async fn start(&mut self, shard_id: ShardId) -> Result<()> {
210+
let shard_info = ShardInfo {
211+
id: shard_id,
212+
total: self.shard_total,
213+
};
210214
let mut shard = Shard::new(
211215
Arc::clone(&self.ws_url),
212216
Arc::clone(self.http.token()),
213-
ShardInfo::new(shard_id, self.shard_total),
217+
shard_info,
214218
self.intents,
215219
self.presence.clone(),
216220
)

0 commit comments

Comments
 (0)