Skip to content

Commit

Permalink
Check for lints which change public API (#2999)
Browse files Browse the repository at this point in the history
This is fine to do on next, and fixed a couple things. I also swapped
the `allow`s for `expect`s because why not.
  • Loading branch information
GnomedDev committed Nov 13, 2024
1 parent 081aa59 commit daaae7b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cognitive-complexity-threshold = 20
avoid-breaking-exported-api = false
12 changes: 2 additions & 10 deletions src/gateway/client/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ macro_rules! event_handler {
$( #[deprecated = $deprecated] )?
async fn $method_name(&self, $($context: Context,)? $( $arg_name: $arg_type ),*) {
// Suppress unused argument warnings
#[allow(dropping_references, dropping_copy_types)]
drop(( $($context,)? $($arg_name),* ))
}
)*
Expand All @@ -43,10 +42,7 @@ macro_rules! event_handler {
/// in a timely manner. It is recommended to keep the runtime
/// complexity of the filter code low to avoid unnecessarily blocking
/// your bot.
fn filter_event(&self, context: &Context, event: &Event) -> bool {
// Suppress unused argument warnings
#[allow(dropping_references, dropping_copy_types)]
drop((context, event));
fn filter_event(&self, _context: &Context, _event: &Event) -> bool {
true
}
}
Expand Down Expand Up @@ -79,7 +75,6 @@ macro_rules! event_handler {
/// ```
#[must_use]
pub fn snake_case_name(&self) -> &'static str {
#[allow(deprecated)]
match self {
$(
$( #[cfg(feature = $feature)] )?
Expand All @@ -90,7 +85,6 @@ macro_rules! event_handler {

/// Runs the given [`EventHandler`]'s code for this event.
pub async fn dispatch(self, ctx: Context, handler: &dyn EventHandler) {
#[allow(deprecated)]
match self {
$(
$( #[cfg(feature = $feature)] )?
Expand Down Expand Up @@ -527,10 +521,8 @@ pub trait RawEventHandler: Send + Sync {
/// in a timely manner. It is recommended to keep the runtime
/// complexity of the filter code low to avoid unnecessarily blocking
/// your bot.
fn filter_event(&self, context: &Context, event: &Event) -> bool {
fn filter_event(&self, _context: &Context, _event: &Event) -> bool {
// Suppress unused argument warnings
#[allow(dropping_references, dropping_copy_types)]
drop((context, event));
true
}
}
4 changes: 2 additions & 2 deletions src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ impl<'a> Request<'a> {
}

#[must_use]
pub fn headers_ref(&self) -> &Option<Headers> {
&self.headers
pub fn headers_ref(&self) -> Option<&Headers> {
self.headers.as_ref()
}

#[must_use]
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
clippy::fallible_impl_from,
clippy::let_underscore_must_use,
clippy::format_push_string,
clippy::allow_attributes,
clippy::pedantic
)]
#![allow(
Expand All @@ -74,6 +75,7 @@
clippy::doc_markdown,
clippy::missing_panics_doc,
clippy::doc_link_with_quotes,
clippy::struct_field_names
)]
#![cfg_attr(test, allow(clippy::unwrap_used))]

Expand Down
4 changes: 2 additions & 2 deletions src/model/channel/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ impl ChannelId {

/// Same as [`Self::await_reply`].
#[cfg(feature = "collector")]
pub fn await_replies(&self, shard_messenger: ShardMessenger) -> MessageCollector {
pub fn await_replies(self, shard_messenger: ShardMessenger) -> MessageCollector {
self.await_reply(shard_messenger)
}

Expand All @@ -825,7 +825,7 @@ impl ChannelId {

/// Same as [`Self::await_reaction`].
#[cfg(feature = "collector")]
pub fn await_reactions(&self, shard_messenger: ShardMessenger) -> ReactionCollector {
pub fn await_reactions(self, shard_messenger: ShardMessenger) -> ReactionCollector {
self.await_reaction(shard_messenger)
}

Expand Down
2 changes: 1 addition & 1 deletion src/model/channel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ impl MessageId {
/// Returns a link referencing this message. When clicked, users will jump to the message. The
/// link will be valid for messages in either private channels or guilds.
#[must_use]
pub fn link(&self, channel_id: ChannelId, guild_id: Option<GuildId>) -> String {
pub fn link(self, channel_id: ChannelId, guild_id: Option<GuildId>) -> String {
if let Some(guild_id) = guild_id {
format!("https://discord.com/channels/{guild_id}/{channel_id}/{self}")
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ impl GuildId {

/// Gets the default permission role (@everyone) from the guild.
#[must_use]
pub fn everyone_role(&self) -> RoleId {
pub fn everyone_role(self) -> RoleId {
RoleId::from(self.get())
}

Expand Down Expand Up @@ -1410,7 +1410,7 @@ impl GuildId {

/// Same as [`Self::await_reply`].
#[cfg(feature = "collector")]
pub fn await_replies(&self, shard_messenger: ShardMessenger) -> MessageCollector {
pub fn await_replies(self, shard_messenger: ShardMessenger) -> MessageCollector {
self.await_reply(shard_messenger)
}

Expand All @@ -1423,7 +1423,7 @@ impl GuildId {

/// Same as [`Self::await_reaction`].
#[cfg(feature = "collector")]
pub fn await_reactions(&self, shard_messenger: ShardMessenger) -> ReactionCollector {
pub fn await_reactions(self, shard_messenger: ShardMessenger) -> ReactionCollector {
self.await_reaction(shard_messenger)
}

Expand Down
12 changes: 7 additions & 5 deletions src/model/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,20 @@ impl Timestamp {
}

#[must_use]
pub fn to_rfc3339(&self) -> Option<String> {
pub fn to_rfc3339(self) -> String {
#[cfg(feature = "chrono")]
let x = self.0.to_rfc3339_opts(SecondsFormat::Millis, true);
return self.0.to_rfc3339_opts(SecondsFormat::Millis, true);
#[cfg(not(feature = "chrono"))]
let x = self.0.format(&Rfc3339).ok()?;
Some(x)
return self
.0
.format(&Rfc3339)
.expect("as the OffsetDateTime is always parsed from rfc3339, this should never fail");
}
}

impl std::fmt::Display for Timestamp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.to_rfc3339().ok_or(std::fmt::Error)?)
f.write_str(&self.to_rfc3339())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/model/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl WebhookGuild {
/// # Errors
///
/// Returns an [`Error::Http`] if the current user is not in the guild.
pub async fn to_partial_guild(self, cache_http: impl CacheHttp) -> Result<PartialGuild> {
pub async fn to_partial_guild(&self, cache_http: impl CacheHttp) -> Result<PartialGuild> {
#[cfg(feature = "cache")]
{
if let Some(cache) = cache_http.cache() {
Expand All @@ -142,7 +142,7 @@ impl WebhookGuild {
/// # Errors
///
/// Returns an [`Error::Http`] if the current user is not in the guild.
pub async fn to_partial_guild_with_counts(self, http: &Http) -> Result<PartialGuild> {
pub async fn to_partial_guild_with_counts(&self, http: &Http) -> Result<PartialGuild> {
http.get_guild_with_counts(self.id).await
}
}
Expand Down

0 comments on commit daaae7b

Please sign in to comment.