From d6e936be0d345588ad127aea56b7b7376d6565ff Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 26 Aug 2022 14:01:02 -0400 Subject: [PATCH] syntax: remove '__Nonexhaustive' hack, use #[non_exhaustive] This marks the various error types as '#[non_exhaustive]' instead of using a __Nonexhaustive variant hack. Closes #884 --- regex-syntax/src/ast/mod.rs | 12 ++++-------- regex-syntax/src/error.rs | 12 ++++-------- regex-syntax/src/hir/mod.rs | 12 ++++-------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/regex-syntax/src/ast/mod.rs b/regex-syntax/src/ast/mod.rs index aae928ec1..1f0fbd2e2 100644 --- a/regex-syntax/src/ast/mod.rs +++ b/regex-syntax/src/ast/mod.rs @@ -64,6 +64,10 @@ impl Error { } /// The type of an error that occurred while building an AST. +/// +/// This error type is marked as `non_exhaustive`. This means that adding a +/// new variant is not considered a breaking change. +#[non_exhaustive] #[derive(Clone, Debug, Eq, PartialEq)] pub enum ErrorKind { /// The capturing group limit was exceeded. @@ -168,13 +172,6 @@ pub enum ErrorKind { /// `(? unreachable!(), } } } diff --git a/regex-syntax/src/error.rs b/regex-syntax/src/error.rs index bd3fcc079..6e7fa7466 100644 --- a/regex-syntax/src/error.rs +++ b/regex-syntax/src/error.rs @@ -9,6 +9,10 @@ use crate::hir; pub type Result = result::Result; /// This error type encompasses any error that can be returned by this crate. +/// +/// This error type is marked as `non_exhaustive`. This means that adding a +/// new variant is not considered a breaking change. +#[non_exhaustive] #[derive(Clone, Debug, Eq, PartialEq)] pub enum Error { /// An error that occurred while translating concrete syntax into abstract @@ -17,13 +21,6 @@ pub enum Error { /// An error that occurred while translating abstract syntax into a high /// level intermediate representation (HIR). Translate(hir::Error), - /// Hints that destructuring should not be exhaustive. - /// - /// This enum may grow additional variants, so this makes sure clients - /// don't count on exhaustive matching. (Otherwise, adding a new variant - /// could break existing code.) - #[doc(hidden)] - __Nonexhaustive, } impl From for Error { @@ -45,7 +42,6 @@ impl fmt::Display for Error { match *self { Error::Parse(ref x) => x.fmt(f), Error::Translate(ref x) => x.fmt(f), - _ => unreachable!(), } } } diff --git a/regex-syntax/src/hir/mod.rs b/regex-syntax/src/hir/mod.rs index 21bbae17f..1af8d4c32 100644 --- a/regex-syntax/src/hir/mod.rs +++ b/regex-syntax/src/hir/mod.rs @@ -52,6 +52,10 @@ impl Error { } /// The type of an error that occurred while building an `Hir`. +/// +/// This error type is marked as `non_exhaustive`. This means that adding a +/// new variant is not considered a breaking change. +#[non_exhaustive] #[derive(Clone, Debug, Eq, PartialEq)] pub enum ErrorKind { /// This error occurs when a Unicode feature is used when Unicode @@ -80,13 +84,6 @@ pub enum ErrorKind { /// Note that this restriction in the translator may be removed in the /// future. EmptyClassNotAllowed, - /// Hints that destructuring should not be exhaustive. - /// - /// This enum may grow additional variants, so this makes sure clients - /// don't count on exhaustive matching. (Otherwise, adding a new variant - /// could break existing code.) - #[doc(hidden)] - __Nonexhaustive, } // BREADCRUMBS: @@ -122,7 +119,6 @@ impl fmt::Display for ErrorKind { (make sure the unicode-case feature is enabled)" } EmptyClassNotAllowed => "empty character classes are not allowed", - __Nonexhaustive => unreachable!(), }; f.write_str(msg) }