Skip to content

Commit

Permalink
Use #[non_exhaustive] where applicable (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
LikeLakers2 committed Sep 13, 2020
1 parent fb44a15 commit 9ee42f1
Show file tree
Hide file tree
Showing 40 changed files with 64 additions and 206 deletions.
1 change: 0 additions & 1 deletion src/builder/create_channel.rs
Expand Up @@ -127,7 +127,6 @@ impl CreateChannel {
let (id, kind) = match perm.kind {
PermissionOverwriteType::Member(id) => (id.0, "member"),
PermissionOverwriteType::Role(id) => (id.0, "role"),
PermissionOverwriteType::__Nonexhaustive => unreachable!(),
};

json!({
Expand Down
3 changes: 1 addition & 2 deletions src/cache/mod.rs
Expand Up @@ -101,6 +101,7 @@ impl<F: FromStr> FromStrAndCache for F {
/// [`Shard`]: ../gateway/struct.Shard.html
/// [`http`]: ../http/index.html
#[derive(Debug)]
#[non_exhaustive]
pub struct Cache {
/// A map of channels in [`Guild`]s that the current user has received data
/// for.
Expand Down Expand Up @@ -182,7 +183,6 @@ pub struct Cache {
pub(crate) message_queue: RwLock<HashMap<ChannelId, VecDeque<MessageId>>>,
/// The settings for the cache.
settings: RwLock<Settings>,
__nonexhaustive: (),
}

impl Cache {
Expand Down Expand Up @@ -969,7 +969,6 @@ impl Default for Cache {
user: RwLock::new(CurrentUser::default()),
users: RwLock::new(HashMap::default()),
message_queue: RwLock::new(HashMap::default()),
__nonexhaustive: (),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/cache/settings.rs
Expand Up @@ -11,19 +11,18 @@
/// settings.max_messages(10);
/// ```
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Settings {
/// The maximum number of messages to store in a channel's message cache.
///
/// Defaults to 0.
pub max_messages: usize,
__nonexhaustive: (),
}

impl Default for Settings {
fn default() -> Self {
Settings {
max_messages: usize::default(),
__nonexhaustive: (),
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/client/bridge/gateway/shard_runner.rs
Expand Up @@ -242,10 +242,8 @@ impl ShardRunner {
match *action {
ShardAction::Reconnect(ReconnectType::Reidentify) => self.request_restart().await,
ShardAction::Reconnect(ReconnectType::Resume) => self.shard.resume().await,
ShardAction::Reconnect(ReconnectType::__Nonexhaustive) => unreachable!(),
ShardAction::Heartbeat => self.shard.heartbeat().await,
ShardAction::Identify => self.shard.identify().await,
ShardAction::__Nonexhaustive => unreachable!(),
}
}

Expand Down Expand Up @@ -427,7 +425,6 @@ impl ShardRunner {
// Value must be forwarded over the websocket
self.shard.client.send_json(&value).await.is_ok()
},
InterMessage::__Nonexhaustive => unreachable!(),
}
}

Expand Down Expand Up @@ -545,7 +542,6 @@ impl ShardRunner {
return Ok((None, None, false));
}
},
ReconnectType::__Nonexhaustive => unreachable!(),
}

return Ok((None, None, true));
Expand Down
9 changes: 1 addition & 8 deletions src/client/dispatch.rs
Expand Up @@ -65,11 +65,10 @@ fn context(

// Once we can use `Box` as part of a pattern, we will reconsider boxing.
#[allow(clippy::large_enum_variant)]
#[non_exhaustive]
pub(crate) enum DispatchEvent {
Client(ClientEvent),
Model(Event),
#[doc(hidden)]
__Nonexhaustive,
}

impl DispatchEvent {
Expand Down Expand Up @@ -138,8 +137,6 @@ impl DispatchEvent {
Self::Model(Event::VoiceStateUpdate(ref mut event)) => {
update(cache_and_http, event).await;
},
Self::Model(Event::__Nonexhaustive) => unreachable!(),
Self::__Nonexhaustive => unreachable!(),
_ => (),
}
}
Expand Down Expand Up @@ -361,7 +358,6 @@ async fn handle_event(
event_handler.category_create(context, &channel).await;
});
},
Channel::__Nonexhaustive => unreachable!(),
}
},
DispatchEvent::Model(Event::ChannelDelete(mut event)) => {
Expand All @@ -383,7 +379,6 @@ async fn handle_event(
event_handler.category_delete(context, &channel).await;
});
},
Channel::__Nonexhaustive => unreachable!(),
}
},
DispatchEvent::Model(Event::ChannelPinsUpdate(event)) => {
Expand Down Expand Up @@ -745,7 +740,5 @@ async fn handle_event(
event_handler.webhook_update(context, event.guild_id, event.channel_id).await;
});
},
DispatchEvent::Model(Event::__Nonexhaustive) => unreachable!(),
DispatchEvent::__Nonexhaustive => unreachable!(),
}
}
5 changes: 1 addition & 4 deletions src/client/error.rs
Expand Up @@ -18,6 +18,7 @@ use std::{
/// [`GuildId::ban`]: ../model/id/struct.GuildId.html#method.ban
#[allow(clippy::enum_variant_names)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum Error {
/// When the token provided is invalid. This is returned when validating a
/// token through the [`validate_token`] function.
Expand All @@ -30,8 +31,6 @@ pub enum Error {
/// When all shards that the client is responsible for have shutdown with an
/// error.
Shutdown,
#[doc(hidden)]
__Nonexhaustive,
}

impl Display for Error {
Expand All @@ -40,7 +39,6 @@ impl Display for Error {
Error::InvalidToken => f.write_str("The provided token was invalid"),
Error::ShardBootFailure => f.write_str("Failed to (re-)boot a shard"),
Error::Shutdown => f.write_str("The clients shards shutdown"),
Error::__Nonexhaustive => unreachable!(),
}
}
}
Expand All @@ -51,7 +49,6 @@ impl StdError for Error {
Error::InvalidToken => "The provided token was invalid",
Error::ShardBootFailure => "Failed to (re-)boot a shard",
Error::Shutdown => "The clients shards shutdown",
Error::__Nonexhaustive => unreachable!(),
}
}
}
1 change: 0 additions & 1 deletion src/client/mod.rs
Expand Up @@ -302,7 +302,6 @@ impl<'a> Future for ClientBuilder<'a> {
#[cfg(feature = "cache")]
update_cache_timeout: self.timeout.take(),
http: Arc::clone(&http),
__nonexhaustive: (),
});

self.fut = Some(Box::pin(async move {
Expand Down
8 changes: 2 additions & 6 deletions src/constants.rs
Expand Up @@ -65,6 +65,7 @@ pub static JOIN_MESSAGES: &[&str] = &[

/// Enum to map gateway opcodes.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum OpCode {
/// Dispatches an event.
Event = 0,
Expand All @@ -90,8 +91,6 @@ pub enum OpCode {
Hello = 10,
/// Sent immediately following a client heartbeat that was received.
HeartbeatAck = 11,
#[doc(hidden)]
__Nonexhaustive,
}

enum_number!(
Expand Down Expand Up @@ -126,13 +125,13 @@ impl OpCode {
OpCode::InvalidSession => 9,
OpCode::Hello => 10,
OpCode::HeartbeatAck => 11,
OpCode::__Nonexhaustive => unreachable!(),
}
}
}

/// Enum to map voice opcodes.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum VoiceOpCode {
/// Used to begin a voice websocket connection.
Identify = 0,
Expand All @@ -158,8 +157,6 @@ pub enum VoiceOpCode {
ClientConnect = 12,
/// Message indicating that another user has disconnected from the voice channel.
ClientDisconnect = 13,
#[doc(hidden)]
__Nonexhaustive,
}

enum_number!(
Expand Down Expand Up @@ -194,7 +191,6 @@ impl VoiceOpCode {
VoiceOpCode::Resumed => 9,
VoiceOpCode::ClientConnect => 12,
VoiceOpCode::ClientDisconnect => 13,
VoiceOpCode::__Nonexhaustive => unreachable!(),
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/error.rs
Expand Up @@ -53,6 +53,7 @@ pub type Result<T> = StdResult<T, Error>;
/// [`GatewayError`]: gateway/enum.GatewayError.html
/// [`Result`]: type.Result.html
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
/// An error while decoding a payload.
Decode(&'static str, Value),
Expand Down Expand Up @@ -109,8 +110,6 @@ pub enum Error {
/// [voice module]: voice/index.html
#[cfg(feature = "voice")]
Voice(VoiceError),
#[doc(hidden)]
__Nonexhaustive,
}

impl From<FormatError> for Error {
Expand Down Expand Up @@ -198,7 +197,6 @@ impl Display for Error {
Error::Tungstenite(inner) => fmt::Display::fmt(&inner, f),
#[cfg(feature = "voice")]
Error::Voice(_) => f.write_str("Voice error"),
Error::__Nonexhaustive => unreachable!(),
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/framework/standard/args.rs
Expand Up @@ -7,13 +7,12 @@ use std::borrow::Cow;

/// Defines how an operation on an `Args` method failed.
#[derive(Debug)]
#[non_exhaustive]
pub enum Error<E> {
/// "END-OF-STRING". We reached the end. There's nothing to parse anymore.
Eos,
/// Parsing operation failed. Contains how it did.
Parse(E),
#[doc(hidden)]
__Nonexhaustive,
}

impl<E> From<E> for Error<E> {
Expand All @@ -29,7 +28,6 @@ impl<E: fmt::Display> fmt::Display for Error<E> {
match *self {
Eos => write!(f, "ArgError(\"end of string\")"),
Parse(ref e) => write!(f, "ArgError(\"{}\")", e),
__Nonexhaustive => unreachable!(),
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/framework/standard/help_commands.rs
Expand Up @@ -92,7 +92,6 @@ macro_rules! format_command_name {
HelpBehaviour::Strike => format!("~~`{}`~~", $command_name),
HelpBehaviour::Nothing => format!("`{}`", $command_name),
HelpBehaviour::Hide => continue,
HelpBehaviour::__Nonexhaustive => unreachable!(),
}
};
}
Expand Down Expand Up @@ -183,6 +182,7 @@ impl Suggestions {
/// yields relevant data in customised textual
/// representation.
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum CustomisedHelpData<'a> {
/// To display suggested commands.
SuggestedCommands {
Expand All @@ -198,8 +198,6 @@ pub enum CustomisedHelpData<'a> {
SingleCommand { command: Command<'a> },
/// To display failure in finding a fitting command.
NoCommandFound { help_error_message: &'a str },
#[doc(hidden)]
__Nonexhaustive,
}

/// Wraps around a `Vec<Vec<T>>` and provides access
Expand Down Expand Up @@ -1316,7 +1314,6 @@ pub async fn with_embeds(
&command,
help_options.embed_success_colour,
).await,
CustomisedHelpData::__Nonexhaustive => unreachable!(),
};

match response_result {
Expand Down Expand Up @@ -1491,7 +1488,6 @@ pub async fn plain(
CustomisedHelpData::SingleCommand { ref command } => {
single_command_to_plain_string(&help_options, &command)
},
CustomisedHelpData::__Nonexhaustive => unreachable!(),
};

match msg.channel_id.say(&ctx, result).await {
Expand Down
3 changes: 1 addition & 2 deletions src/framework/standard/mod.rs
Expand Up @@ -47,6 +47,7 @@ use crate::model::{guild::Role, id::RoleId};
/// An enum representing all possible fail conditions under which a command won't
/// be executed.
#[derive(Debug)]
#[non_exhaustive]
pub enum DispatchError {
/// When a custom function check has failed.
CheckFailed(&'static str, Reason),
Expand Down Expand Up @@ -82,8 +83,6 @@ pub enum DispatchError {
IgnoredBot,
/// When the bot ignores webhooks and a command was issued by one.
WebhookAuthor,
#[doc(hidden)]
__Nonexhaustive,
}

type DispatchHook = for<'fut> fn(&'fut Context, &'fut Message, DispatchError) -> BoxFuture<'fut , ()>;
Expand Down
3 changes: 1 addition & 2 deletions src/framework/standard/structures/check.rs
Expand Up @@ -17,6 +17,7 @@ use futures::future::BoxFuture;
/// [`Check`]: struct.Check.html
/// [`CheckResult::Failure`]: enum.CheckResult.html#variant.Failure
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum Reason {
/// No information on the failure.
Unknown,
Expand All @@ -26,8 +27,6 @@ pub enum Reason {
Log(String),
/// Information for the user but also for logging purposes.
UserAndLog { user: String, log: String },
#[doc(hidden)]
__Nonexhaustive,
}

/// Returned from [`Check`]s.
Expand Down
6 changes: 2 additions & 4 deletions src/framework/standard/structures/mod.rs
Expand Up @@ -19,12 +19,11 @@ pub mod buckets;
pub use self::check::*;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum OnlyIn {
Dm,
Guild,
None,
#[doc(hidden)]
__Nonexhaustive,
}

impl Default for OnlyIn {
Expand Down Expand Up @@ -129,15 +128,14 @@ impl PartialEq for HelpCommand {
/// Lacking required roles to execute the command.
/// The command can't be used in the current channel (as in `DM only` or `guild only`).
#[derive(Copy, Clone, Debug, PartialOrd, Ord, Eq, PartialEq)]
#[non_exhaustive]
pub enum HelpBehaviour {
/// The command will be displayed, hence nothing will be done.
Nothing,
/// Strikes a command by applying `~~{command_name}~~`.
Strike,
/// Does not list a command in the help-menu.
Hide,
#[doc(hidden)]
__Nonexhaustive,
}

#[derive(Clone, Debug, PartialEq)]
Expand Down
4 changes: 1 addition & 3 deletions src/gateway/error.rs
Expand Up @@ -13,6 +13,7 @@ use async_tungstenite::tungstenite::protocol::CloseFrame;
/// Note that - from a user standpoint - there should be no situation in which
/// you manually handle these.
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum Error {
/// There was an error building a URL.
BuildingUrl,
Expand Down Expand Up @@ -57,8 +58,6 @@ pub enum Error {
/// If an connection has been established but priviliged gateway intents
/// were provided without enabling them prior.
DisallowedGatewayIntents,
#[doc(hidden)]
__Nonexhaustive,
}

impl Display for Error {
Expand All @@ -78,7 +77,6 @@ impl Display for Error {
Error::ReconnectFailure => f.write_str("Failed to Reconnect"),
Error::InvalidGatewayIntents => f.write_str("Invalid gateway intents were provided"),
Error::DisallowedGatewayIntents => f.write_str("Disallowed gateway intents were provided"),
Error::__Nonexhaustive => unreachable!(),
}
}
}
Expand Down

0 comments on commit 9ee42f1

Please sign in to comment.