Skip to content

Commit

Permalink
Remove some pedantic lints from the whitelist (serenity-rs#2728)
Browse files Browse the repository at this point in the history
This also removes the impls of `From<{i32,u64}> for Colour`, as it only
makes sense to convert infallibly from `u32`.
  • Loading branch information
mkrasnitski committed Dec 8, 2024
1 parent e409837 commit 888409d
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/builder/edit_interaction_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Builder for EditInteractionResponse<'_> {
) -> Result<Self::Built> {
self.0.check_length()?;

let files = self.0.attachments.as_mut().map_or(Vec::new(), |a| a.take_files());
let files = self.0.attachments.as_mut().map_or(Vec::new(), EditAttachments::take_files);

cache_http.http().edit_original_interaction_response(ctx, &self, files).await
}
Expand Down
2 changes: 1 addition & 1 deletion src/builder/edit_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Builder for EditMessage<'_> {
}
}

let files = self.attachments.as_mut().map_or(Vec::new(), |a| a.take_files());
let files = self.attachments.as_mut().map_or(Vec::new(), EditAttachments::take_files);

let http = cache_http.http();
if self.allowed_mentions.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion src/builder/edit_webhook_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Builder for EditWebhookMessage<'_> {
) -> Result<Self::Built> {
self.check_length()?;

let files = self.attachments.as_mut().map_or(Vec::new(), |a| a.take_files());
let files = self.attachments.as_mut().map_or(Vec::new(), EditAttachments::take_files);

let http = cache_http.http();
if self.allowed_mentions.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion src/cache/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<K: Eq + Hash, V> MaybeMap<K, V> {
}

pub fn len(&self) -> usize {
self.0.as_ref().map_or(0, |map| map.len())
self.0.as_ref().map_or(0, DashMap::len)
}

pub fn shrink_to_fit(&self) {
Expand Down
2 changes: 1 addition & 1 deletion src/gateway/bridge/shard_queuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl ShardQueue {
/// Pops a `ShardId` from every bucket containing at least one and returns them all as a `Vec`.
pub fn pop_batch(&mut self) -> Vec<ShardId> {
(0..self.max_concurrency.get())
.filter_map(|i| self.buckets.get_mut(&i).and_then(|bucket| bucket.pop_front()))
.filter_map(|i| self.buckets.get_mut(&i).and_then(VecDeque::pop_front))
.collect()
}

Expand Down
11 changes: 2 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,22 @@
clippy::non_ascii_literal,
clippy::fallible_impl_from,
clippy::let_underscore_must_use,
clippy::format_collect,
clippy::format_push_string,
clippy::pedantic
)]
#![allow(
// Allowed to avoid breaking changes.
clippy::module_name_repetitions,
clippy::unused_self,
// Allowed as they are too pedantic
clippy::cast_possible_truncation,
clippy::module_name_repetitions,
clippy::unreadable_literal,
clippy::cast_possible_wrap,
clippy::wildcard_imports,
clippy::cast_sign_loss,
clippy::too_many_lines,
clippy::doc_markdown,
clippy::cast_lossless,
clippy::redundant_closure_for_method_calls,
// Covered by other lints
clippy::missing_panics_doc, // clippy::unwrap_used
clippy::missing_panics_doc,
)]
#![cfg_attr(test, allow(clippy::unwrap_used))]
#![type_length_limit = "3294819"] // needed so ShardRunner::run compiles with instrument.

#[macro_use]
extern crate serde;
Expand Down
40 changes: 1 addition & 39 deletions src/model/colour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,6 @@ impl Colour {
}
}

impl From<i32> for Colour {
/// Constructs a Colour from a i32.
///
/// This is used for functions that accept `Into<Colour>`.
///
/// This is useful when providing hex values.
///
/// # Examples
///
/// ```rust
/// use serenity::model::Colour;
///
/// assert_eq!(Colour::from(0xDEA584).tuple(), (222, 165, 132));
/// ```
fn from(value: i32) -> Colour {
Colour(value as u32)
}
}

impl From<u32> for Colour {
/// Constructs a Colour from a u32.
///
Expand All @@ -235,24 +216,7 @@ impl From<u32> for Colour {
/// assert_eq!(Colour::from(6573123u32).r(), 100);
/// ```
fn from(value: u32) -> Colour {
Colour(value)
}
}

impl From<u64> for Colour {
/// Constructs a Colour from a u32.
///
/// This is used for functions that accept `Into<Colour>`.
///
/// # Examples
///
/// ```rust
/// use serenity::model::Colour;
///
/// assert_eq!(Colour::from(6573123u64).r(), 100);
/// ```
fn from(value: u64) -> Colour {
Colour(value as u32)
Colour(value & 0xffffff)
}
}

Expand Down Expand Up @@ -445,8 +409,6 @@ mod test {

#[test]
fn from() {
assert_eq!(Colour::from(7i32).0, 7);
assert_eq!(Colour::from(7u32).0, 7);
assert_eq!(Colour::from(7u64).0, 7);
}
}
2 changes: 1 addition & 1 deletion src/model/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ pub mod secret {
secret: &Option<Secret<S>>,
serializer: Sr,
) -> Result<Sr::Ok, Sr::Error> {
secret.as_ref().map(|s| s.expose_secret()).serialize(serializer)
secret.as_ref().map(ExposeSecret::expose_secret).serialize(serializer)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ pub(crate) fn user_perms(cache: impl AsRef<Cache>, channel_id: ChannelId) -> Res
#[must_use]
pub fn shard_id(guild_id: GuildId, shard_count: u16) -> u16 {
let shard_count = check_shard_total(shard_count);
((guild_id.get() >> 22) % (shard_count.get() as u64)) as u16
((guild_id.get() >> 22) % u64::from(shard_count.get())) as u16
}

pub(crate) fn check_shard_total(total_shards: u16) -> NonZeroU16 {
Expand Down

0 comments on commit 888409d

Please sign in to comment.