From c5eb108549b320a0db2f01e79ec862c868e0bd0d Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Mon, 19 Aug 2024 21:56:28 -0400 Subject: [PATCH] Fix unused warnings when model feature is disabled --- src/builder/create_attachment.rs | 1 + src/builder/edit_role.rs | 1 - src/builder/get_messages.rs | 1 + src/gateway/sharding/mod.rs | 1 + src/http/client.rs | 1 + src/internal/prelude.rs | 7 ++++--- src/internal/utils.rs | 2 +- src/model/channel/channel_id.rs | 2 +- src/model/channel/guild_channel.rs | 1 + src/model/channel/message.rs | 1 + src/model/channel/mod.rs | 1 + src/model/channel/private_channel.rs | 2 +- src/model/channel/reaction.rs | 1 + src/model/error.rs | 2 ++ src/model/guild/guild_id.rs | 2 ++ src/model/guild/mod.rs | 5 ++++- src/model/guild/partial_guild.rs | 4 +++- src/model/mention.rs | 5 +++-- src/model/misc.rs | 3 ++- src/utils/formatted_timestamp.rs | 7 ++++--- 20 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/builder/create_attachment.rs b/src/builder/create_attachment.rs index 0a016b25b86..d8728ea166c 100644 --- a/src/builder/create_attachment.rs +++ b/src/builder/create_attachment.rs @@ -250,6 +250,7 @@ impl<'a> EditAttachments<'a> { /// Clones all new attachments into a new Vec, keeping only data and filename, because those /// are needed for the multipart form data. The data is taken out of `self` in the process, so /// this method can only be called once. + #[cfg(feature = "http")] pub(crate) fn take_files(&mut self) -> Vec> { let mut files = Vec::new(); for attachment in &mut self.new_and_existing_attachments { diff --git a/src/builder/edit_role.rs b/src/builder/edit_role.rs index 84e4be4ea0f..feb2c08f548 100644 --- a/src/builder/edit_role.rs +++ b/src/builder/edit_role.rs @@ -3,7 +3,6 @@ use std::borrow::Cow; use super::CreateAttachment; #[cfg(feature = "http")] use crate::http::Http; -use crate::internal::prelude::*; use crate::model::prelude::*; /// A builder to create or edit a [`Role`] for use via a number of model methods. diff --git a/src/builder/get_messages.rs b/src/builder/get_messages.rs index 89b6c07ae61..293bed2555c 100644 --- a/src/builder/get_messages.rs +++ b/src/builder/get_messages.rs @@ -121,6 +121,7 @@ impl GetMessages { } } +#[cfg_attr(not(feature = "http"), allow(dead_code))] #[derive(Clone, Copy, Debug)] enum SearchFilter { After(MessageId), diff --git a/src/gateway/sharding/mod.rs b/src/gateway/sharding/mod.rs index 4f5248fa1ea..388a15b7d25 100644 --- a/src/gateway/sharding/mod.rs +++ b/src/gateway/sharding/mod.rs @@ -42,6 +42,7 @@ use std::fmt; use std::sync::Arc; use std::time::{Duration as StdDuration, Instant}; +use aformat::{aformat, CapStr}; use secrecy::{ExposeSecret as _, Secret}; use tokio_tungstenite::tungstenite::error::Error as TungsteniteError; use tokio_tungstenite::tungstenite::protocol::frame::CloseFrame; diff --git a/src/http/client.rs b/src/http/client.rs index 6f09f53f817..d6c27f67443 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -5,6 +5,7 @@ use std::cell::Cell; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; +use aformat::{aformat, CapStr}; use arrayvec::ArrayVec; use nonmax::{NonMaxU16, NonMaxU8}; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; diff --git a/src/internal/prelude.rs b/src/internal/prelude.rs index 82a62d064c8..c0799ad98a2 100644 --- a/src/internal/prelude.rs +++ b/src/internal/prelude.rs @@ -4,13 +4,14 @@ pub use std::result::Result as StdResult; -pub use aformat::{aformat, aformat_into, ArrayString, CapStr}; pub use extract_map::{ExtractKey, ExtractMap, LendingIterator}; pub use serde_json::Value; pub use small_fixed_array::{FixedArray, FixedString, TruncatingInto}; pub use to_arraystring::ToArrayString; -pub(crate) use super::utils::join_to_string; -pub use crate::error::{Error, Result}; +pub use super::utils::join_to_string; +#[cfg(feature = "http")] +pub use crate::error::Error; +pub use crate::error::Result; pub type JsonMap = serde_json::Map; diff --git a/src/internal/utils.rs b/src/internal/utils.rs index 53e35b9391c..9d22425051d 100644 --- a/src/internal/utils.rs +++ b/src/internal/utils.rs @@ -1,6 +1,6 @@ use std::fmt::Write; -pub(crate) fn join_to_string( +pub fn join_to_string( sep: impl std::fmt::Display, iter: impl IntoIterator, ) -> String { diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index 8454489c469..9dffb8bbd7f 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "model")] use std::borrow::Cow; #[cfg(feature = "model")] use std::sync::Arc; @@ -28,7 +29,6 @@ use crate::collector::{MessageCollector, ReactionCollector}; use crate::gateway::ShardMessenger; #[cfg(feature = "model")] use crate::http::{CacheHttp, Http, Typing}; -use crate::internal::prelude::*; use crate::model::prelude::*; #[cfg(feature = "model")] diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index cdffbeb4949..f3ec4e6d761 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "model")] use std::borrow::Cow; use std::fmt; #[cfg(feature = "model")] diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 2370fb01445..38ea95c5264 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -1,5 +1,6 @@ //! Models relating to Discord channels. +#[cfg(feature = "model")] use std::borrow::Cow; use nonmax::NonMaxU64; diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index 6f1dfd1259f..41f04e64064 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -15,6 +15,7 @@ use serde::de::{Error as DeError, Unexpected}; use serde_json::from_value; pub use self::attachment::*; +#[cfg(feature = "model")] pub use self::channel_id::*; pub use self::embed::*; pub use self::guild_channel::*; diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index b979de19a1f..4c0f88e347b 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "model")] use std::borrow::Cow; use std::fmt; #[cfg(feature = "model")] @@ -9,7 +10,6 @@ use crate::builder::{CreateAttachment, CreateMessage, EditMessage, GetMessages}; use crate::http::CacheHttp; #[cfg(feature = "model")] use crate::http::{Http, Typing}; -use crate::internal::prelude::*; use crate::model::prelude::*; use crate::model::utils::single_recipient; diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs index b6529a67417..a7060589218 100644 --- a/src/model/channel/reaction.rs +++ b/src/model/channel/reaction.rs @@ -4,6 +4,7 @@ use std::fmt::Display as _; use std::fmt::{self, Write as _}; use std::str::FromStr; +#[cfg(feature = "model")] use nonmax::NonMaxU8; #[cfg(feature = "http")] use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; diff --git a/src/model/error.rs b/src/model/error.rs index 9bbaf3f78d4..29192d178db 100644 --- a/src/model/error.rs +++ b/src/model/error.rs @@ -16,6 +16,7 @@ pub enum Maximum { BulkDeleteAmount, } +#[cfg(feature = "http")] impl Maximum { pub(crate) fn check_overflow(self, value: usize) -> Result<(), Error> { let max = self.value(); @@ -64,6 +65,7 @@ pub enum Minimum { BulkDeleteAmount, } +#[cfg(feature = "http")] impl Minimum { pub(crate) fn check_underflow(self, value: usize) -> Result<(), Error> { let min = self.value(); diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index 4f6dc47c34e..28b86e8d5d6 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -2,6 +2,7 @@ use std::fmt; #[cfg(feature = "model")] use futures::stream::Stream; +#[cfg(feature = "model")] use nonmax::{NonMaxU16, NonMaxU8}; #[cfg(feature = "model")] @@ -31,6 +32,7 @@ use crate::gateway::ShardMessenger; use crate::http::{CacheHttp, Http, UserPagination}; #[cfg(feature = "model")] use crate::internal::prelude::*; +#[cfg(feature = "model")] use crate::model::error::Maximum; use crate::model::prelude::*; diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 481dcbaa1cb..8a6f47a1f36 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -17,7 +17,9 @@ mod welcome_screen; #[cfg(feature = "model")] use std::borrow::Cow; -use nonmax::{NonMaxU16, NonMaxU64, NonMaxU8}; +use nonmax::NonMaxU64; +#[cfg(feature = "model")] +use nonmax::{NonMaxU16, NonMaxU8}; #[cfg(feature = "model")] use tracing::{error, warn}; @@ -59,6 +61,7 @@ use crate::gateway::ShardMessenger; use crate::http::{CacheHttp, Http, UserPagination}; use crate::internal::prelude::*; use crate::model::prelude::*; +#[cfg(feature = "model")] use crate::model::utils::*; /// A representation of a banning of a user. diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index 462bf4f979a..2288a7ab45d 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -1,4 +1,6 @@ -use nonmax::{NonMaxU16, NonMaxU64, NonMaxU8}; +use nonmax::NonMaxU64; +#[cfg(feature = "model")] +use nonmax::{NonMaxU16, NonMaxU8}; use serde::Serialize; #[cfg(feature = "model")] diff --git a/src/model/mention.rs b/src/model/mention.rs index ecda0701a03..3e2027db1d0 100644 --- a/src/model/mention.rs +++ b/src/model/mention.rs @@ -4,8 +4,9 @@ use std::fmt; #[cfg(all(feature = "model", feature = "utils"))] use std::str::FromStr; +use aformat::{aformat_into, ArrayString, ToArrayString}; + use super::prelude::*; -use crate::internal::prelude::*; #[cfg(all(feature = "model", feature = "utils"))] use crate::utils; @@ -113,7 +114,7 @@ impl fmt::Display for Mention { impl ToArrayString for Mention { const MAX_LENGTH: usize = 20 + 4; - type ArrayString = ArrayString<{ 20 + 4 }>; + type ArrayString = ArrayString<{ Self::MAX_LENGTH }>; fn to_arraystring(self) -> Self::ArrayString { let mut out = Self::ArrayString::new(); diff --git a/src/model/misc.rs b/src/model/misc.rs index 0ccf69d2d58..425ec62c1e1 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -8,8 +8,9 @@ use std::fmt::Write; use std::result::Result as StdResult; use std::str::FromStr; +use aformat::ArrayString; + use super::prelude::*; -use crate::internal::prelude::*; #[cfg(all(feature = "model", any(feature = "cache", feature = "utils")))] use crate::utils; diff --git a/src/utils/formatted_timestamp.rs b/src/utils/formatted_timestamp.rs index 6c1343cdc64..025fdca380f 100644 --- a/src/utils/formatted_timestamp.rs +++ b/src/utils/formatted_timestamp.rs @@ -2,10 +2,9 @@ use std::error::Error as StdError; use std::fmt; use std::str::FromStr; -use aformat::{ArrayString, ToArrayString}; +use aformat::{aformat_into, ArrayString, ToArrayString}; -use crate::all::Timestamp; -use crate::internal::prelude::*; +use crate::model::Timestamp; /// Represents a combination of a timestamp and a style for formatting time in messages. /// @@ -195,6 +194,8 @@ impl FromStr for FormattedTimestampStyle { #[cfg(test)] mod tests { + use aformat::aformat; + use super::*; #[test]