Skip to content

Commit

Permalink
project: use stable rustfmt (twilight-rs#170)
Browse files Browse the repository at this point in the history
Use the stable channel's rustfmt. This runs rustfmt and removes the
following lints that are unstable and only in nightly:

- `imports_layout`
- `match_block_training_comma`
- `merge_imports`
- `struct_lit_single_line`

The action has also been updating to use the stable channel.

Approved-by: Erk-
Merged-by: Vivian Hellyer <[email protected]>
Signed-off-by: Vivian Hellyer <[email protected]>
  • Loading branch information
zeylahellyer authored May 26, 2020
1 parent 14c955c commit c04e208
Show file tree
Hide file tree
Showing 78 changed files with 505 additions and 1,125 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ jobs:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt
profile: minimal
toolchain: stable
override: true

- run: rustup component add rustfmt

components: rustfmt
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
args: --all -- --check
4 changes: 0 additions & 4 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
imports_layout = "HorizontalVertical"
match_block_trailing_comma = true
merge_imports = true
struct_lit_single_line = false
use_field_init_shorthand = true
23 changes: 10 additions & 13 deletions cache/in-memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use futures::{future, lock::Mutex};
use std::{
collections::{
hash_map::{Entry, HashMap},
BTreeMap,
HashSet,
BTreeMap, HashSet,
},
error::Error,
fmt::{Display, Formatter, Result as FmtResult},
Expand Down Expand Up @@ -50,7 +49,7 @@ async fn upsert_guild_item<K: Eq + Hash, V: PartialEq>(
});

v
},
}
Entry::Vacant(e) => Arc::clone(
&e.insert(GuildItem {
data: Arc::new(v),
Expand All @@ -73,7 +72,7 @@ async fn upsert_item<K: Eq + Hash, V: PartialEq>(
e.insert(Arc::clone(&v));

v
},
}
Entry::Vacant(e) => Arc::clone(e.insert(Arc::new(v))),
}
}
Expand Down Expand Up @@ -414,7 +413,7 @@ impl InMemoryCache {
pub async fn cache_emoji(&self, guild_id: GuildId, emoji: Emoji) -> Arc<CachedEmoji> {
match self.0.emojis.lock().await.get(&emoji.id) {
Some(e) if *e.data == emoji => return Arc::clone(&e.data),
Some(_) | None => {},
Some(_) | None => {}
}
let user = match emoji.user {
Some(u) => Some(self.cache_user(u).await),
Expand Down Expand Up @@ -551,7 +550,7 @@ impl InMemoryCache {
let id = (guild_id, member.user.id);
match self.0.members.lock().await.get(&id) {
Some(m) if **m == member => return Arc::clone(&m),
Some(_) | None => {},
Some(_) | None => {}
}

let user = self.cache_user(member.user).await;
Expand Down Expand Up @@ -610,7 +609,7 @@ impl InMemoryCache {

match self.0.presences.lock().await.get(&k) {
Some(p) if **p == presence => return Arc::clone(&p),
Some(_) | None => {},
Some(_) | None => {}
}
let cached = Arc::new(CachedPresence::from(&presence));

Expand All @@ -636,7 +635,7 @@ impl InMemoryCache {
.insert(id, Arc::clone(&v));

v
},
}
}
}

Expand Down Expand Up @@ -664,7 +663,7 @@ impl InMemoryCache {
pub async fn cache_user(&self, user: User) -> Arc<User> {
match self.0.users.lock().await.get(&user.id) {
Some(u) if **u == user => return Arc::clone(&u),
Some(_) | None => {},
Some(_) | None => {}
}
let user = Arc::new(user);
self.0.users.lock().await.insert(user.id, Arc::clone(&user));
Expand Down Expand Up @@ -692,7 +691,7 @@ impl InMemoryCache {

match self.0.voice_states.lock().await.get(&k) {
Some(v) if **v == vs => return Arc::clone(v),
Some(_) | None => {},
Some(_) | None => {}
}
let state = Arc::new(CachedVoiceState {
channel_id: vs.channel_id,
Expand Down Expand Up @@ -777,9 +776,7 @@ fn guild_channel_id(channel: &GuildChannel) -> &ChannelId {
fn presence_user_id(presence: &Presence) -> UserId {
match presence.user {
UserOrId::User(ref u) => u.id,
UserOrId::UserId {
id,
} => id,
UserOrId::UserId { id } => id,
}
}

Expand Down
9 changes: 2 additions & 7 deletions cache/in-memory/src/model/guild.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use twilight_model::{
guild::{
DefaultMessageNotificationLevel,
ExplicitContentFilter,
MfaLevel,
Permissions,
PremiumTier,
SystemChannelFlags,
VerificationLevel,
DefaultMessageNotificationLevel, ExplicitContentFilter, MfaLevel, Permissions, PremiumTier,
SystemChannelFlags, VerificationLevel,
},
id::{ApplicationId, ChannelId, GuildId, UserId},
};
Expand Down
12 changes: 3 additions & 9 deletions cache/in-memory/src/model/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ use twilight_model::{
channel::{
embed::Embed,
message::{
Message,
MessageActivity,
MessageApplication,
MessageFlags,
MessageReaction,
MessageReference,
MessageType,
Message, MessageActivity, MessageApplication, MessageFlags, MessageReaction,
MessageReference, MessageType,
},
Attachment,
ChannelMention,
Attachment, ChannelMention,
},
guild::PartialMember,
id::{ChannelId, GuildId, MessageId, RoleId, UserId, WebhookId},
Expand Down
8 changes: 2 additions & 6 deletions cache/in-memory/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ mod presence;
mod voice_state;

pub use self::{
emoji::CachedEmoji,
guild::CachedGuild,
member::CachedMember,
message::CachedMessage,
presence::CachedPresence,
voice_state::CachedVoiceState,
emoji::CachedEmoji, guild::CachedGuild, member::CachedMember, message::CachedMessage,
presence::CachedPresence, voice_state::CachedVoiceState,
};

#[cfg(tests)]
Expand Down
4 changes: 1 addition & 3 deletions cache/in-memory/src/model/presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ impl From<&'_ Presence> for CachedPresence {
fn presence_user_id(user: &UserOrId) -> UserId {
match user {
UserOrId::User(ref u) => u.id,
UserOrId::UserId {
id,
} => *id,
UserOrId::UserId { id } => *id,
}
}
4 changes: 2 additions & 2 deletions cache/in-memory/src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ impl UpdateCache<InMemoryCache, InMemoryCacheError> for Box<Ready> {
match status {
GuildStatus::Offline(u) => {
cache.unavailable_guild(u.id).await;
},
}
GuildStatus::Online(g) => {
cache.cache_guild(g.clone()).await;
},
}
}
}

Expand Down
22 changes: 11 additions & 11 deletions cache/in-memory/src/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ impl UpdateCache<InMemoryCache, InMemoryCacheError> for ChannelCreate {
match self.0.clone() {
Channel::Group(c) => {
super::upsert_item(&cache.0.groups, c.id, c).await;
},
}
Channel::Guild(c) => {
if let Some(gid) = super::guild_channel_guild_id(&c) {
cache.cache_guild_channel(*gid, c.clone()).await;
}
},
}
Channel::Private(c) => {
cache.cache_private_channel(c.clone()).await;
},
}
}

Ok(())
Expand All @@ -69,15 +69,15 @@ impl UpdateCache<InMemoryCache, InMemoryCacheError> for ChannelDelete {
match self.0 {
Channel::Group(ref c) => {
cache.delete_group(c.id).await;
},
}
Channel::Guild(ref c) => {
let id = *super::guild_channel_id(&c);

cache.delete_guild_channel(id).await;
},
}
Channel::Private(ref c) => {
cache.0.channels_private.lock().await.remove(&c.id);
},
}
}

Ok(())
Expand All @@ -101,15 +101,15 @@ impl UpdateCache<InMemoryCache, InMemoryCacheError> for ChannelUpdate {
match self.0.clone() {
Channel::Group(c) => {
cache.cache_group(c.clone()).await;
},
}
Channel::Guild(c) => {
if let Some(gid) = super::guild_channel_guild_id(&c) {
cache.cache_guild_channel(*gid, c.clone()).await;
}
},
}
Channel::Private(c) => {
cache.cache_private_channel(c.clone()).await;
},
}
}

Ok(())
Expand Down Expand Up @@ -602,10 +602,10 @@ impl UpdateCache<InMemoryCache, InMemoryCacheError> for Ready {
match status {
GuildStatus::Offline(u) => {
cache.unavailable_guild(u.id).await;
},
}
GuildStatus::Online(g) => {
cache.cache_guild(g.clone()).await;
},
}
}
}

Expand Down
22 changes: 6 additions & 16 deletions command-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<'a> Parser<'a> {

match buf.get(idx..)? {
v if !v.starts_with(padding) => return None,
_ => {},
_ => {}
}

idx += padding.len();
Expand Down Expand Up @@ -168,9 +168,7 @@ mod tests {
let message_unicode_2 = "!\u{3b4} is delta";

// Case insensitive - ASCII
let Command {
name, ..
} = parser
let Command { name, .. } = parser
.parse(message_ascii)
.expect("Parser is case sensitive");
assert_eq!(
Expand All @@ -180,9 +178,7 @@ mod tests {

// Case insensitive - Unicode
parser.config.command("wei\u{df}").add();
let Command {
name, ..
} = parser
let Command { name, .. } = parser
.parse(message_unicode)
.expect("Parser is case sensitive");
assert_eq!(
Expand All @@ -191,9 +187,7 @@ mod tests {
);

parser.config.command("\u{394}").add();
let Command {
name, ..
} = parser
let Command { name, .. } = parser
.parse(message_unicode_2)
.expect("Parser is case sensitive");
assert_eq!(
Expand Down Expand Up @@ -232,14 +226,10 @@ mod tests {
let parser = simple_config();

match parser.parse("!echo what a test") {
Some(Command {
name,
prefix,
..
}) => {
Some(Command { name, prefix, .. }) => {
assert_eq!("echo", name);
assert_eq!("!", prefix);
},
}
other => panic!("Not command: {:?}", other),
}
}
Expand Down
10 changes: 5 additions & 5 deletions gateway/examples/request-members/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
shard
.command(&RequestGuildMembers::new_all(guildcreate.id, Some(false)))
.await?;
},
}
Event::Ready(_ready) => {
//commands can be send with the command function

Expand Down Expand Up @@ -62,7 +62,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
Some(String::from("hoister_list")),
))
.await?;
},
}

Event::MemberChunk(chunk) => {
//this is where the magic happens
Expand Down Expand Up @@ -92,17 +92,17 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
// just to keep the compiler happy, empty nonces are not a thing
}
}
},
}
None => println!(
"Received chunk {:?}/{:?} for guilds {:?}",
chunk.chunk_index + 1,
chunk.chunk_count,
chunk.guild_id
),
}
},
}

_ => {},
_ => {}
}
}

Expand Down
15 changes: 5 additions & 10 deletions gateway/src/cluster/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ impl<T: RangeBounds<u64>> TryFrom<(T, u64)> for ShardScheme {
};

if start > end {
return Err(Error::IdTooLarge {
end,
start,
total,
});
return Err(Error::IdTooLarge { end, start, total });
}

Ok(Self::Range {
Expand Down Expand Up @@ -232,11 +228,10 @@ impl ClusterConfigBuilder {
/// [`ShardConfigBuilder::large_threshold`]: ../../shard/config/struct.ShardConfigBuilder.html#method.large_threshold
/// [`ShardError::LargeThresholdInvalid`]: ../../shard/error/enum.Error.html#variant.LargeThresholdInvalid
pub fn large_threshold(mut self, large_threshold: u64) -> Result<Self> {
self.1 = self.1.large_threshold(large_threshold).map_err(|source| {
Error::LargeThresholdInvalid {
source,
}
})?;
self.1 = self
.1
.large_threshold(large_threshold)
.map_err(|source| Error::LargeThresholdInvalid { source })?;

Ok(self)
}
Expand Down
Loading

0 comments on commit c04e208

Please sign in to comment.