Skip to content

Commit 6a614cd

Browse files
authored
Check for lints which change public API (#2999)
This is fine to do on next, and fixed a couple things. I also swapped the `allow`s for `expect`s because why not.
1 parent 5b6a1d4 commit 6a614cd

File tree

9 files changed

+22
-26
lines changed

9 files changed

+22
-26
lines changed

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cognitive-complexity-threshold = 20
1+
avoid-breaking-exported-api = false

src/gateway/client/event_handler.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ macro_rules! event_handler {
2626
$( #[deprecated = $deprecated] )?
2727
async fn $method_name(&self, $($context: Context,)? $( $arg_name: $arg_type ),*) {
2828
// Suppress unused argument warnings
29-
#[allow(dropping_references, dropping_copy_types)]
3029
drop(( $($context,)? $($arg_name),* ))
3130
}
3231
)*
@@ -43,10 +42,7 @@ macro_rules! event_handler {
4342
/// in a timely manner. It is recommended to keep the runtime
4443
/// complexity of the filter code low to avoid unnecessarily blocking
4544
/// your bot.
46-
fn filter_event(&self, context: &Context, event: &Event) -> bool {
47-
// Suppress unused argument warnings
48-
#[allow(dropping_references, dropping_copy_types)]
49-
drop((context, event));
45+
fn filter_event(&self, _context: &Context, _event: &Event) -> bool {
5046
true
5147
}
5248
}
@@ -79,7 +75,6 @@ macro_rules! event_handler {
7975
/// ```
8076
#[must_use]
8177
pub fn snake_case_name(&self) -> &'static str {
82-
#[allow(deprecated)]
8378
match self {
8479
$(
8580
$( #[cfg(feature = $feature)] )?
@@ -90,7 +85,6 @@ macro_rules! event_handler {
9085

9186
/// Runs the given [`EventHandler`]'s code for this event.
9287
pub async fn dispatch(self, ctx: Context, handler: &dyn EventHandler) {
93-
#[allow(deprecated)]
9488
match self {
9589
$(
9690
$( #[cfg(feature = $feature)] )?
@@ -527,10 +521,8 @@ pub trait RawEventHandler: Send + Sync {
527521
/// in a timely manner. It is recommended to keep the runtime
528522
/// complexity of the filter code low to avoid unnecessarily blocking
529523
/// your bot.
530-
fn filter_event(&self, context: &Context, event: &Event) -> bool {
524+
fn filter_event(&self, _context: &Context, _event: &Event) -> bool {
531525
// Suppress unused argument warnings
532-
#[allow(dropping_references, dropping_copy_types)]
533-
drop((context, event));
534526
true
535527
}
536528
}

src/http/request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ impl<'a> Request<'a> {
119119
}
120120

121121
#[must_use]
122-
pub fn headers_ref(&self) -> &Option<Headers> {
123-
&self.headers
122+
pub fn headers_ref(&self) -> Option<&Headers> {
123+
self.headers.as_ref()
124124
}
125125

126126
#[must_use]

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
clippy::fallible_impl_from,
6161
clippy::let_underscore_must_use,
6262
clippy::format_push_string,
63+
clippy::allow_attributes,
6364
clippy::pedantic
6465
)]
6566
#![allow(
@@ -74,6 +75,7 @@
7475
clippy::doc_markdown,
7576
clippy::missing_panics_doc,
7677
clippy::doc_link_with_quotes,
78+
clippy::struct_field_names
7779
)]
7880
#![cfg_attr(test, allow(clippy::unwrap_used))]
7981

src/model/channel/channel_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ impl ChannelId {
812812

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

@@ -825,7 +825,7 @@ impl ChannelId {
825825

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

src/model/channel/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ impl MessageId {
913913
/// Returns a link referencing this message. When clicked, users will jump to the message. The
914914
/// link will be valid for messages in either private channels or guilds.
915915
#[must_use]
916-
pub fn link(&self, channel_id: ChannelId, guild_id: Option<GuildId>) -> String {
916+
pub fn link(self, channel_id: ChannelId, guild_id: Option<GuildId>) -> String {
917917
if let Some(guild_id) = guild_id {
918918
format!("https://discord.com/channels/{guild_id}/{channel_id}/{self}")
919919
} else {

src/model/guild/guild_id.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ impl GuildId {
902902

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

@@ -1410,7 +1410,7 @@ impl GuildId {
14101410

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

@@ -1423,7 +1423,7 @@ impl GuildId {
14231423

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

src/model/timestamp.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,20 @@ impl Timestamp {
133133
}
134134

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

145147
impl std::fmt::Display for Timestamp {
146148
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
147-
f.write_str(&self.to_rfc3339().ok_or(std::fmt::Error)?)
149+
f.write_str(&self.to_rfc3339())
148150
}
149151
}
150152

src/model/webhook.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl WebhookGuild {
121121
/// # Errors
122122
///
123123
/// Returns an [`Error::Http`] if the current user is not in the guild.
124-
pub async fn to_partial_guild(self, cache_http: impl CacheHttp) -> Result<PartialGuild> {
124+
pub async fn to_partial_guild(&self, cache_http: impl CacheHttp) -> Result<PartialGuild> {
125125
#[cfg(feature = "cache")]
126126
{
127127
if let Some(cache) = cache_http.cache() {
@@ -142,7 +142,7 @@ impl WebhookGuild {
142142
/// # Errors
143143
///
144144
/// Returns an [`Error::Http`] if the current user is not in the guild.
145-
pub async fn to_partial_guild_with_counts(self, http: &Http) -> Result<PartialGuild> {
145+
pub async fn to_partial_guild_with_counts(&self, http: &Http) -> Result<PartialGuild> {
146146
http.get_guild_with_counts(self.id).await
147147
}
148148
}

0 commit comments

Comments
 (0)