Skip to content

Commit

Permalink
chore(clippy): Resolve Clippy 1.80 lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Erk- authored and Gelbpunkt committed Aug 28, 2024
1 parent 52279b2 commit d839bcf
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ Utility crate that adds utilities to the twilight ecosystem that do not fit
in any other crate. Currently, it contains:

- A trait to make extracting data from Discord identifiers (Snowflakes)
easier;
easier;
- A calculator to calculate the permissions of a member in a guild or
channel.
channel.

### [`twilight-gateway-queue`]

Expand Down
3 changes: 1 addition & 2 deletions twilight-cache-inmemory/src/event/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ impl<CacheModels: CacheableModels> UpdateCache<CacheModels> for ReactionAdd {
} else {
let me = cache
.current_user()
.map(|user| user.id() == self.0.user_id)
.unwrap_or_default();
.is_some_and(|user| user.id() == self.0.user_id);

message.add_reaction(Reaction {
burst_colors: Vec::new(),
Expand Down
9 changes: 3 additions & 6 deletions twilight-cache-inmemory/src/event/sticker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ mod tests {
assert!(cache
.stickers
.get(&STICKER_ONE_ID)
.map(|r| r.id == STICKER_ONE_ID)
.unwrap_or_default());
.is_some_and(|r| r.id == STICKER_ONE_ID));
assert!(cache
.stickers
.get(&STICKER_TWO_ID)
.map(|r| r.id == STICKER_TWO_ID)
.unwrap_or_default());
.is_some_and(|r| r.id == STICKER_TWO_ID));

let guild_stickers = cache
.guild_stickers
Expand All @@ -145,8 +143,7 @@ mod tests {
assert!(cache
.stickers
.get(&STICKER_ONE_ID)
.map(|r| r.id == STICKER_ONE_ID)
.unwrap_or_default());
.is_some_and(|r| r.id == STICKER_ONE_ID));
let guild_stickers = cache
.guild_stickers
.get(&GUILD_ID)
Expand Down
10 changes: 4 additions & 6 deletions twilight-cache-inmemory/src/event/voice_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ impl<CacheModels: CacheableModels> InMemoryCache<CacheModels> {
let remove_channel_mapping = self
.voice_state_channels
.get_mut(&voice_state.channel_id())
.map(|mut channel_voice_states| {
.is_some_and(|mut channel_voice_states| {
channel_voice_states.remove(&(guild_id, user_id));

channel_voice_states.is_empty()
})
.unwrap_or_default();
});

if remove_channel_mapping {
self.voice_state_channels.remove(&voice_state.channel_id());
Expand Down Expand Up @@ -57,12 +56,11 @@ impl<CacheModels: CacheableModels> InMemoryCache<CacheModels> {
let remove_guild = self
.voice_state_guilds
.get_mut(&guild_id)
.map(|mut guild_users| {
.is_some_and(|mut guild_users| {
guild_users.remove(&user_id);

guild_users.is_empty()
})
.unwrap_or_default();
});

if remove_guild {
self.voice_state_guilds.remove(&guild_id);
Expand Down
7 changes: 3 additions & 4 deletions twilight-cache-inmemory/src/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,7 @@ impl<'a, CacheModels: CacheableModels> InMemoryCachePermissions<'a, CacheModels>
self.cache
.guilds
.get(&guild_id)
.map(|r| r.owner_id() == user_id)
.unwrap_or_default()
.is_some_and(|r| r.owner_id() == user_id)
}

/// Retrieve a member's roles' permissions and the guild's `@everyone`
Expand Down Expand Up @@ -1045,8 +1044,8 @@ mod tests {
/// In particular, we want to test that:
///
/// - if a member is timed out they will be limited to the intersection of
/// the [`Permissions::READ_MESSAGE_HISTORY`] and
/// [`Permissions::VIEW_CHANNEL`] permissions on a [guild level][`root`]
/// the [`Permissions::READ_MESSAGE_HISTORY`] and
/// [`Permissions::VIEW_CHANNEL`] permissions on a [guild level][`root`]
/// - the same is true on a [channel level][`in_channel`]
/// - administrators are never timed out
/// - checking whether the member's communication is disabled is configurable
Expand Down
2 changes: 1 addition & 1 deletion twilight-http-ratelimiting/src/in_memory/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl BucketQueueTask {
const WAIT: Duration = Duration::from_secs(10);

/// Create a new task to manage the ratelimit for a [`Bucket`].
pub fn new(
pub const fn new(
bucket: Arc<Bucket>,
buckets: Arc<Mutex<HashMap<Path, Arc<Bucket>>>>,
global: Arc<GlobalLockPair>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a> UpdateCurrentUserVoiceState<'a> {
/// # Caveats
///
/// - You are able to set `request_to_speak_timestamp` to any present or
/// future time.
/// future time.
pub const fn request_to_speak_timestamp(mut self, request_to_speak_timestamp: &'a str) -> Self {
if request_to_speak_timestamp.is_empty() {
self.fields.request_to_speak_timestamp = Some(Nullable(None));
Expand All @@ -79,7 +79,7 @@ impl<'a> UpdateCurrentUserVoiceState<'a> {
/// # Caveats
///
/// - You must have the `MUTE_MEMBERS` permission to unsuppress yourself.
/// You can always suppress yourself.
/// - You can always suppress yourself.
pub const fn suppress(mut self) -> Self {
self.fields.suppress = Some(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ impl<'a> UpdateUserVoiceState<'a> {
///
/// - You must have the [`MUTE_MEMBERS`] permission to use this method.
/// - When unsuppressed, non-bot users will have their
/// `request_to_speak_timestamp` set to the current time. Bot users will
/// not.
/// `request_to_speak_timestamp` set to the current time. Bot users will
/// not.
/// - When suppressed, the user will have their `request_to_speak_timestamp`
/// removed.
/// removed.
///
/// [`MUTE_MEMBERS`]: twilight_model::guild::Permissions::MUTE_MEMBERS
pub const fn suppress(mut self) -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl UserIdsError {
(self.kind, None)
}

fn too_many(ids: Vec<Id<UserMarker>>) -> Self {
const fn too_many(ids: Vec<Id<UserMarker>>) -> Self {
Self {
kind: UserIdsErrorType::TooMany { ids },
}
Expand Down
6 changes: 2 additions & 4 deletions twilight-model/src/id/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,14 @@ impl<T> PartialEq for Id<T> {
impl<T> PartialEq<i64> for Id<T> {
fn eq(&self, other: &i64) -> bool {
u64::try_from(*other)
.map(|v| v == self.value.get())
.unwrap_or_default()
.is_ok_and(|v| v == self.value.get())
}
}

impl<T> PartialEq<Id<T>> for i64 {
fn eq(&self, other: &Id<T>) -> bool {
u64::try_from(*self)
.map(|v| v == other.value.get())
.unwrap_or_default()
.is_ok_and(|v| v == other.value.get())
}
}

Expand Down
2 changes: 1 addition & 1 deletion twilight-util/src/link/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn parse(url: &str) -> Result<(Id<WebhookMarker>, Option<&str>), WebhookPars
let mut token = segments.next();

// Don't return an empty token if the segment is empty.
if token.map(str::is_empty).unwrap_or_default() {
if token.is_some_and(str::is_empty) {
token = None;
}

Expand Down
8 changes: 4 additions & 4 deletions twilight-util/src/permission_calculator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! like:
//!
//! - `@everyone` role is allowed the [Embed Links] and [Add Reactions]
//! permissions; and
//! permissions; and
//! - member is denied the [Send Messages] permission.
//!
//! Taking into account the guild root-level permissions and the permission
Expand Down Expand Up @@ -230,11 +230,11 @@ impl<'a> PermissionCalculator<'a> {
/// circumstances:
///
/// - When the permission is denied on the role level and
/// isn't enabled on a role or member permission overwrite;
/// isn't enabled on a role or member permission overwrite;
/// - When the permission is denied on a role permission overwrite but isn't
/// enabled on a member permission overwrite; or
/// enabled on a member permission overwrite; or
/// - When permission isn't enabled on a guild level and isn't enabled via a
/// permission overwrite.
/// permission overwrite.
///
/// When the [Send Messages] permission is denied and is not similarly
/// enabled like above then the [Attach Files], [Embed Links],
Expand Down

0 comments on commit d839bcf

Please sign in to comment.