diff --git a/regex-syntax/src/ast/mod.rs b/regex-syntax/src/ast/mod.rs index 9b9127b1f..69c586f54 100644 --- a/regex-syntax/src/ast/mod.rs +++ b/regex-syntax/src/ast/mod.rs @@ -66,6 +66,7 @@ impl Error { /// The type of an error that occurred while building an AST. #[derive(Clone, Debug, Eq, PartialEq)] +#[non_exhaustive] pub enum ErrorKind { /// The capturing group limit was exceeded. /// @@ -169,13 +170,6 @@ pub enum ErrorKind { /// `(? unreachable!(), } } } diff --git a/regex-syntax/src/error.rs b/regex-syntax/src/error.rs index 71cfa426a..ae8368536 100644 --- a/regex-syntax/src/error.rs +++ b/regex-syntax/src/error.rs @@ -11,6 +11,7 @@ pub type Result = result::Result; /// This error type encompasses any error that can be returned by this crate. #[derive(Clone, Debug, Eq, PartialEq)] +#[non_exhaustive] pub enum Error { /// An error that occurred while translating concrete syntax into abstract /// syntax (AST). @@ -18,13 +19,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 { @@ -46,7 +40,6 @@ impl error::Error for Error { match *self { Error::Parse(ref x) => x.description(), Error::Translate(ref x) => x.description(), - _ => unreachable!(), } } } @@ -56,7 +49,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 4969f1265..52775fa7a 100644 --- a/regex-syntax/src/hir/mod.rs +++ b/regex-syntax/src/hir/mod.rs @@ -54,6 +54,7 @@ impl Error { /// The type of an error that occurred while building an `Hir`. #[derive(Clone, Debug, Eq, PartialEq)] +#[non_exhaustive] pub enum ErrorKind { /// This error occurs when a Unicode feature is used when Unicode /// support is disabled. For example `(?-u:\pL)` would trigger this error. @@ -81,13 +82,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, } impl ErrorKind { @@ -109,7 +103,6 @@ impl ErrorKind { (make sure the unicode-case feature is enabled)" } EmptyClassNotAllowed => "empty character classes are not allowed", - __Nonexhaustive => unreachable!(), } } } diff --git a/src/error.rs b/src/error.rs index 3e0ec7521..189f4ca10 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,19 +3,13 @@ use std::iter::repeat; /// An error that occurred during parsing or compiling a regular expression. #[derive(Clone, PartialEq)] +#[non_exhaustive] pub enum Error { /// A syntax error. Syntax(String), /// The compiled program exceeded the set size limit. /// The argument is the size limit imposed. CompiledTooBig(usize), - /// 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 ::std::error::Error for Error { @@ -25,7 +19,6 @@ impl ::std::error::Error for Error { match *self { Error::Syntax(ref err) => err, Error::CompiledTooBig(_) => "compiled program too big", - Error::__Nonexhaustive => unreachable!(), } } } @@ -39,7 +32,6 @@ impl fmt::Display for Error { "Compiled regex exceeds size limit of {} bytes.", limit ), - Error::__Nonexhaustive => unreachable!(), } } } @@ -63,9 +55,6 @@ impl fmt::Debug for Error { Error::CompiledTooBig(limit) => { f.debug_tuple("CompiledTooBig").field(&limit).finish() } - Error::__Nonexhaustive => { - f.debug_tuple("__Nonexhaustive").finish() - } } } }