From b83453f126a4273c601632f516d5bd61b962e1c9 Mon Sep 17 00:00:00 2001 From: Cassandra McCarthy Date: Thu, 22 Sep 2022 17:58:48 -0400 Subject: [PATCH] ci: check doc comments with nightly format (#1857) --- .github/workflows/check.yml | 11 ++++-- twilight-gateway/src/cluster/builder.rs | 10 +++-- twilight-gateway/src/cluster/impl.rs | 39 +++++++++---------- twilight-gateway/src/cluster/mod.rs | 17 ++++---- twilight-gateway/src/shard/builder.rs | 17 ++++---- twilight-gateway/src/shard/impl.rs | 15 ++++--- twilight-gateway/src/shard/mod.rs | 9 +---- twilight-http/src/client/mod.rs | 4 +- .../interaction/delete_response.rs | 2 +- .../application/interaction/get_followup.rs | 2 +- .../application/interaction/get_response.rs | 2 +- .../create_guild_scheduled_event/mod.rs | 4 +- .../src/channel/message/component/mod.rs | 4 +- 13 files changed, 70 insertions(+), 66 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d14ab541be1..cc78579eeae 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -104,14 +104,17 @@ jobs: - name: Checkout sources uses: actions/checkout@v3 - - name: Install stable toolchain - uses: dtolnay/rust-toolchain@stable + - name: Install nightly toolchain + uses: dtolnay/rust-toolchain@v1 + with: + components: rustfmt + toolchain: nightly - name: Add problem matchers run: echo "::add-matcher::.github/rust.json" - - name: Run cargo fmt - run: cargo fmt --all -- --check + - name: Check code formatting + run: cargo fmt --all -- --check --unstable-features --config format_code_in_doc_comments=true min-vers: name: Minimal crate versions diff --git a/twilight-gateway/src/cluster/builder.rs b/twilight-gateway/src/cluster/builder.rs index 3d80c409fcb..536f9e2d54c 100644 --- a/twilight-gateway/src/cluster/builder.rs +++ b/twilight-gateway/src/cluster/builder.rs @@ -189,14 +189,13 @@ impl ClusterBuilder { /// ```no_run /// # fn main() -> Result<(), Box> { /// use std::env::{self, consts::OS}; - /// use twilight_gateway::{Intents, Cluster}; + /// use twilight_gateway::{Cluster, Intents}; /// use twilight_model::gateway::payload::outgoing::identify::IdentifyProperties; /// /// let token = env::var("DISCORD_TOKEN")?; /// let properties = IdentifyProperties::new("twilight.rs", "twilight.rs", OS); /// - /// let builder = Cluster::builder(token, Intents::empty()) - /// .identify_properties(properties); + /// let builder = Cluster::builder(token, Intents::empty()).identify_properties(properties); /// # Ok(()) } /// ``` #[allow(clippy::missing_const_for_fn)] @@ -273,8 +272,11 @@ impl ClusterBuilder { /// Configure a cluster to manage shards 0-9 out of 20 shards total: /// /// ```no_run - /// use twilight_gateway::{cluster::{Cluster, ShardScheme}, Intents}; /// use std::env; + /// use twilight_gateway::{ + /// cluster::{Cluster, ShardScheme}, + /// Intents, + /// }; /// /// # #[tokio::main] async fn main() -> Result<(), Box> { /// let token = env::var("DISCORD_TOKEN")?; diff --git a/twilight-gateway/src/cluster/impl.rs b/twilight-gateway/src/cluster/impl.rs index 29151f0f526..0fa66c1c142 100644 --- a/twilight-gateway/src/cluster/impl.rs +++ b/twilight-gateway/src/cluster/impl.rs @@ -231,9 +231,9 @@ impl Cluster { /// Create a cluster, receiving a stream of events: /// /// ```no_run - /// use twilight_gateway::{Cluster, EventTypeFlags, Event, Intents}; /// use futures::StreamExt; /// use std::env; + /// use twilight_gateway::{Cluster, Event, EventTypeFlags, Intents}; /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { @@ -241,10 +241,11 @@ impl Cluster { /// | EventTypeFlags::MESSAGE_DELETE /// | EventTypeFlags::MESSAGE_UPDATE; /// - /// let (cluster, mut events) = Cluster::builder(env::var("DISCORD_TOKEN")?, Intents::GUILD_MESSAGES) - /// .event_types(types) - /// .build() - /// .await?; + /// let (cluster, mut events) = + /// Cluster::builder(env::var("DISCORD_TOKEN")?, Intents::GUILD_MESSAGES) + /// .event_types(types) + /// .build() + /// .await?; /// cluster.up().await; /// /// while let Some((shard_id, event)) = events.next().await { @@ -253,7 +254,7 @@ impl Cluster { /// Event::MessageDelete(_) => println!("Shard {shard_id} got a deleted message"), /// Event::MessageUpdate(_) => println!("Shard {shard_id} got an updated message"), /// // No other events will come in through the stream. - /// _ => {}, + /// _ => {} /// } /// } /// # Ok(()) } @@ -327,9 +328,9 @@ impl Cluster { /// created, deleted, or updated: /// /// ```no_run - /// use twilight_gateway::{Cluster, EventTypeFlags, Event, Intents}; /// use futures::StreamExt; /// use std::env; + /// use twilight_gateway::{Cluster, Event, EventTypeFlags, Intents}; /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { @@ -350,7 +351,7 @@ impl Cluster { /// Event::MessageDelete(_) => println!("Shard {shard_id} got a deleted message"), /// Event::MessageUpdate(_) => println!("Shard {shard_id} got an updated message"), /// // No other events will come in through the stream. - /// _ => {}, + /// _ => {} /// } /// } /// # Ok(()) } @@ -372,8 +373,11 @@ impl Cluster { /// Bring up a cluster, starting shards all 10 shards that a bot uses: /// /// ```no_run - /// use twilight_gateway::{cluster::{Cluster, ShardScheme}, Intents}; /// use std::env; + /// use twilight_gateway::{ + /// cluster::{Cluster, ShardScheme}, + /// Intents, + /// }; /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { @@ -435,8 +439,8 @@ impl Cluster { /// After waiting a minute, print the ID, latency, and stage of each shard: /// /// ```no_run - /// use twilight_gateway::{Cluster, Intents}; /// use std::{env, time::Duration}; + /// use twilight_gateway::{Cluster, Intents}; /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { @@ -472,11 +476,9 @@ impl Cluster { /// # async fn main() -> Result<(), Box> { /// use std::env; /// use twilight_gateway::{cluster::Cluster, Intents}; - /// use twilight_model::{ - /// gateway::{ - /// payload::outgoing::UpdatePresence, - /// presence::{Activity, ActivityType, MinimalActivity, Status}, - /// }, + /// use twilight_model::gateway::{ + /// payload::outgoing::UpdatePresence, + /// presence::{Activity, ActivityType, MinimalActivity, Status}, /// }; /// /// let intents = Intents::GUILD_VOICE_STATES; @@ -494,12 +496,7 @@ impl Cluster { /// name: "testing".to_owned(), /// url: None, /// }); - /// let request = UpdatePresence::new( - /// Vec::from([activity]), - /// false, - /// None, - /// Status::Online, - /// )?; + /// let request = UpdatePresence::new(Vec::from([activity]), false, None, Status::Online)?; /// /// // Send the request over the shard. /// cluster.command(2, &request).await?; diff --git a/twilight-gateway/src/cluster/mod.rs b/twilight-gateway/src/cluster/mod.rs index 8ed801b1bc7..f5819e8ce5e 100644 --- a/twilight-gateway/src/cluster/mod.rs +++ b/twilight-gateway/src/cluster/mod.rs @@ -7,14 +7,15 @@ //! disconnected, and when new message commands come in: //! //! ```no_run -//! use twilight_gateway::{Cluster, Event, Intents}; //! use futures::StreamExt; //! use std::{env, sync::Arc}; +//! use twilight_gateway::{Cluster, Event, Intents}; //! //! #[tokio::main] //! async fn main() -> anyhow::Result<()> { //! let token = env::var("DISCORD_TOKEN")?; -//! let intents = Intents::GUILD_BANS | Intents::GUILD_EMOJIS_AND_STICKERS | Intents::GUILD_MESSAGES; +//! let intents = +//! Intents::GUILD_BANS | Intents::GUILD_EMOJIS_AND_STICKERS | Intents::GUILD_MESSAGES; //! let (cluster, mut events) = Cluster::new(token, intents).await?; //! let cluster = Arc::new(cluster); //! cluster.up().await; @@ -32,23 +33,23 @@ //! match event { //! Event::ShardConnected { .. } => { //! println!("Shard {shard_id} is now connected"); -//! }, +//! } //! Event::ShardDisconnected { .. } => { //! println!("Shard {shard_id} is now disconnected"); -//! }, +//! } //! Event::MessageCreate(msg) if msg.content == "!latency" => { //! if let Some(shard) = cluster.shard(shard_id) { //! if let Ok(info) = shard.info() { //! println!("Shard {shard_id}'s latency is {:?}", info.latency()); //! } //! } -//! }, +//! } //! Event::MessageCreate(msg) if msg.content == "!shutdown" => { //! println!("Got a shutdown request from shard {shard_id}"); //! //! cluster.down(); -//! }, -//! _ => {}, +//! } +//! _ => {} //! } //! } //! ``` @@ -57,9 +58,9 @@ //! of 16: //! //! ```no_run -//! use twilight_gateway::{cluster::ShardScheme, Cluster, Event, Intents}; //! use futures::StreamExt; //! use std::env; +//! use twilight_gateway::{cluster::ShardScheme, Cluster, Event, Intents}; //! //! #[tokio::main] //! async fn main() -> anyhow::Result<()> { diff --git a/twilight-gateway/src/shard/builder.rs b/twilight-gateway/src/shard/builder.rs index 7e2279fd8c1..1b60e1f17d5 100644 --- a/twilight-gateway/src/shard/builder.rs +++ b/twilight-gateway/src/shard/builder.rs @@ -207,8 +207,7 @@ impl ShardBuilder { /// let token = env::var("DISCORD_TOKEN")?; /// let properties = IdentifyProperties::new("twilight.rs", "twilight.rs", OS); /// - /// let builder = Shard::builder(token, Intents::empty()) - /// .identify_properties(properties); + /// let builder = Shard::builder(token, Intents::empty()).identify_properties(properties); /// # Ok(()) } /// ``` #[allow(clippy::missing_const_for_fn)] @@ -264,8 +263,8 @@ impl ShardBuilder { /// }; /// /// # fn main() -> Result<(), Box> { - /// let shard = Shard::builder(env::var("DISCORD_TOKEN")?, Intents::empty()) - /// .presence(UpdatePresencePayload::new( + /// let shard = Shard::builder(env::var("DISCORD_TOKEN")?, Intents::empty()).presence( + /// UpdatePresencePayload::new( /// vec![MinimalActivity { /// kind: ActivityType::Playing, /// name: "Not accepting commands".into(), @@ -275,9 +274,9 @@ impl ShardBuilder { /// false, /// None, /// Status::Idle, - /// )?); + /// )?, + /// ); /// # Ok(()) } - /// /// ``` pub fn presence(mut self, presence: UpdatePresencePayload) -> Self { self.presence.replace(presence); @@ -333,13 +332,15 @@ impl ShardBuilder { /// a total of 19 shards: /// /// ```no_run - /// use twilight_gateway::{Intents, Shard}; /// use std::env; + /// use twilight_gateway::{Intents, Shard}; /// /// # fn main() -> Result<(), Box> { /// let token = env::var("DISCORD_TOKEN")?; /// - /// let shard = Shard::builder(token, Intents::empty()).shard(18, 19)?.build(); + /// let shard = Shard::builder(token, Intents::empty()) + /// .shard(18, 19)? + /// .build(); /// # Ok(()) } /// ``` /// diff --git a/twilight-gateway/src/shard/impl.rs b/twilight-gateway/src/shard/impl.rs index 7503af5f493..45b71b504a6 100644 --- a/twilight-gateway/src/shard/impl.rs +++ b/twilight-gateway/src/shard/impl.rs @@ -369,7 +369,7 @@ pub struct ResumeSession { /// ```no_run /// use futures::stream::StreamExt; /// use std::env; -/// use twilight_gateway::{EventTypeFlags, Event, Intents, Shard}; +/// use twilight_gateway::{Event, EventTypeFlags, Intents, Shard}; /// /// # #[tokio::main] async fn main() -> Result<(), Box> { /// // Use the value of the "DISCORD_TOKEN" environment variable as the bot's @@ -390,11 +390,11 @@ pub struct ResumeSession { /// match event { /// Event::MessageCreate(message) => { /// println!("message received with content: {}", message.content); -/// }, +/// } /// Event::MessageDelete(message) => { /// println!("message with ID {} deleted", message.id); -/// }, -/// _ => {}, +/// } +/// _ => {} /// } /// } /// # Ok(()) } @@ -421,9 +421,9 @@ impl Shard { /// current connection stage: /// /// ```no_run - /// use twilight_gateway::{Intents, Shard}; /// use std::{env, time::Duration}; /// use tokio::time as tokio_time; + /// use twilight_gateway::{Intents, Shard}; /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { @@ -639,7 +639,10 @@ impl Shard { /// ```no_run /// # #[tokio::main] async fn main() -> Result<(), Box> { /// use std::env; - /// use twilight_gateway::{shard::{raw_message::Message, Shard}, Intents}; + /// use twilight_gateway::{ + /// shard::{raw_message::Message, Shard}, + /// Intents, + /// }; /// /// let token = env::var("DISCORD_TOKEN")?; /// let (shard, _) = Shard::new(token, Intents::GUILDS); diff --git a/twilight-gateway/src/shard/mod.rs b/twilight-gateway/src/shard/mod.rs index 8db020c047d..a1971ff4144 100644 --- a/twilight-gateway/src/shard/mod.rs +++ b/twilight-gateway/src/shard/mod.rs @@ -22,10 +22,7 @@ //! # #[tokio::main] async fn main() -> Result<(), Box> { //! use std::env; //! use twilight_gateway::{shard::Shard, Intents}; -//! use twilight_model::{ -//! gateway::payload::outgoing::RequestGuildMembers, -//! id::Id, -//! }; +//! use twilight_model::{gateway::payload::outgoing::RequestGuildMembers, id::Id}; //! //! let intents = Intents::GUILD_MEMBERS; //! let token = env::var("DISCORD_TOKEN")?; @@ -35,9 +32,7 @@ //! //! // Query members whose names start with "tw" and limit the results to //! // 10 members. -//! let request = -//! RequestGuildMembers::builder(Id::new(1)) -//! .query("tw", Some(10)); +//! let request = RequestGuildMembers::builder(Id::new(1)).query("tw", Some(10)); //! //! // Send the request over the shard. //! shard.command(&request).await?; diff --git a/twilight-http/src/client/mod.rs b/twilight-http/src/client/mod.rs index 3646a65b54e..78e3871d75d 100644 --- a/twilight-http/src/client/mod.rs +++ b/twilight-http/src/client/mod.rs @@ -2183,7 +2183,7 @@ impl Client { /// /// ```no_run /// # use twilight_http::Client; - /// use twilight_model::{id::Id, guild::scheduled_event::PrivacyLevel, util::Timestamp}; + /// use twilight_model::{guild::scheduled_event::PrivacyLevel, id::Id, util::Timestamp}; /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); @@ -2208,7 +2208,7 @@ impl Client { /// /// ```no_run /// # use twilight_http::Client; - /// use twilight_model::{id::Id, guild::scheduled_event::PrivacyLevel, util::Timestamp}; + /// use twilight_model::{guild::scheduled_event::PrivacyLevel, id::Id, util::Timestamp}; /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); diff --git a/twilight-http/src/request/application/interaction/delete_response.rs b/twilight-http/src/request/application/interaction/delete_response.rs index ba5d4599f66..22178795bc3 100644 --- a/twilight-http/src/request/application/interaction/delete_response.rs +++ b/twilight-http/src/request/application/interaction/delete_response.rs @@ -17,7 +17,7 @@ use twilight_model::id::{marker::ApplicationMarker, Id}; /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// use std::env; -/// use twilight_http::{Client, request::AuditLogReason}; +/// use twilight_http::{request::AuditLogReason, Client}; /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); diff --git a/twilight-http/src/request/application/interaction/get_followup.rs b/twilight-http/src/request/application/interaction/get_followup.rs index 1c8b9774d0f..58a8c004f48 100644 --- a/twilight-http/src/request/application/interaction/get_followup.rs +++ b/twilight-http/src/request/application/interaction/get_followup.rs @@ -23,7 +23,7 @@ use twilight_model::{ /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// use std::env; -/// use twilight_http::{Client, request::AuditLogReason}; +/// use twilight_http::{request::AuditLogReason, Client}; /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); diff --git a/twilight-http/src/request/application/interaction/get_response.rs b/twilight-http/src/request/application/interaction/get_response.rs index 622f877521e..352edfcea52 100644 --- a/twilight-http/src/request/application/interaction/get_response.rs +++ b/twilight-http/src/request/application/interaction/get_response.rs @@ -20,7 +20,7 @@ use twilight_model::{ /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// use std::env; -/// use twilight_http::{Client, request::AuditLogReason}; +/// use twilight_http::{request::AuditLogReason, Client}; /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); diff --git a/twilight-http/src/request/scheduled_event/create_guild_scheduled_event/mod.rs b/twilight-http/src/request/scheduled_event/create_guild_scheduled_event/mod.rs index 74d8a4141d1..65c63a25411 100644 --- a/twilight-http/src/request/scheduled_event/create_guild_scheduled_event/mod.rs +++ b/twilight-http/src/request/scheduled_event/create_guild_scheduled_event/mod.rs @@ -66,7 +66,7 @@ struct CreateGuildScheduledEventFields<'a> { /// /// ```no_run /// # use twilight_http::Client; -/// use twilight_model::{id::Id, guild::scheduled_event::PrivacyLevel, util::Timestamp}; +/// use twilight_model::{guild::scheduled_event::PrivacyLevel, id::Id, util::Timestamp}; /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); @@ -91,7 +91,7 @@ struct CreateGuildScheduledEventFields<'a> { /// /// ```no_run /// # use twilight_http::Client; -/// use twilight_model::{id::Id, guild::scheduled_event::PrivacyLevel, util::Timestamp}; +/// use twilight_model::{guild::scheduled_event::PrivacyLevel, id::Id, util::Timestamp}; /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); diff --git a/twilight-model/src/channel/message/component/mod.rs b/twilight-model/src/channel/message/component/mod.rs index 6a2537905e7..c97b6455347 100644 --- a/twilight-model/src/channel/message/component/mod.rs +++ b/twilight-model/src/channel/message/component/mod.rs @@ -125,7 +125,9 @@ impl Component { /// Type of component that this is. /// /// ``` - /// use twilight_model::channel::message::component::{Button, ButtonStyle, Component, ComponentType}; + /// use twilight_model::channel::message::component::{ + /// Button, ButtonStyle, Component, ComponentType, + /// }; /// /// let component = Component::Button(Button { /// custom_id: None,