Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use #[non_exhaustive] attribute instead of __Nonexhaustive enum variant hack #884

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 4 additions & 9 deletions regex-syntax/src/ast/mod.rs
Expand Up @@ -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.
///
Expand Down Expand Up @@ -169,13 +170,6 @@ pub enum ErrorKind {
/// `(?<!re)`. Note that all of these syntaxes are otherwise invalid; this
/// error is used to improve the user experience.
UnsupportedLookAround,
/// 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 error::Error for Error {
Expand Down Expand Up @@ -208,13 +202,15 @@ impl error::Error for Error {
GroupUnclosed => "unclosed group",
GroupUnopened => "unopened group",
NestLimitExceeded(_) => "nest limit exceeded",
RepetitionCountDecimalEmpty => {
"invalid decimal in repetition quantifier"
}
RepetitionCountInvalid => "invalid repetition count range",
RepetitionCountUnclosed => "unclosed counted repetition",
RepetitionMissing => "repetition operator missing expression",
UnicodeClassInvalid => "invalid Unicode character class",
UnsupportedBackreference => "backreferences are not supported",
UnsupportedLookAround => "look-around is not supported",
_ => unreachable!(),
}
}
}
Expand Down Expand Up @@ -310,7 +306,6 @@ impl fmt::Display for ErrorKind {
"look-around, including look-ahead and look-behind, \
is not supported"
),
_ => unreachable!(),
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions regex-syntax/src/error.rs
Expand Up @@ -11,20 +11,14 @@ pub type Result<T> = result::Result<T, Error>;

/// 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).
Parse(ast::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<ast::Error> for Error {
Expand All @@ -46,7 +40,6 @@ impl error::Error for Error {
match *self {
Error::Parse(ref x) => x.description(),
Error::Translate(ref x) => x.description(),
_ => unreachable!(),
}
}
}
Expand All @@ -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!(),
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions regex-syntax/src/hir/mod.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -109,7 +103,6 @@ impl ErrorKind {
(make sure the unicode-case feature is enabled)"
}
EmptyClassNotAllowed => "empty character classes are not allowed",
__Nonexhaustive => unreachable!(),
}
}
}
Expand Down
13 changes: 1 addition & 12 deletions src/error.rs
Expand Up @@ -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 {
Expand All @@ -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!(),
}
}
}
Expand All @@ -39,7 +32,6 @@ impl fmt::Display for Error {
"Compiled regex exceeds size limit of {} bytes.",
limit
),
Error::__Nonexhaustive => unreachable!(),
}
}
}
Expand All @@ -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()
}
}
}
}